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
- #helpers(helpers) ⇒ Object
-
#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
- #view_paths(path = ".") ⇒ Object
Constructor Details
#initialize(&block) ⇒ Base
Returns a new instance of Base.
19 20 21 22 |
# File 'lib/pdf_maker.rb', line 19 def initialize(&block) instance_eval(&block) @pdf = PDFKit.new(render(@renders, )) end |
Instance Attribute Details
#pdf ⇒ Object
Returns the value of attribute pdf.
15 16 17 |
# File 'lib/pdf_maker.rb', line 15 def pdf @pdf end |
#view ⇒ Object
Returns the value of attribute view.
15 16 17 |
# File 'lib/pdf_maker.rb', line 15 def view @view end |
Instance Method Details
#helpers(helpers) ⇒ Object
61 62 63 |
# File 'lib/pdf_maker.rb', line 61 def helpers(helpers) helpers.map { |helper| self.class.send(:helper, helper) } end |
#layout(layout = nil) ⇒ Object
24 25 26 27 |
# File 'lib/pdf_maker.rb', line 24 def layout(layout=nil) return @layout if defined?(@layout) @layout = layout end |
#method(key, value) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/pdf_maker.rb', line 39 def method(key,value) self.class.instance_eval do helper_method key define_method key do value end end end |
#options ⇒ Object
29 30 31 32 |
# File 'lib/pdf_maker.rb', line 29 def @options ||= {} @options.merge({layout: layout}) end |
#pdf_maker_assets_tag ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/pdf_maker.rb', line 65 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
34 35 36 37 |
# File 'lib/pdf_maker.rb', line 34 def renders(renders=nil) return @renders if defined?(@renders) @renders = renders end |
#to_file(path) ⇒ Object
53 54 55 |
# File 'lib/pdf_maker.rb', line 53 def to_file(path) @pdf.to_file(path) end |
#variable(key, value) ⇒ Object
48 49 50 51 |
# File 'lib/pdf_maker.rb', line 48 def variable(key,value) instance_variable_set("@#{key}", value) self.class.instance_eval { attr_accessor key } end |
#view_paths(path = ".") ⇒ Object
57 58 59 |
# File 'lib/pdf_maker.rb', line 57 def view_paths(path=".") self.class.view_paths = path end |