fabulator 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,12 @@
1
+ === 0.0.12 2010-12-03
2
+
3
+ * 1 major enhancement:
4
+ * Added <template /> element to libraries
5
+
6
+ * 2 minor enhancements:
7
+ * Fixed various XSLT issues with form markup
8
+ * Fixed scope issue that caused <for-each /> failure with @as
9
+
1
10
  === 0.0.11 2010-11-11
2
11
 
3
12
  * 1 bug fix
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.11
1
+ 0.0.12
@@ -13,19 +13,37 @@ module Fabulator
13
13
 
14
14
  def run(context, autovivify = false)
15
15
  @context.with(context) do |ctx|
16
- items = self.select(ctx) #@select.run(ctx)
16
+ items = self.select(ctx)
17
17
  res = nil
18
18
  ctx.in_context do |c|
19
19
  if !@sorts.empty?
20
- items = items.sort_by{ |i|
21
- c.set_var(self.as, i) unless self.as.nil?
22
- @sorts.collect{|s| s.run(c.with_root(i)) }.join("\0")
23
- }
20
+ if self.as.nil?
21
+ items = items.sort_by{ |i|
22
+ @sorts.collect{|s| s.run(c.with_root(i)) }.join("\0")
23
+ }
24
+ else
25
+ items = items.sort_by{ |i|
26
+ r = nil
27
+ c.in_context do |cc|
28
+ cc.set_var(self.as, i)
29
+ r = @sorts.collect{|s| s.run(cc.with_root(i)) }.join("\0")
30
+ end
31
+ r
32
+ }
33
+ end
24
34
  end
25
35
  res = [ ]
26
- items.each do |i|
27
- c.set_var(self.as, i) unless self.as.nil?
28
- res = res + self.run_actions(c.with_root(i))
36
+ if self.as.nil?
37
+ items.each do |i|
38
+ res = res + self.run_actions(c.with_root(i))
39
+ end
40
+ else
41
+ items.each do |i|
42
+ c.in_context do |cc|
43
+ cc.set_var(self.as, i) unless self.as.nil?
44
+ res = res + self.run_actions(cc.with_root(i))
45
+ end
46
+ end
29
47
  end
30
48
  end
31
49
  return res
@@ -48,7 +48,7 @@ module_eval(<<'...end xsm_expression_parser.racc/module_eval...', 'xsm_expressio
48
48
  @yydebug = true
49
49
 
50
50
  @last_token = nil
51
-
51
+
52
52
  do_parse
53
53
  end
54
54
 
@@ -62,6 +62,7 @@ module Fabulator
62
62
  structural :mapping, Mapping
63
63
  structural :reduction, Reduction
64
64
  structural :consolidation, Consolidation
65
+ structural :template, Template
65
66
  #structural :type, Type
66
67
  #structural :filter, Filter
67
68
  #structural :constraint, Constraint
@@ -31,6 +31,82 @@ module Fabulator
31
31
 
32
32
  has_actions
33
33
  end
34
+
35
+ class Template < Fabulator::Structural
36
+ namespace FAB_LIB_NS
37
+
38
+ attribute :name, :static => true
39
+
40
+ def compile_xml(xml, context)
41
+ super
42
+
43
+ @actions = [ ]
44
+ @wrapper = [ ]
45
+
46
+ if !xml.nil?
47
+ ctx = nil
48
+ if xml.name == 'template' && xml.namespaces.namespace.href == FAB_LIB_NS
49
+ ctx = @context.merge(xml)
50
+ @wrapper = [ '', '' ]
51
+ else
52
+ ctx = @context.merge
53
+ # we need to set @wrapper to [ begin, end ]
54
+ s = ""
55
+ if (xml.namespaces.namespace.prefix rescue nil)
56
+ s += xml.namespaces.namespace.prefix + ":"
57
+ end
58
+ s += xml.name
59
+ e = "</" + s + ">"
60
+ s = "<" + s
61
+ xml.each_attr do |attr|
62
+ s += " "
63
+ if attr.ns?
64
+ s += attr.ns.prefix + ":"
65
+ end
66
+ s += attr.name + "="
67
+ if attr.value =~ /"/
68
+ s += "'" + attr.value.gsub(/&/, '&amp;').gsub(/</, '&lt;').gsub(/'/, '&quot;') + "'"
69
+ else
70
+ s += '"' + attr.value.gsub(/&/, '&amp;').gsub(/</, '&lt;') + '"'
71
+ end
72
+ end
73
+ s += ">"
74
+ @wrapper = [ s, e ]
75
+ end
76
+ xml.each_child do |node|
77
+ if node.element?
78
+ if ctx.action_exists?((node.namespaces.namespace.href rescue nil), node.name)
79
+ @actions << ctx.compile_action(node)
80
+ else
81
+ a = self.class.new
82
+ a.compile_xml(node, ctx)
83
+ @actions << a
84
+ end
85
+ elsif node.text? || node.cdata?
86
+ @actions << node.content
87
+ end
88
+ end
89
+ end
90
+
91
+ self
92
+ end
93
+
94
+ def run(context, autovivify = false)
95
+ s = ''
96
+ @context.with(context) do |ctx|
97
+ @actions.each do |action|
98
+ if action.is_a?(String)
99
+ s += action
100
+ else
101
+ r = action.run(ctx, autovivify)
102
+ s += r.collect { |v| v.to([FAB_NS, 'string'], ctx).value }.join('')
103
+ end
104
+ end
105
+ end
106
+ s = @wrapper.first + s + @wrapper.last
107
+ return [ context.root.anon_node(s, [ FAB_NS, 'string' ]) ]
108
+ end
109
+ end
34
110
  end
35
111
  end
36
112
 
@@ -14,6 +14,7 @@ module Fabulator
14
14
  contains :mapping, :storage => :hash, :key => :name, :delayable => true
15
15
  contains :reduction, :storage => :hash, :key => :name, :delayable => true
16
16
  contains :consolidation, :storage => :hash, :key => :name, :delayable => true
17
+ contains :template, :storage => :hash, :key => :name, :delayable => true
17
18
  contains :type, :storage => :hash, :key => :name, :delayable => true
18
19
  contains :filter, :storage => :hash, :key => :name, :delayable => true
19
20
  contains :constraint, :storage => :hash, :key => :name, :delayable => true
@@ -73,6 +74,10 @@ module Fabulator
73
74
  fctn = @reductions[nom]
74
75
  fctn_type = :reduction
75
76
  end
77
+ if fctn.nil?
78
+ fctn = @templates[nom]
79
+ fctn_type = :function
80
+ end
76
81
  end
77
82
 
78
83
  if !fctn.nil?
@@ -51,7 +51,7 @@
51
51
  <xsl:param name="form_level" />
52
52
  <xsl:choose>
53
53
  <xsl:when test="f:caption">
54
- <tr><td colspan="2">
54
+ <tr><td colspan="2" class="form-subform">
55
55
  <fieldset>
56
56
  <legend><xsl:apply-templates select="f:caption" /></legend>
57
57
  <xsl:call-template name="form-content">
@@ -71,9 +71,8 @@
71
71
  </xsl:template>
72
72
 
73
73
  <xsl:template match="f:text">
74
- <tr><td class="form-caption" valign="top">
75
- <xsl:apply-templates select="f:caption" />
76
- </td><td class="form-element" valign="top">
74
+ <tr><xsl:call-template name="form-caption" />
75
+ <td class="form-element" valign="top">
77
76
  <xsl:choose>
78
77
  <xsl:when test="@f:rows > 1 or @rows > 1">
79
78
  <textarea>
@@ -114,9 +113,8 @@
114
113
  </xsl:template>
115
114
 
116
115
  <xsl:template match="f:password">
117
- <tr><td class="form-caption" valign="top">
118
- <xsl:apply-templates select="f:caption" />
119
- </td><td class="form-element" valign="top">
116
+ <tr><xsl:call-template name="form-caption" />
117
+ <td class="form-element" valign="top">
120
118
  <input>
121
119
  <xsl:attribute name="type">password</xsl:attribute>
122
120
  <xsl:attribute name="name"><xsl:apply-templates select="." mode="id" /></xsl:attribute>
@@ -125,8 +123,8 @@
125
123
  </xsl:template>
126
124
 
127
125
  <xsl:template match="f:asset">
128
- <div class="form-element">
129
- <xsl:apply-templates select="f:caption" />
126
+ <tr><xsl:call-template name="form-caption" />
127
+ <td class="form-element" valign="top">
130
128
  <span class="form-fluid-asset"></span>
131
129
  <input>
132
130
  <xsl:attribute name="class">form-asset</xsl:attribute>
@@ -136,56 +134,28 @@
136
134
  <xsl:attribute name="accept"><xsl:value-of select="@f:accept" /></xsl:attribute>
137
135
  </xsl:if>
138
136
  </input>
139
- </div>
137
+ </td></tr>
140
138
  </xsl:template>
141
139
 
142
140
  <xsl:template match="f:selection">
143
141
  <!-- for now, just handle simple selections -->
144
142
  <xsl:param name="form_level"/>
145
- <xsl:choose>
146
- <xsl:when test="./f:option//f:form//f:selection">
147
- <span class="form-element">
148
- <xsl:apply-templates select="f:caption"/>
149
- <xsl:apply-templates select="f:help"/>
150
- <xsl:call-template name="field-selection">
151
- <!-- xsl:with-param name="form_id"><xsl:value-of select="$form_id"/></xsl:with-param -->
152
- <xsl:with-param name="form_level"><xsl:value-of select="$form_level"/></xsl:with-param>
153
- </xsl:call-template>
154
- </span>
155
- </xsl:when>
156
- <xsl:when test="./f:option//f:help|./f:option//f:form">
157
- <span class="form-element">
158
- <xsl:apply-templates select="f:caption"/>
159
- <xsl:apply-templates select="f:help"/>
160
- <xsl:call-template name="field-selection">
161
- <!-- xsl:with-param name="form_id"><xsl:value-of select="$form_id"/></xsl:with-param -->
162
- <xsl:with-param name="form_level"><xsl:value-of select="$form_level" /></xsl:with-param>
163
- </xsl:call-template>
164
- </span>
165
- </xsl:when>
166
- <xsl:otherwise>
167
- <span class="form-element">
168
- <!-- label class="form-element-label">
169
- <xsl:attribute name="for">
170
- <xsl:apply-templates select="." mode="id"/>
171
- </xsl:attribute -->
172
- <xsl:apply-templates select="f:caption"/>
173
- <xsl:apply-templates select="f:help"/>
174
- <!-- /label -->
175
- <xsl:call-template name="field-selection">
176
- <xsl:with-param name="form_level"><xsl:value-of select="$form_level" /></xsl:with-param>
177
- </xsl:call-template>
178
- </span>
179
- </xsl:otherwise>
180
- </xsl:choose>
143
+ <tr><xsl:call-template name="form-caption" />
144
+ <td class="form-element" valign="top">
145
+ <xsl:call-template name="field-selection">
146
+ <xsl:with-param name="form_level"><xsl:value-of select="$form_level"/></xsl:with-param>
147
+ </xsl:call-template>
148
+ </td></tr>
181
149
  </xsl:template>
182
150
 
183
151
  <xsl:template match="f:group">
184
- <xsl:param name="form_level" />
185
- <xsl:apply-templates select="f:caption" />
152
+ <xsl:param name="form_level" />
153
+ <tr><xsl:call-template name="form-caption" />
154
+ <td class="form-element" valign="top">
186
155
  <xsl:call-template name="form-content">
187
156
  <xsl:with-param name="form_level"><xsl:value-of select="$form_level" /></xsl:with-param>
188
157
  </xsl:call-template>
158
+ </td></tr>
189
159
  </xsl:template>
190
160
 
191
161
  <xsl:template match="f:submission">
@@ -468,6 +438,13 @@
468
438
  </xsl:choose>
469
439
  </xsl:template>
470
440
 
441
+ <xsl:template name="form-caption">
442
+ <td class="form-caption" valign="top">
443
+ <xsl:apply-templates select="f:caption" />
444
+ </td>
445
+ </xsl:template>
446
+
447
+
471
448
 
472
449
  <xsl:template match="*" mode="id">
473
450
  <xsl:for-each select="ancestor::*[@id != '']">
@@ -232,7 +232,7 @@ end
232
232
  @yydebug = true
233
233
 
234
234
  @last_token = nil
235
-
235
+
236
236
  do_parse
237
237
  end
238
238
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fabulator
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 11
10
- version: 0.0.11
9
+ - 12
10
+ version: 0.0.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Smith
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-11 00:00:00 +00:00
18
+ date: 2010-12-03 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency