iab-Oil 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,48 @@
1
+ require File.join(File.dirname(__FILE__),'DSLContext')
2
+
3
+ #create class that fills in for the RAILS class when rails is not around, e.g. when testing
4
+ #when RAILS is around this will have no effect
5
+ class HashWithIndifferentAccess < Hash
6
+ end
7
+
8
+ class CollesceProductInterpreter < DslContext
9
+
10
+ bubble :than, :is, :list, :the, :to, :at, :it, :end
11
+
12
+ def getResult
13
+ result = Array.new
14
+ result[0] = @entities
15
+ result[1] = @coverages
16
+ result
17
+ end
18
+
19
+ def product(*args)
20
+ @entities = Hash.new
21
+ @coverages = Hash.new
22
+ end
23
+
24
+ def endproduct
25
+ end
26
+
27
+ def entities(*args)
28
+ @libtype = "entities"
29
+ end
30
+
31
+ def endentities
32
+ end
33
+
34
+ def coverages(*args)
35
+ @libtype = "coverages"
36
+ end
37
+
38
+ def endcoverages
39
+ end
40
+
41
+ def has_one(*args)
42
+ @entities[args[0]] = "has_one" if @libtype == "entities"
43
+ @coverages[args[0]] = "has_one" if @libtype == "coverages"
44
+ end
45
+
46
+ def has_many(*args)
47
+ end
48
+ end
@@ -0,0 +1,161 @@
1
+ require 'set'
2
+ require File.join(File.dirname(__FILE__),'DSLContext')
3
+
4
+ #create class that fills in for the RAILS class when rails is not around, e.g. when testing
5
+ #when RAILS is around this will have no effect
6
+ class HashWithIndifferentAccess < Hash
7
+ end
8
+
9
+ class CoverageInterpreter < DslContext
10
+
11
+ bubble :than, :is, :list, :the, :to, :at, :it, :end
12
+
13
+ def initialize(*args)
14
+ @columns = 1
15
+ @hidden_fields = Set.new
16
+ end
17
+
18
+ def getResult
19
+ widgets = ""
20
+ @widgets.each { |k| widgets << ",'#{k}'" }
21
+ @erb = "<%= widgets(#{widgets[1..-1]}) %>\n" + @erb unless widgets.length == 0
22
+ @erb
23
+ end
24
+
25
+ def hideFields(*args)
26
+ args[0].split('&').each { |a| @hidden_fields << a.to_sym }
27
+ end
28
+
29
+ def columns(*args)
30
+ @columns = args[0].to_i
31
+ end
32
+
33
+ def coverage(*args)
34
+ begin_erb(COVERAGE_DEF_ROOT, args)
35
+ end
36
+
37
+ def endcoverage(*args)
38
+ end_erb
39
+ end
40
+
41
+ def entity(*args)
42
+ begin_erb(ENTITY_DEF_ROOT, args)
43
+ end
44
+
45
+ def endentity(*args)
46
+ end_erb
47
+ end
48
+
49
+ def use(*args)
50
+ #the test on hidden_fields property is a bit too brutal in that it cuts out a whole part of the tree
51
+ #it serves to provide the same hiding capability as we had in the iteration earlier this day
52
+ #but more consideration especially around individual field level restriction needs to be considered
53
+ #i.e. we may want to keep part of the tree but loose some of the fields at that level
54
+ #so that we need considering in the code block below
55
+ args.each { |a| return if @hidden_fields.include?(a.to_sym) unless a.class.name == 'Hash' }
56
+
57
+ # If the last argument is a hash we assume it's a hash of overrides which we remove
58
+ # and merge in later.
59
+ args_hash = nil
60
+ args_hash = args.pop if args.last.class.name == 'Hash'
61
+
62
+ #now figure out whether the last arg above leads to an empty hash
63
+ #not strictly empty since every hash has an xpath property of the position in the class hierarchy
64
+ #if so backup a level and read the property whose name = the last arg value passed in
65
+ lastArg = ""
66
+ specificProperty = false
67
+ myHash = @prdhash["#{@argName}#{args}"]
68
+ raise "Failed to find [#{@argName}#{args}] in [#{@argName}PropertyHash]" if myHash == nil
69
+
70
+ # Have a look for meta data pertaining to the class which may specify a type.
71
+ class_meta_data = @prdhash["#{@argName}#{args}MD"]
72
+ specific_widget = class_meta_data[:type] unless class_meta_data == nil
73
+
74
+ if (myHash.length == 1)
75
+ specificProperty = true
76
+ lastArg = args.pop
77
+ myHash = @prdhash["#{@argName}#{args}"]
78
+ # Since we are delegating to our parent definition we look at that for a type
79
+ # specification if we haven' already found one.
80
+ #class_meta_data = @prdhash["#{@argName}#{args}MD"] if specific_widget == nil
81
+ #specific_widget = class_meta_data[:type] unless class_meta_data == nil
82
+ end
83
+
84
+ @widgets << specific_widget unless specific_widget == nil
85
+ @erb << "<% #{specific_widget} \"#\{widgetROOT}/#{specific_widget}\" do %>" unless specific_widget == nil
86
+
87
+ myHash.each do |property, value|
88
+ if (property != 'xpath' and (property =~ /MD$/) == nil) then
89
+ #properties of type HashWithIndifferentAccess hold metadata about the property
90
+ if (value == "" && (!specificProperty || (specificProperty && property == "#{lastArg}"))) then
91
+
92
+ if (@columns > 1)
93
+ @erb << '<tr>' if @col == 1
94
+ @erb << "<td width=\"#{100/@columns}%\">"
95
+ #@erb << "<div style=\"display: inline-block;float: left;width: #{(100/@columns)}%;\">"
96
+ end
97
+
98
+ metaData = myHash["#{property}MD"]
99
+ metaData = metaData.merge(args_hash) unless args_hash == nil
100
+ sMetaData = "{"
101
+ metaData.each { |n, v| sMetaData << "'#{n}' => '#{v}'," }
102
+ sMetaData << ":entityName => '#{@argName}#{args}',"
103
+ sMetaData << ":propertyName => '#{property}'"
104
+ sMetaData << "}"
105
+ #puts "METADATA:#{property}:#{metaData['mask']}_input:#{metaData['type']}_input"
106
+ @erb << "<% singleline_rowpanel \"#\{widgetROOT}/singleline_rowpanel\",\"#{sMetaData}\" do %>\n"
107
+ @widgets << "singleline_rowpanel"
108
+
109
+ if (metaData['type'] != nil) then
110
+ @widgets << "#{metaData['type']}_input"
111
+ @erb << "<% #{metaData['type']}_input \"#\{widgetROOT}/#{metaData['type']}_input\",\"#{sMetaData}\" do %>\n<% end %>"
112
+ elsif (metaData['mask'] != nil) then
113
+ @widgets << "#{metaData['mask']}_input"
114
+ @erb << "<% #{metaData['mask']}_input \"#\{widgetROOT}/#{metaData['mask']}_input\",\"#{sMetaData}\" do %>\n<% end %>"
115
+ else
116
+ @widgets << "text_input"
117
+ @erb << "<% text_input \"#\{widgetROOT}/text_input\",\"#{sMetaData}\" do %>\n<% end %>"
118
+ end
119
+
120
+ @erb << "\n<% end %>"
121
+
122
+ if (@columns > 1)
123
+ #@erb << '</div>'
124
+ @erb << '</td>'
125
+ @erb << '</tr>' if @col == @columns
126
+ @col = 0 if @col == @columns
127
+ @col += 1
128
+ end
129
+ end
130
+ end
131
+ end
132
+ @erb << '<% end %>' unless specific_widget == nil
133
+ end
134
+
135
+ private
136
+ def begin_erb(dsl_root, *args)
137
+ @widgets = Set.new
138
+ @col = 1
139
+ @argName = "#{args[0]}"
140
+ @prdhash = YAML::load(open(File.join(dsl_root,"/#{@argName}PropertyHash"),'r' ))
141
+ # Check to see if there's meta data specifying a type for this class.
142
+ class_meta_data = @prdhash["#{@argName}MD"]
143
+ specific_widget = class_meta_data[:type] unless class_meta_data == nil
144
+ @widgets << specific_widget unless specific_widget == nil
145
+ @erb = ''
146
+ @erb = "<% #{specific_widget} \"#\{widgetROOT}/#{specific_widget}\" do %>" unless specific_widget == nil
147
+ @erb << '<table width="100%">' if @columns > 1
148
+ end
149
+
150
+ private
151
+ def end_erb()
152
+ if(@columns > 1)
153
+ @erb << '</tr>' if @erb.match(/tr>$/) == nil
154
+ @erb << '</table>'
155
+ end
156
+ class_meta_data = @prdhash["#{@argName}MD"]
157
+ specific_widget = class_meta_data[:type] unless class_meta_data == nil
158
+ @erb << '<% end %>' unless specific_widget == nil
159
+ end
160
+ end
161
+
@@ -0,0 +1,36 @@
1
+ require 'DSLContext'
2
+
3
+ class CoverageInterpreter2 < DslContext
4
+ def initialize
5
+ @name = ''
6
+ @entity = Array.new
7
+ end
8
+
9
+ def getResult
10
+ @entity
11
+ end
12
+
13
+ def coverage(*args)
14
+ @name = args[0].to_s
15
+ end
16
+
17
+ def endcoverage(*args)
18
+ #nothing to do here at the mo
19
+ end
20
+
21
+ def entity(*args)
22
+ coverage(args)
23
+ end
24
+
25
+ def endentity(*args)
26
+ endcoverage(args)
27
+ end
28
+
29
+ def use(*args)
30
+ # remove the trailing defaults and stuff
31
+ if(args.last.class.name == 'Hash')
32
+ args.pop
33
+ end
34
+ @entity << args.collect{ |p| ':' + (p.to_s()) }.join(',')
35
+ end
36
+ end
data/lib/DSLContext.rb ADDED
@@ -0,0 +1,28 @@
1
+ class DslContext
2
+ def self.execute(*args)
3
+ rules = polish_text(args[0])
4
+ #significant change to allow class instance variables to be set on the initialize, ahead
5
+ #of the evaluation of the DSL - allows dynamic props to be sent to the class
6
+ #see VPMSProductSchemaInterpreter, which gets a param from the package interpreter
7
+ inst = (args.length > 1) ? self.new(args.slice(1,1)) : self.new
8
+ rules.each do |rule|
9
+ result = inst.instance_eval(rule)
10
+ #passes results as parm into code that was passed with call to execute (if any was)
11
+ yield result if block_given?
12
+ end
13
+ inst.getResult
14
+ end
15
+
16
+ def self.polish_text(text)
17
+ rules = text.split("\n")
18
+ rules.collect do |rule|
19
+ rule << " "
20
+ end
21
+ end
22
+
23
+ def self.bubble(*methods)
24
+ methods.each do |method|
25
+ define_method(method) {}
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,109 @@
1
+ require 'set'
2
+ require File.join(File.dirname(__FILE__),'DSLContext')
3
+ require 'Element'
4
+
5
+ class DataModelInterpreter < DslContext
6
+ def initialize
7
+ @elements = []
8
+ @elementTree = []
9
+ @depth=0
10
+ end
11
+
12
+ def getResult
13
+ #dumpParsedStructure
14
+ result = @elements
15
+ result
16
+ end
17
+ # --parse - implement the grammar
18
+ def datamodel(*args)
19
+ end
20
+
21
+ def enddatamodel(*args)
22
+ end
23
+
24
+ def createNewElement(name,coverage,parent,type)
25
+ e = ElementFactory(name,coverage,parent,type)
26
+ @elementTree.last.children.push e if @elementTree.last and @elementTree.length > 0
27
+ @elementTree.push e
28
+ end
29
+
30
+ def ElementFactory(name,coverage,parent,type)
31
+ @elements.each do |node|
32
+ if node.name == name
33
+ node.parent = parent
34
+ return node
35
+ end
36
+ end
37
+ e = Element.new(name,coverage,parent,type)
38
+ @elements.push e
39
+ return e
40
+ end
41
+
42
+ def element(*args)
43
+ createNewElement(args[0],false,@elementTree.last,nil)
44
+ end
45
+
46
+ def endelement(*args)
47
+ @elementTree.pop
48
+ end
49
+
50
+ def coverage(*args)
51
+ createNewElement(args[0]+ "Coverage",true,@elementTree.last,"coverages")
52
+ end
53
+
54
+ def endcoverage(*args)
55
+ @elementTree.pop
56
+ end
57
+
58
+ def entity(*args)
59
+ createNewElement(args[0],true,@elementTree.last,"entities")
60
+ end
61
+
62
+ def endentity(*args)
63
+ @elementTree.pop
64
+ end
65
+
66
+ def field(*args)
67
+ if (args[0][:ctype] != nil)
68
+ if (@elementTree.last.coverage)
69
+ parent = nil
70
+ else
71
+ parent = @elementTree.last
72
+ end
73
+ createNewElement(args[0][:ctype],false,parent,nil) #the parent is nil here since a complex type may be used by many coverages or entities
74
+ @elementTree.pop
75
+ else
76
+ @elementTree.last.fields.push args[0]
77
+ end
78
+ end
79
+
80
+ #----------- dump
81
+
82
+ def dumpParsedStructure
83
+ @dumpStructure = ""
84
+ @elements.each do |e|
85
+ if (e.coverage)
86
+ @dumpStructure << "#{e.name}:\n"
87
+ listChildren(e)
88
+ @dumpStructure << "\n"
89
+ end
90
+ end
91
+ puts "#{@dumpStructure}"
92
+ end
93
+
94
+ def listChildren(e)
95
+ @depth = @depth + 1
96
+ e.children.each do |c|
97
+ str = ""
98
+ @depth.times { str << "\t"}
99
+ @dumpStructure << "#{str}#{c.name}\n"
100
+ c.fields.each do |f|
101
+ str = ""
102
+ @depth.times { str << "\t\t"}
103
+ @dumpStructure << "#{str}field:#{f}\n"
104
+ end
105
+ listChildren(c)
106
+ @depth = @depth - 1
107
+ end
108
+ end
109
+ end
data/lib/Element.rb ADDED
@@ -0,0 +1,12 @@
1
+ class Element
2
+ attr_accessor :coverage,:name,:children,:parent,:fields,:type
3
+
4
+ def initialize(name,isaentityorcoverage,parent,type)
5
+ @coverage = isaentityorcoverage
6
+ @name = name
7
+ @children = []
8
+ @parent = parent
9
+ @fields = []
10
+ @type = type
11
+ end
12
+ end
@@ -0,0 +1,166 @@
1
+ require File.join(File.dirname(__FILE__),'DSLContext')
2
+ require File.join(File.dirname(__FILE__),'CoverageInterpreter')
3
+
4
+ class LayoutInterpreter < DslContext
5
+
6
+ bubble :than, :is, :list, :the, :to, :at, :it, :endheader, :endlayout, :endfooter
7
+
8
+ def getResult
9
+ widgets = ""
10
+ @widgets.each do |k,v|
11
+ widgets << ",'#{k}'"
12
+ end
13
+ @erb = "<%= widgets(#{widgets[1..-1]}) %>\n" + @erb unless widgets.length == 0
14
+ @erb
15
+ end
16
+
17
+ def product(*args)
18
+ @product = args[0]
19
+ end
20
+
21
+ def navigation(steps)
22
+ @navigationSteps = steps
23
+ end
24
+
25
+ def layout(*args)
26
+ @widgets = Hash.new
27
+ @erb = "<head>\n"
28
+ @erb << "<%= getCSS('#{args[0]}.css') %>\n"
29
+ @erb << "</head>\n"
30
+ @erb << "<body>\n"
31
+ @erb << "\t<div class=\"container\">\n"
32
+ end
33
+
34
+ def endlayout(*args)
35
+ @erb << "\t</div>\n"
36
+ @erb << "</body>"
37
+ end
38
+
39
+ def header(*args)
40
+ @erb << "\t\t<div class=\"header\">\n"
41
+ end
42
+
43
+ def endheader(*args)
44
+ @erb << "\t\t</div>\n"
45
+ end
46
+
47
+ def miniheader(*args)
48
+ @erb << "\t\t<div class=\"mini-header\">#{args[0]}\n"
49
+ end
50
+
51
+ def endminiheader(*args)
52
+ @erb << "\t\t</div>\n"
53
+ end
54
+
55
+ def column(*args)
56
+ @erb << "\t\t<td style=\"vertical-align: top;\">\n"
57
+ end
58
+
59
+ def endcolumn
60
+ @erb << "\t\t</td>\n"
61
+ end
62
+
63
+ def columns
64
+ @erb << "\t\t<table class=\"columnWrapper\"><tr>\n"
65
+ end
66
+
67
+ def endcolumns
68
+ @erb << "\t\t</tr></table>\n"
69
+ end
70
+
71
+ def footer(*args)
72
+ @erb << "\t\t<div class=\"footer\">\n"
73
+ end
74
+
75
+ def endfooter(*args)
76
+ @erb << "\t\t</div>\n"
77
+ end
78
+
79
+ def panel(*args)
80
+ if args.length > 0
81
+ @erb << "\t\t\t<div class=\"#{args[0]}\">\n"
82
+ else
83
+ @erb << "\t\t\t<div>\n"
84
+ end
85
+ end
86
+
87
+ def endpanel
88
+ @erb << "\t\t\t</div>\n"
89
+ end
90
+
91
+ def product_menu(*args)
92
+ #TODO:slidingMenu needs implementing as a single item menu construct
93
+ #that is repeated for each of theargs
94
+ @erb << "\t\t\t"
95
+ @erb << '<%= render :partial => "#{widgetROOT}/sliding_menu/sliding_menu", :locals => { :menuitems => %w('
96
+ @erb << args.join(' ')
97
+ @erb << ') } %>'
98
+ @erb << "\n"
99
+ end
100
+
101
+ def teaser(*args)
102
+ @erb << "\t\t\t<%= render :partial => \"#\{teaserROOT}/#{args[0]}\" %>\n"
103
+ end
104
+
105
+ def widget(*args)
106
+ @widgets["#{args[0]}"] = 1
107
+
108
+ @erb << "\t\t\t<% #{args[0]} \"#\{widgetROOT}/#{args[0]}\""
109
+
110
+ widget_args_hash = args[1]
111
+
112
+ if (@navigationSteps.length > 0)
113
+ if (args[0].to_sym == :submit_panel)
114
+ widget_args_hash = {:nextLayout => @navigationSteps[0].to_sym}
115
+ elsif (args[0].to_sym == :button_panel)
116
+ str = "{:button1 => :#{@navigationSteps.first}"
117
+ i = 1
118
+ @navigationSteps.each do |step|
119
+ str << ",:button#{i += 1} => :#{step}" unless step == @navigationSteps.first
120
+ end
121
+ str << "}"
122
+ widget_args_hash = eval(str)
123
+ end
124
+ end
125
+
126
+
127
+ if (widget_args_hash and widget_args_hash.class.name == "Hash")
128
+ sHash = "{"
129
+ comma = ""
130
+ widget_args_hash.each do |n,v|
131
+ sHash << "#{comma}:#{n} => '#{v}'"
132
+ comma = ","
133
+ end
134
+ sHash << "}"
135
+
136
+ @erb << ",\"#{sHash}\" do %>\n"
137
+ else
138
+ @erb << " do %>\n"
139
+ end
140
+ end
141
+
142
+ def endwidget
143
+ @erb << "\t\t\t <% end %>\n"
144
+ end
145
+
146
+ def entity(*args)
147
+ interpret(ENTITY_DSL_ROOT, *args)
148
+ end
149
+
150
+ def coverage(*args)
151
+ interpret(COVERAGE_DSL_ROOT, *args)
152
+ end
153
+
154
+ private
155
+ def interpret(dslroot, *args)
156
+ path = dslroot.gsub(/%product/,@product)
157
+ open(File.join(path,"/#{args[0]}.oil")) {|f| @contents = f.read }
158
+ dsl = ''
159
+ if (args[1])
160
+ dsl << "hideFields \"#{args[1][:hide]}\"\n" if args[1][:hide]
161
+ dsl << "columns \"#{args[1][:columns]}\"\n" if args[1][:columns]
162
+ end
163
+ dsl << @contents.to_s
164
+ @erb << CoverageInterpreter.execute(dsl, args[1])
165
+ end
166
+ end
@@ -0,0 +1,51 @@
1
+ require 'DSLContext'
2
+
3
+ class ProductInterpreter2 < DslContext
4
+
5
+ attr_reader :entity
6
+ attr_reader :coverage
7
+
8
+ def initialize
9
+ @name = ''
10
+ @entity = Array.new
11
+ @coverage = Array.new
12
+ end
13
+
14
+ def getResult
15
+ self
16
+ end
17
+
18
+ def product(*args)
19
+ @name = args[0]
20
+ end
21
+
22
+ def endproduct(*args)
23
+
24
+ end
25
+
26
+ def coverages(*args)
27
+ @currentGroup = @coverage
28
+ end
29
+
30
+ def endcoverages(*args)
31
+ end
32
+
33
+ def entities(*args)
34
+ @currentGroup = @entity
35
+ end
36
+
37
+ def endentities(*args)
38
+ end
39
+
40
+ def has_one(*args)
41
+ @currentGroup.push([args[0].to_s(), 'has_one'])
42
+ end
43
+
44
+ def has_many(*args)
45
+ @currentGroup.push([args[0].to_s(), 'has_many'])
46
+ end
47
+
48
+ def has_between(*args)
49
+ @currentGroup.push([args[0].to_s(), 'has_many'])
50
+ end
51
+ end
@@ -0,0 +1,60 @@
1
+ require File.join(File.dirname(__FILE__),'DSLContext')
2
+
3
+ #create class that fills in for the RAILS class when rails is not around, e.g. when testing
4
+ #when RAILS is around this will have no effect
5
+ class HashWithIndifferentAccess < Hash
6
+ end
7
+
8
+ class RailsProcessInterpreter < DslContext
9
+
10
+ bubble :channels,:channel,:processes,:process,:to,:endprocess,:endprocesses,:endchannel,:endchannels
11
+
12
+ def getResult
13
+ @result
14
+ end
15
+
16
+ def workflow_steps
17
+ @result = ""
18
+ end
19
+
20
+ def endworkflow_steps
21
+ end
22
+
23
+ def flow(*args)
24
+ #serialize array
25
+ sarray ="["
26
+ args[1].each do |a|
27
+ if (a == args[1].first)
28
+ sarray << ":#{a}"
29
+ else
30
+ sarray << ",:#{a}"
31
+ end
32
+ end
33
+ sarray << "]"
34
+ @result << ":#{args[0]} => #{sarray},"
35
+ end
36
+
37
+ def valid_flows(*args)
38
+ @result << "def wireProcess\n"
39
+ @result << "@processMap = {"
40
+ end
41
+
42
+ def endvalid_flows(*args)
43
+ @result << "}\n"
44
+ @result << "end"
45
+ end
46
+
47
+ def step(*args)
48
+ #there will be at least five parameters for an IAB app - rails controller, rails action, language, brand, product
49
+ controller_process_step = "if self.respond_to?(:#{args[1][:do].to_s.downcase})\nparams.merge!(#{args[1][:do].to_s.downcase})\nend" if (args[1][:do])
50
+ engine_call = ""
51
+ engine_call << "@results = Communicator.instance.handle(session,\"#{args[1][:do]}\",params)" if (args[1][:do])
52
+ marshalling = ""
53
+ marshalling << "possible_redirect = massage(@results) if @results\nif possible_redirect\nredirect_to possible_redirect\nreturn\nend" if (args[1][:do])
54
+ injectLayoutDict = "introduce_layout_dictionary(\"#{args[1][:template]}\")"
55
+
56
+ action = "def #{args[0]}\n@template.setParmsForViewUse({:currentstep => :#{args[0]}})\n#{controller_process_step}\n#{engine_call}\n#{marshalling}\n#{injectLayoutDict}\nrender :template => \"#{args[1][:template]}.oil\", :layout => \"#{args[1][:layout]}\"\nend\n"
57
+ #puts("introducing controller action\n#{action}")
58
+ @result << action
59
+ end
60
+ end