Class: PdfMaker::Base
- Inherits:
-
AbstractController::Base
- Object
- AbstractController::Base
- PdfMaker::Base
- Includes:
- AbstractController::AssetPaths, AbstractController::Helpers, AbstractController::Layouts, AbstractController::Rendering, ActionView::Helpers::OutputSafetyHelper, ActionView::Helpers::TextHelper
- Defined in:
- lib/pdf_maker.rb
Instance Attribute Summary collapse
-
#pdf ⇒ Object
Returns the value of attribute pdf.
-
#view ⇒ Object
Returns the value of attribute view.
Instance Method Summary collapse
-
#initialize(&block) ⇒ Base
constructor
A new instance of Base.
- #layout(layout = nil) ⇒ Object
- #method(key, value) ⇒ Object
- #options ⇒ Object
- #pdf_maker_assets_tag ⇒ Object
- #renders(renders = nil) ⇒ Object
- #to_file(path) ⇒ Object
- #variable(key, value) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Base
Returns a new instance of Base.
21 22 23 24 |
# File 'lib/pdf_maker.rb', line 21 def initialize(&block) instance_eval(&block) @pdf = PDFKit.new(render(@renders, )) end |
Instance Attribute Details
#pdf ⇒ Object
Returns the value of attribute pdf.
17 18 19 |
# File 'lib/pdf_maker.rb', line 17 def pdf @pdf end |
#view ⇒ Object
Returns the value of attribute view.
17 18 19 |
# File 'lib/pdf_maker.rb', line 17 def view @view end |
Instance Method Details
#layout(layout = nil) ⇒ Object
26 27 28 29 |
# File 'lib/pdf_maker.rb', line 26 def layout(layout=nil) return @layout if defined?(@layout) @layout = layout end |
#method(key, value) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/pdf_maker.rb', line 41 def method(key,value) self.class.instance_eval do helper_method key define_method key do value end end end |
#options ⇒ Object
31 32 33 34 |
# File 'lib/pdf_maker.rb', line 31 def @options ||= {} @options.merge({layout: layout}) end |
#pdf_maker_assets_tag ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/pdf_maker.rb', line 59 def pdf_maker_assets_tag env = Sprockets::Environment.new Rails.application.assets.paths.each { |asset_path| env.append_path asset_path } raw "<style>#{env['application.css']}</style> <script>#{env['application.js']}</script>" end |
#renders(renders = nil) ⇒ Object
36 37 38 39 |
# File 'lib/pdf_maker.rb', line 36 def renders(renders=nil) return @renders if defined?(@renders) @renders = renders end |
#to_file(path) ⇒ Object
55 56 57 |
# File 'lib/pdf_maker.rb', line 55 def to_file(path) @pdf.to_file(path) end |
#variable(key, value) ⇒ Object
50 51 52 53 |
# File 'lib/pdf_maker.rb', line 50 def variable(key,value) instance_variable_set("@#{key}", value) self.class.instance_eval { attr_accessor key } end |