Module: IabHelper

Defined in:
lib/hooks/helpers/iab_helper.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/hooks/helpers/iab_helper.rb', line 102

def method_missing(m, *args, &block)
  if (args[0] != nil and args[0].include?("widgets"))
    #puts "There's no method called #{m} with arg.length= #{args.length}, args=#{args} and block=#{block} here -- please try again."
    #this will trap missing methods
    #it traps missing widget methods with can take up to n args
    #partialROOT, some arg 1...some arg n, properties
    #OR
    #partialROOT, some arg1... some arg n
    props = {}
    if (args.length > 1)
      #last arg may be serialized array of metadata passed
      #from the coverage interpreter (used to interpret the oil based data model)
      props = eval(args.last) if args.last.include?("=>")

      #now build up a block_to_partial method call that contains all the parameters
      #passed, plus any property metadata loaded by the coverage interpreter
      #we are building something of the form kike what appears on the line below
      #block_to_partial("#{partialROOT}/extending_panel", props.merge(:arg1 => 'arg1 value'...), &block)

      len = 1
       = false
      if (args.last.include?("=>"))
        len = 2
         = true
      end

      i = 0
      comma = ""
      arguments = "props"
      if (args.length > len)
        #arguments = "props.merge("
        arguments = "["
        args.each do |a|
          comma = "," unless i < 2
          arguments<< "#{comma}\"#{a}\"" unless (a == args.first or (a == args.last and ))
          i = i + 1
        end
        #arguments << ")"
        arguments << "]"
      end

      props["args"] = arguments
      btp = "block_to_partial(\"#{args[0]}/#{m}\",props, &block)"
      eval(btp)
    else
      block_to_partial("#{args[0]}/#{m}", props, &block)
    end
  end
end

Instance Method Details

#block_to_partial(partial_name, options = {}, &block) ⇒ Object

Only need this helper once, it will provide an interface to convert a block into a partial.

  1. Capture is a Rails helper which will ‘capture’ the output of a block into a variable

  2. Merge the ‘body’ variable into our options hash

  3. Render the partial with the given options hash. Just like calling the partial directly.



96
97
98
99
100
# File 'lib/hooks/helpers/iab_helper.rb', line 96

def block_to_partial(partial_name, options = {}, &block)
  #puts "PARTIAL_NAME=#{partial_name},OPTIONS=#{options},BLOCK=#{block}"
  options.merge!(:body => capture(&block))
  concat(render(:partial => partial_name, :locals => options))
end

#ci_widgets(*args) ⇒ Object



43
44
45
# File 'lib/hooks/helpers/iab_helper.rb', line 43

def ci_widgets(*args)
  include_widgets(*args)
end

#format_mtas(mtas) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/hooks/helpers/iab_helper.rb', line 15

def format_mtas(mtas)
  tab = "["
  mtas.each do |mta|
    applied_date = mta['AD']
    start_date = mta['SD']
    end_date = mta['ED']
    rolled_back = mta['RB']
    changes = mta['Changes']
    tab << "{'AD':'#{applied_date}','SD':'#{start_date}','ED':'#{end_date}','RB':'#{rolled_back}','Changes':'#{changes}'}"
  end
  tab << "]"
  CGI.escape(tab)
end

#getCSS(sheet) ⇒ Object



85
86
87
88
89
# File 'lib/hooks/helpers/iab_helper.rb', line 85

def getCSS(sheet)
  open(File.join("#{LIBRARY_ROOT}/genericlayoutgrids/stylesheets/#{sheet}")) {|f| @css = f.read }
  result = "<style type=\"text/css\">"+@css.to_s+"</style>"
  result
end

#include_widgets(*args) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/hooks/helpers/iab_helper.rb', line 57

def include_widgets(*args)
  includes = ""
  #pull in global jquery scripts used across all layouts
  Dir.entries("#{JS_ROOT}").sort.each do |file_name|
    if ((file_name =~ /.js$/) != nil and !@assets.has_key?(file_name.to_sym))
      @assets[file_name.to_sym] = 1
      includes << "<script src=\"#{JS_ROOT2}/#{file_name}\" type=\"text/javascript\" language=\"javascript\"></script>\n"
    end
  end
  args.each do |a|
    if (!@widgets.has_key?(a.to_sym))
      @widgets[a.to_sym] = 1
      Dir.entries("#{WIDGET_ROOT}/#{a}").each do |file_name|
        if ((file_name =~ /.js$/) != nil or (file_name =~ /.css$/) != nil)
          if ((file_name =~ /.js$/) != nil and !@assets.has_key?(file_name.to_sym))
            @assets[file_name.to_sym] = 1
            includes << "<script src=\"#{WIDGET_ROOT3}/#{a}/#{file_name}\" type=\"text/javascript\" language=\"javascript\"></script>\n"
          elsif ((file_name =~ /.css$/) != nil and !@assets.has_key?(file_name.to_sym))
            @assets[file_name.to_sym] = 1
            includes << "<link href=\"#{WIDGET_ROOT3}/#{a}/#{file_name}\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n"
          end
        end
      end
    end
  end
  includes
end

#mtaHeaderInfoObject



29
30
31
32
33
34
35
36
37
# File 'lib/hooks/helpers/iab_helper.rb', line 29

def mtaHeaderInfo
  headers = '[
{"text":"MTA Applied Date","key":"AD","sortable":false,"fixedWidth":true,"defaultWidth":"100px"},
{"text":"MTA Start Date","key":"SD","sortable":false,"fixedWidth":true,"defaultWidth":"100px"},
{"text":"MTA End Date","key":"ED","sortable":false,"fixedWidth":true,"defaultWidth":"100px"},
{"text":"Rolled Back?","key":"RB","sortable":false,"fixedWidth":true,"defaultWidth":"100px"},
{"text":"What Changed?","key":"Changes","sortable":false,"defaultWidth":"280px"}]'
  headers
end

#resultsToRailsClass(rows) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/hooks/helpers/iab_helper.rb', line 4

def resultsToRailsClass(rows)
   results = []
   if (rows != nil) then
     rows.each do |r|
       eval(r)
       results.push(Searchresult.public_instantiate(@rowHash))
     end
   end
   results
end

#widgets(*args) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/hooks/helpers/iab_helper.rb', line 47

def widgets(*args)
  includes = include_widgets(*args)
  Dir.entries("#{BRANDS_ROOT}/#{session[:brand]}").each do |file_name|
    if (file_name =~ /.css$/) != nil
       includes << "<link href=\"/#{GIT}/brands/#{session[:brand]}/#{file_name}\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n"
    end
  end
  includes
end