Class: Pdf::View
- Inherits:
-
Object
- Object
- Pdf::View
- Defined in:
- lib/pdf/view.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
- .blueprint ⇒ Object
- .each(source, **options, &block) ⇒ Object
- .inherited(subclass) ⇒ Object
- .layout(klass) ⇒ Object
-
.method_missing(name, *args, **options, &block) ⇒ Object
Dynamic component support via DynamicComponents pattern.
- .page_break_if(threshold:) ⇒ Object
- .partial(method_name) ⇒ Object
- .raw(&block) ⇒ Object
- .render_if(condition, &block) ⇒ Object
- .render_unless(condition, &block) ⇒ Object
- .respond_to_missing?(name, include_private = false) ⇒ Boolean
- .section(title_text, **options, &block) ⇒ Object
Instance Method Summary collapse
-
#initialize(data = {}) ⇒ View
constructor
A new instance of View.
- #render_content(renderer) ⇒ Object
- #to_file(path) ⇒ Object
- #to_pdf ⇒ Object
Constructor Details
#initialize(data = {}) ⇒ View
Returns a new instance of View.
79 80 81 |
# File 'lib/pdf/view.rb', line 79 def initialize(data = {}) @data = data.is_a?(Hash) ? symbolize_keys(data) : data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
77 78 79 |
# File 'lib/pdf/view.rb', line 77 def data @data end |
Class Method Details
.blueprint ⇒ Object
14 15 16 |
# File 'lib/pdf/view.rb', line 14 def blueprint @blueprint ||= Blueprint.new end |
.each(source, **options, &block) ⇒ Object
33 34 35 |
# File 'lib/pdf/view.rb', line 33 def each(source, **, &block) content_builder.each(source, **, &block) end |
.inherited(subclass) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/pdf/view.rb', line 6 def inherited(subclass) # CRITICAL: Inherit parent's blueprint via dup, not empty blueprint # This allows child views to extend parent views parent_blueprint = @blueprint || Blueprint.new subclass.instance_variable_set(:@blueprint, parent_blueprint.dup) subclass.instance_variable_set(:@content_builder, nil) end |
.layout(klass) ⇒ Object
18 19 20 |
# File 'lib/pdf/view.rb', line 18 def layout(klass) blueprint.set_layout(klass) end |
.method_missing(name, *args, **options, &block) ⇒ Object
Dynamic component support via DynamicComponents pattern
58 59 60 61 62 63 64 |
# File 'lib/pdf/view.rb', line 58 def method_missing(name, *args, **, &block) if Pdf.component_registered?(name) content_builder.send(name, *args, **, &block) else super end end |
.page_break_if(threshold:) ⇒ Object
41 42 43 |
# File 'lib/pdf/view.rb', line 41 def page_break_if(threshold:) content_builder.page_break_if(threshold: threshold) end |
.partial(method_name) ⇒ Object
37 38 39 |
# File 'lib/pdf/view.rb', line 37 def partial(method_name) content_builder.partial(method_name) end |
.raw(&block) ⇒ Object
53 54 55 |
# File 'lib/pdf/view.rb', line 53 def raw(&block) content_builder.raw(&block) end |
.render_if(condition, &block) ⇒ Object
45 46 47 |
# File 'lib/pdf/view.rb', line 45 def render_if(condition, &block) content_builder.render_if(condition, &block) end |
.render_unless(condition, &block) ⇒ Object
49 50 51 |
# File 'lib/pdf/view.rb', line 49 def render_unless(condition, &block) content_builder.render_unless(condition, &block) end |
.respond_to_missing?(name, include_private = false) ⇒ Boolean
66 67 68 |
# File 'lib/pdf/view.rb', line 66 def respond_to_missing?(name, include_private = false) Pdf.component_registered?(name) || super end |
.section(title_text, **options, &block) ⇒ Object
29 30 31 |
# File 'lib/pdf/view.rb', line 29 def section(title_text, **, &block) content_builder.section(title_text, **, &block) end |
Instance Method Details
#render_content(renderer) ⇒ Object
102 103 104 105 |
# File 'lib/pdf/view.rb', line 102 def render_content(renderer) evaluator = ContentEvaluator.new(self, renderer) evaluator.evaluate(self.class.blueprint) end |
#to_file(path) ⇒ Object
98 99 100 |
# File 'lib/pdf/view.rb', line 98 def to_file(path) File.binwrite(path, to_pdf) end |
#to_pdf ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/pdf/view.rb', line 83 def to_pdf renderer = Renderer.new layout_class = self.class.blueprint.layout_class if layout_class layout = layout_class.new(self) layout.render(renderer) else renderer.setup render_content(renderer) end renderer.finalize end |