iab-RailsGlue 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,87 @@
1
+ # Copyright (c) 2007-2008 Orangery Technology Limited
2
+ # You can redistribute it and/or modify it under the same terms as Ruby.
3
+ #
4
+ require 'rubygems'
5
+ require 'hooks/helpers/ActionView'
6
+ require 'hooks/helpers/ActiveRecord'
7
+ require 'hooks/helpers/paypal_helper'
8
+ require 'channel_manager'
9
+
10
+ require 'processengine/communicator'
11
+
12
+ class IabBaseController < ApplicationController
13
+
14
+ include PaypalHelper
15
+ helper_method :payment_amount
16
+
17
+ before_filter :set_channel_in_session, :load_changes_in_channel
18
+
19
+
20
+ def initialize()
21
+ @widgets = Hash.new
22
+ @assets = Hash.new
23
+ end
24
+
25
+ def render_for_file(template_path, status = nil, layout = nil, locals = {}) #:nodoc:
26
+ add_variables_to_assigns
27
+ assert_existence_of_template_file(template_path) if use_full_path
28
+ logger.info("Rendering #{template_path}" + (status ? " (#{status})" : '')) if logger
29
+ p = Hash.new
30
+ p[:product] = session[:product]
31
+ @template.setParmsForViewUse(p)
32
+ @template.setParmsForViewUse(@processMap)
33
+ text = @template.render(:file => template_path, :locals => locals, :layout => layout)
34
+ render_for_text text, status, true
35
+ end
36
+
37
+ def render_for_text(text = nil, status = nil, append_response = false) #:nodoc:
38
+ @performed_render = true
39
+
40
+ response.content_type = "text/html" #added this line over the standard rails method
41
+
42
+ response.headers['Status'] = interpret_status(status || DEFAULT_RENDER_STATUS_CODE)
43
+
44
+ if append_response
45
+ response.body ||= ''
46
+ response.body << text.to_s
47
+ else
48
+ response.body = case text
49
+ when Proc then text
50
+ when nil then " " # Safari doesn't pass the headers of the return if the response is zero length
51
+ else text.to_s
52
+ end
53
+ end
54
+ end
55
+
56
+ def massage(results)
57
+ #the search result will be an Array
58
+ #the normal response will be a hash of values to be displayed
59
+ #a hash entry maybe an array - this will be so when multiple occurrences of a relation is returned
60
+ #a url will be returned where's there is a redirection usually for paypal
61
+ if (results.is_a?(String) and results.include?("http"))
62
+ return results
63
+ elsif (results.is_a?(Hash))
64
+ results.each do |k,v|
65
+ if (v.is_a?(HashWithIndifferentAccess))
66
+ eval("@#{k} = #{k}.public_instantiate(v)")
67
+ elsif (v.is_a?(Array))
68
+ eval("@#{k} = Array.new")
69
+ #typically RAILS view code would interate over the instances for display purposes
70
+ v.each do |inst|
71
+ eval("@#{k}.push(#{k}.public_instantiate(inst))")
72
+ end
73
+ end
74
+ end
75
+ end
76
+ #nil implies there is no redirected URL
77
+ return nil
78
+ end
79
+
80
+ def sectionPremium
81
+ premium = Communicator.instance.handle(session,"SectionRating",params)
82
+
83
+ respond_to do |format|
84
+ format.js {render :text => "#{premium}" }
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,93 @@
1
+ require 'hooks/helpers/instance_tag'
2
+ class ActionView::Template
3
+ def source
4
+ if (self.filename.include?("oil"))
5
+ require 'LayoutInterpreter'
6
+ open(self.filename) {|f| @contents = f.read }
7
+ if (@view)
8
+ dsl = "product \"#{@view.productInfo[:product]}\"\n#{@view.navigationSteps}\n"+@contents.to_s
9
+ else
10
+ #the JRuby version inside tomcat seems to pass thru here before @view is setup, but then again once it is
11
+ #this is to allow it to work until this issue is better understood
12
+ dsl = "product \"Retailer\"\nnavigation [:QNBRiskDataCollect,:QuoteSearch,:PolicySearch,:CancelConfirm]\n"+@contents.to_s
13
+ end
14
+ erb = "\t<% widgetROOT=\"#{WIDGET_ROOT2}\" %>\n"
15
+ erb << "\t<% teaserROOT=\"#{TEASER_ROOT}\" %>\n"
16
+ erb << LayoutInterpreter.execute(dsl)
17
+ source ||= erb
18
+ else
19
+ source ||= File.read(self.filename)
20
+ end
21
+ source
22
+ end
23
+
24
+ def registerView(view)
25
+ @view = view
26
+ end
27
+ end
28
+ class ActionView::Base
29
+ def productInfo
30
+ @productInfo
31
+ end
32
+ def setParmsForViewUse(productInfo)
33
+ if (@productInfo)
34
+ @productInfo.merge!(productInfo)
35
+ else
36
+ @productInfo = productInfo
37
+ end
38
+ end
39
+
40
+ def navigationSteps
41
+ if @productInfo[@productInfo[:currentstep]] == nil
42
+ logger.error("Line of the form \"flow :#{@productInfo[:currentstep]} , [:nextstep1,:nextstep2,...]\" is missing in the \"valid_flows\" section of the product processes.oil file") if logger
43
+ end
44
+ steps = "navigation [:#{@productInfo[@productInfo[:currentstep]].first}"
45
+ @productInfo[@productInfo[:currentstep]].each do |action|
46
+ steps << ",:#{action}" unless action == @productInfo[@productInfo[:currentstep]].first
47
+ end
48
+ steps << "]"
49
+ steps
50
+ end
51
+
52
+ #added from ActionView::Base with additional call to registerView added in there
53
+ #not proud of the solution but need to quickly establish access to the base class from within the template
54
+ #to pick up some gui widget metadata used to control the navigation
55
+ #in rails 2.1 and below we had access to the ActionView::Base via @view instance var
56
+ def _pick_template(template_path)
57
+ return template_path if template_path.respond_to?(:render)
58
+
59
+ path = template_path.sub(/^\//, '')
60
+ if m = path.match(/(.*)\.(\w+)$/)
61
+ template_file_name, template_file_extension = m[1], m[2]
62
+ else
63
+ template_file_name = path
64
+ end
65
+
66
+ # OPTIMIZE: Checks to lookup template in view path
67
+ if template = self.view_paths["#{template_file_name}.#{template_format}"]
68
+ template
69
+ elsif template = self.view_paths[template_file_name]
70
+ template
71
+ elsif (first_render = @_render_stack.first) && first_render.respond_to?(:format_and_extension) &&
72
+ (template = self.view_paths["#{template_file_name}.#{first_render.format_and_extension}"])
73
+ template
74
+ elsif template_format == :js && template = self.view_paths["#{template_file_name}.html"]
75
+ @template_format = :html
76
+ template
77
+ else
78
+ template = ActionView::Template.new(template_path, view_paths)
79
+ template.registerView(self)
80
+
81
+ if self.class.warn_cache_misses && logger
82
+ logger.debug "[PERFORMANCE] Rendering a template that was " +
83
+ "not found in view path. Templates outside the view path are " +
84
+ "not cached and result in expensive disk operations. Move this " +
85
+ "file into #{view_paths.join(':')} or add the folder to your " +
86
+ "view path list"
87
+ end
88
+
89
+ template
90
+ end
91
+ end
92
+ #memoize :_pick_template
93
+ end
@@ -0,0 +1,15 @@
1
+ class ActiveRecord::Base
2
+ def method_missing(method_id, *args, &block)
3
+ begin
4
+ super
5
+ rescue
6
+ #needs to be less crude
7
+ #intention here is to trap RAILS failure when it cannot find/build an accessor method
8
+ #for a class property
9
+ #this will be the case with IAB because it only builds hashes that have values
10
+ #so properties in the data model that do not have values in an instance record
11
+ #in the DB will not result in an entry to the hash that defines the instance and hence
12
+ #RAILS will not be able to build a method via it's method missing with more sophisication
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,143 @@
1
+ require 'cgi'
2
+
3
+ module IabHelper
4
+ def resultsToRailsClass(rows)
5
+ results = []
6
+ if (rows != nil) then
7
+ rows.each do |r|
8
+ eval(r)
9
+ results.push(Searchresult.public_instantiate(@rowHash))
10
+ end
11
+ end
12
+ results
13
+ end
14
+
15
+ def format_mtas(mtas)
16
+ tab = "["
17
+ mtas.each do |mta|
18
+ applied_date = mta['AD']
19
+ start_date = mta['SD']
20
+ end_date = mta['ED']
21
+ rolled_back = mta['RB']
22
+ changes = mta['Changes']
23
+ tab << "{'AD':'#{applied_date}','SD':'#{start_date}','ED':'#{end_date}','RB':'#{rolled_back}','Changes':'#{changes}'}"
24
+ end
25
+ tab << "]"
26
+ CGI.escape(tab)
27
+ end
28
+
29
+ def mtaHeaderInfo
30
+ headers = '[
31
+ {"text":"MTA Applied Date","key":"AD","sortable":false,"fixedWidth":true,"defaultWidth":"100px"},
32
+ {"text":"MTA Start Date","key":"SD","sortable":false,"fixedWidth":true,"defaultWidth":"100px"},
33
+ {"text":"MTA End Date","key":"ED","sortable":false,"fixedWidth":true,"defaultWidth":"100px"},
34
+ {"text":"Rolled Back?","key":"RB","sortable":false,"fixedWidth":true,"defaultWidth":"100px"},
35
+ {"text":"What Changed?","key":"Changes","sortable":false,"defaultWidth":"280px"}]'
36
+ headers
37
+ end
38
+
39
+ #entity - substring after inClassname substring-before nodename <label class=\"rowLabel\" for=\"#{hashname}_#{property}\">#{property}</label>
40
+ #property - nodename #{inclassName} #{nodeN} result << widget :checkbox, inclassName, nodeN
41
+
42
+
43
+ def widgets(*args)
44
+ includes = ""
45
+ #pull in global jquery scripts used across all layouts
46
+ Dir.entries("#{JS_ROOT}").sort.each do |file_name|
47
+ if ((file_name =~ /.js$/) != nil and !@assets.has_key?(file_name.to_sym))
48
+ @assets[file_name.to_sym] = 1
49
+ includes << "<script src=\"#{JS_ROOT2}/#{file_name}\" type=\"text/javascript\" language=\"javascript\"></script>\n"
50
+ end
51
+ end
52
+ args.each do |a|
53
+ if (!@widgets.has_key?(a.to_sym))
54
+ @widgets[a.to_sym] = 1
55
+ Dir.entries("#{WIDGET_ROOT}/#{a}").each do |file_name|
56
+ if ((file_name =~ /.js$/) != nil or (file_name =~ /.css$/) != nil)
57
+ if ((file_name =~ /.js$/) != nil and !@assets.has_key?(file_name.to_sym))
58
+ @assets[file_name.to_sym] = 1
59
+ includes << "<script src=\"#{WIDGET_ROOT3}/#{a}/#{file_name}\" type=\"text/javascript\" language=\"javascript\"></script>\n"
60
+ elsif ((file_name =~ /.css$/) != nil and !@assets.has_key?(file_name.to_sym))
61
+ @assets[file_name.to_sym] = 1
62
+ includes << "<link href=\"#{WIDGET_ROOT3}/#{a}/#{file_name}\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n"
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ Dir.entries("#{BRANDS_ROOT}/#{session[:brand]}").each do |file_name|
69
+ if (file_name =~ /.css$/) != nil
70
+ includes << "<link href=\"/#{GIT}/brands/#{session[:brand]}/#{file_name}\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n"
71
+ end
72
+ end
73
+ includes
74
+ end
75
+
76
+ def getCSS(sheet)
77
+ open(File.join("#{LIBRARY_ROOT}/genericlayoutgrids/stylesheets/#{sheet}")) {|f| @css = f.read }
78
+ result = "<style type=\"text/css\">"+@css.to_s+"</style>"
79
+ result
80
+ end
81
+
82
+ # Only need this helper once, it will provide an interface to convert a block into a partial.
83
+ # 1. Capture is a Rails helper which will 'capture' the output of a block into a variable
84
+ # 2. Merge the 'body' variable into our options hash
85
+ # 3. Render the partial with the given options hash. Just like calling the partial directly.
86
+
87
+ def block_to_partial(partial_name, options = {}, &block)
88
+ #puts "PARTIAL_NAME=#{partial_name},OPTIONS=#{options},BLOCK=#{block}"
89
+ options.merge!(:body => capture(&block))
90
+ concat(render(:partial => partial_name, :locals => options))
91
+ end
92
+
93
+ def method_missing(m, *args, &block)
94
+ if (args[0] != nil and args[0].include?("widgets"))
95
+ puts "There's no method called #{m} with arg.length= #{args.length}, args=#{args} and block=#{block} here -- please try again."
96
+ #this will trap missing methods
97
+ #it traps missing widget methods with can take up to n args
98
+ #partialROOT, some arg 1...some arg n, properties
99
+ #OR
100
+ #partialROOT, some arg1... some arg n
101
+ props = {}
102
+ if (args.length > 1)
103
+ #last arg may be serialized array of metadata passed
104
+ #from the coverage interpreter (used to interpret the oil based data model)
105
+ props = eval(args.last) if args.last.include?("=>")
106
+
107
+ #now build up a block_to_partial method call that contains all the parameters
108
+ #passed, plus any property metadata loaded by the coverage interpreter
109
+ #we are building something of the form kike what appears on the line below
110
+ #block_to_partial("#{partialROOT}/extending_panel", props.merge(:arg1 => 'arg1 value'...), &block)
111
+
112
+ len = 1
113
+ metaData = false
114
+ if (args.last.include?("=>"))
115
+ len = 2
116
+ metaData = true
117
+ end
118
+
119
+ i = 0
120
+ comma = ""
121
+ arguments = "props"
122
+ if (args.length > len)
123
+ #arguments = "props.merge("
124
+ arguments = "["
125
+ args.each do |a|
126
+ comma = "," unless i < 2
127
+ arguments<< "#{comma}\"#{a}\"" unless (a == args.first or (a == args.last and metaData))
128
+ i = i + 1
129
+ end
130
+ #arguments << ")"
131
+ arguments << "]"
132
+ end
133
+
134
+ props["args"] = arguments
135
+ btp = "block_to_partial(\"#{args[0]}/#{m}\",props, &block)"
136
+ eval(btp)
137
+ else
138
+ block_to_partial("#{args[0]}/#{m}", props, &block)
139
+ end
140
+ end
141
+ end
142
+ end
143
+
@@ -0,0 +1,16 @@
1
+ class ActionView::Helpers::InstanceTag
2
+ def to_input_field_tag(field_type, options = {})
3
+ options = options.stringify_keys
4
+ options["size"] = options["maxlength"] || DEFAULT_FIELD_OPTIONS["size"] unless options.key?("size")
5
+ options = DEFAULT_FIELD_OPTIONS.merge(options)
6
+ if field_type == "hidden"
7
+ options.delete("size")
8
+ end
9
+ options["type"] = field_type
10
+ if (field_type != "file")
11
+ options["value"] = value_before_type_cast(object) unless !value_before_type_cast(object)
12
+ end
13
+ add_default_name_and_id(options)
14
+ tag("input", options)
15
+ end
16
+ end
@@ -0,0 +1,36 @@
1
+ module PaypalHelper
2
+ PAYMENT_AMOUNT_SESSION_KEY = :payment_amount
3
+
4
+ def payment_amount
5
+ session[PAYMENT_AMOUNT_SESSION_KEY]
6
+ end
7
+
8
+ #the following methods are automatically called from the iab_controller actions that are created at runtime
9
+ #the rule is that if a method whose name is the lowercase equivalent of the process 'do' step then it will get fired
10
+ #prior to calling communicator which controls access to the server logic
11
+ def checkout
12
+ session[PAYMENT_AMOUNT_SESSION_KEY] = "3000"
13
+ params = {
14
+ :payment_amount => payment_amount,
15
+ :ip => request.remote_ip,
16
+ :return_url => url_for(:action => 'PaymentConfirm', :only_path => false),
17
+ #TODO where do we go if the user cancels from making payment?
18
+ :cancel_return_url => url_for(:action => 'ProductSelection', :only_path => false)
19
+ }
20
+ params
21
+ end
22
+
23
+ def confirmpayment
24
+ params = { :token => @_params[:token] }
25
+ params
26
+ end
27
+
28
+ def completedpayment
29
+ params = {
30
+ :payment_amount => payment_amount,
31
+ :ip => request.remote_ip,
32
+ :payer_id => @_params[:payer_id],
33
+ :token => @_params[:token] }
34
+ params
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iab-RailsGlue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Gary Mawdsley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-31 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mime-types
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "1.15"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: diff-lcs
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.2
34
+ version:
35
+ description: RailsGlue is a series hooks that allow other iab components to work atop of RAILS
36
+ email: garymawdsley@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - lib/hooks
45
+ - lib/hooks/controllers
46
+ - lib/hooks/controllers/iabbase_controller.rb
47
+ - lib/hooks/helpers
48
+ - lib/hooks/helpers/instance_tag.rb
49
+ - lib/hooks/helpers/paypal_helper.rb
50
+ - lib/hooks/helpers/ActionView.rb
51
+ - lib/hooks/helpers/ActiveRecord.rb
52
+ - lib/hooks/helpers/iab_helper.rb
53
+ has_rdoc: true
54
+ homepage: http://github.com/iab/RailsGlue
55
+ post_install_message:
56
+ rdoc_options:
57
+ - --inline-source
58
+ - --charset=UTF-8
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ requirements: []
74
+
75
+ rubyforge_project: RailsGlue
76
+ rubygems_version: 1.2.0
77
+ signing_key:
78
+ specification_version: 2
79
+ summary: RailsGlue is a series hooks that allow other iab components to work atop of RAILS
80
+ test_files: []
81
+