| | 588 | class CustomFormatter < Ruport::Formatter |
|---|
| | 589 | def custom_helper |
|---|
| | 590 | output << "Custom!" |
|---|
| | 591 | end |
|---|
| | 592 | end |
|---|
| | 593 | |
|---|
| | 594 | class ControllerWithAnonymousFormatters < Ruport::Controller |
|---|
| | 595 | |
|---|
| | 596 | stage :report |
|---|
| | 597 | |
|---|
| | 598 | formatter :html do |
|---|
| | 599 | build :report do |
|---|
| | 600 | output << textile("h1. Hi there") |
|---|
| | 601 | end |
|---|
| | 602 | end |
|---|
| | 603 | |
|---|
| | 604 | formatter :csv do |
|---|
| | 605 | build :report do |
|---|
| | 606 | build_row([1,2,3]) |
|---|
| | 607 | end |
|---|
| | 608 | end |
|---|
| | 609 | |
|---|
| | 610 | formatter :pdf do |
|---|
| | 611 | build :report do |
|---|
| | 612 | add_text "hello world" |
|---|
| | 613 | end |
|---|
| | 614 | end |
|---|
| | 615 | |
|---|
| | 616 | formatter :text do |
|---|
| | 617 | build :report do |
|---|
| | 618 | output << "Hello world" |
|---|
| | 619 | end |
|---|
| | 620 | end |
|---|
| | 621 | |
|---|
| | 622 | formatter :custom => CustomFormatter do |
|---|
| | 623 | |
|---|
| | 624 | build :report do |
|---|
| | 625 | output << "This is " |
|---|
| | 626 | custom_helper |
|---|
| | 627 | end |
|---|
| | 628 | |
|---|
| | 629 | end |
|---|
| | 630 | |
|---|
| | 631 | end |
|---|
| | 632 | |
|---|
| | 633 | class TestAnonymousFormatter < Test::Unit::TestCase |
|---|
| | 634 | context "When using built in Ruport formatters" do |
|---|
| | 635 | |
|---|
| | 636 | def specify_text_formatter_shortcut_is_accessible |
|---|
| | 637 | assert_equal "Hello world", ControllerWithAnonymousFormatters.render_text |
|---|
| | 638 | assert_equal "1,2,3\n", ControllerWithAnonymousFormatters.render_csv |
|---|
| | 639 | assert_equal "<h1>Hi there</h1>", ControllerWithAnonymousFormatters.render_html |
|---|
| | 640 | assert_not_nil ControllerWithAnonymousFormatters.render_pdf |
|---|
| | 641 | end |
|---|
| | 642 | |
|---|
| | 643 | end |
|---|
| | 644 | |
|---|
| | 645 | context "When using custom formatters" do |
|---|
| | 646 | def specify_custom_formatter_shortcut_is_accessible |
|---|
| | 647 | assert_equal "This is Custom!", ControllerWithAnonymousFormatters.render_custom |
|---|
| | 648 | end |
|---|
| | 649 | end |
|---|
| | 650 | |
|---|
| | 651 | end |
|---|
| | 652 | |
|---|