Sha256: d824efe07c01c9ffdbe1ccb5df69b60248fc146f46d88675ff885229cfa71553
Contents?: true
Size: 1.79 KB
Versions: 2
Compression:
Stored size: 1.79 KB
Contents
require 'haml' module SFanalytics class SFa attr_reader :analytics_id, :transaction, :line_items, :transaction_id if defined? Rails require 'sfanalytics/view_helpers' ActionView::Base.send :include, ViewHelpers end def initialize() @line_items = '' end def generate(analytics_id) template = File.read(File.dirname(__FILE__) + '/../templates/analytics.html.haml') raise ArgumentError.new if ! analytics_id.match(/UA-\d{0,8}-\d{0,3}/) @analytics_id = analytics_id obj = Object.new Haml::Engine.new(template).def_method(obj, :render, :analytics_id, :analytics_transaction, :line_items) return obj.render( :analytics_id => @analytics_id, :analytics_transaction => @transaction, :line_items => @line_items ) obj = Object.new Haml::Engine.new(template).def_method(obj, :render, :analytics_id) return obj.render(:analytics_id => "Hello!") end def add_transaction(transaction) template = File.read(File.dirname(__FILE__) + '/../templates/transaction.html.haml') obj = Object.new Haml::Engine.new(template).def_method(obj, :render, :analytics_id, :transaction) @transaction = obj.render( :analytics_id => @analytics_id, :transaction => transaction ) @transaction_id = transaction[:id] return true end def add_line_item(item) raise "No Transaction Defined" unless(@transaction) template = File.read(File.dirname(__FILE__) + '/../templates/line_item.html.haml') obj = Object.new Haml::Engine.new(template).def_method(obj, :render, :transaction, :item) @line_items << obj.render( :transaction => @transaction_id, :item => item ) return true end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sfanalytics-0.2.16 | lib/sfanalytics.rb |
sfanalytics-0.2.15 | lib/sfanalytics.rb |