Sha256: bddaaa807cdd2cc597c4c4a31dce750f88bc8b5db21950ea94a60399fdeb18a2
Contents?: true
Size: 1.16 KB
Versions: 4
Compression:
Stored size: 1.16 KB
Contents
require "erb" module Billme class Factory def initialize @template_file_path = File.expand_path('../views/bill.html.erb', __FILE__) @css_path = File.expand_path('../views/style.css', __FILE__) @data = {} @css = nil read_css end def method_missing(name, *args, &block) return @data[name.to_sym] = args[0] unless block_given? #super "Not supported!" section = Section.new section.instance_eval &block @data[name] = section.data end def services(&block) section = ServicesSection.new section.instance_eval &block @data[:services] = section.data @data[:services][:total] = section.total @data[:services][:subtotal] = section.subtotal @data[:services][:tax] = section.total - section.subtotal end def render erb = ERB.new(File.read(@template_file_path)) erb.filename = filename result = erb.result(binding) File.open('output.html', 'w') do |file| file.write(result) end result end private def read_css File.open(@css_path, 'r') do |file| @css = file.read end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
billme-0.6.0 | lib/billme/factory.rb |
billme-0.5.0 | lib/billme/factory.rb |
billme-0.2.0 | lib/billme/factory.rb |
billme-0.1.0 | lib/billme/factory.rb |