Module: Lablr
- Defined in:
- lib/lablr.rb,
lib/lablr/template.rb,
lib/lablr/template_style.rb
Defined Under Namespace
Modules: Template, VERSION Classes: TemplateStyle
Class Method Summary collapse
- .GEM_ROOT ⇒ Object
- .generate_labels(options = {}) ⇒ Object
-
.render_to_pdf(html) ⇒ Object
create a pdf.
Class Method Details
.GEM_ROOT ⇒ Object
8 9 10 |
# File 'lib/lablr.rb', line 8 def self.GEM_ROOT return File.join(File.dirname(File.join(__FILE__)), "..") end |
.generate_labels(options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/lablr.rb', line 12 def self.generate_labels( = {}) [:format] ||= :pdf [:template] ||= "avery_5163" [:content] ||= "No Content Set" [:style] ||= {} [:to_file] ||= nil # to a specific file #puts options.inspect lablr_template = Lablr::Template::Base.new(:name => [:template], :content => [:content], :style => TemplateStyle.new([:style])) rendered_template = lablr_template.erb.result(lablr_template.getBinding) # render erb template if [:format] == :pdf data = Lablr.render_to_pdf(rendered_template) elsif [:format] == :html data = rendered_template end #puts rendered_template if [:to_file] # write to file filename = File.basename([:to_file], "." + [:format].to_s) + "." + [:format].to_s file = File.join(File.dirname([:to_file]), filename) File.open(file, "w"){|f| f.write(data)} return "Labels written to #{File.basename(file)}" else # return data return data end end |
.render_to_pdf(html) ⇒ Object
create a pdf
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lablr.rb', line 43 def self.render_to_pdf(html) # create a pdf #data = render_to_string(options) pdf = ::PDF::HTMLDoc.new pdf.set_option :bodycolor, :white pdf.set_option :toc, false pdf.set_option :portrait, true pdf.set_option :links, false pdf.set_option :webpage, true pdf.set_option :top, '0cm' pdf.set_option :left, '0cm' pdf.set_option :right, '0cm' pdf.set_option :bottom, '0cm' pdf. ".1." pdf << html pdf.generate end |