fabulator 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,10 @@
1
+ === 0.0.16 2010-12-28
2
+
3
+ * 3 minor enhancements:
4
+ * Template functions dedent their text.
5
+ * Functions can be immediately followed by predicates
6
+ * Actions defined in a library can have a f:select attribute now
7
+
1
8
  === 0.0.15 2010-12-09
2
9
 
3
10
  * 1 minor enhancement:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.15
1
+ 0.0.16
@@ -173,7 +173,7 @@ Feature: Function calls and lists
173
173
  Scenario: Random numbers
174
174
  Given a context
175
175
  And the prefix f as "http://dh.tamu.edu/ns/fabulator/1.0#"
176
- When I run the expression (f:random(5) < 5)
176
+ When I run the expression (f:random(5) < 6)
177
177
  Then I should get 1 item
178
178
  And item 0 should be [f:true()]
179
179
 
@@ -38,6 +38,9 @@ Feature: Libraries
38
38
  <l:attribute l:name="foo" l:eval="false" />
39
39
  <f:value f:path="/actn4foo" f:select="f:eval($foo)" />
40
40
  </l:action>
41
+ <l:action l:name="test-select" l:has-select="true">
42
+ <f:value f:path="/test-select" f:select="f:eval($select)" />
43
+ </l:action>
41
44
  <l:template l:name="tmpl">
42
45
  Foo
43
46
  </l:template>
@@ -58,12 +61,14 @@ Feature: Libraries
58
61
  >
59
62
  <m:actn3 m:path="/actn3" />
60
63
  <m:actn4 m:foo="bar" />
64
+ <m:test-select f:select="123" />
61
65
  </f:application>
62
66
  """
63
67
  Then the expression (/actn3) should equal [3]
64
68
  And the expression (/actn4foo) should equal ['bar']
69
+ And the expression (/test-select) should equal [123]
65
70
  And the expression (m:fctn(3,2)) should equal [1]
66
71
  And the expression (m:fctn2(2,3)) should equal [1]
67
- And the expression (f:normalize-space(m:tmpl())) should equal ['Foo']
68
- And the expression (f:normalize-space(m:tmpl2('Foo'))) should equal ['Foo']
69
- And the expression (f:normalize-space(m:tmpl3('Foo'))) should equal ['<p> Foo </p>']
72
+ And the expression (m:tmpl()) should equal ['Foo']
73
+ And the expression (m:tmpl2('Foo')) should equal ['Foo']
74
+ And the expression (f:normalize-space(m:tmpl3('Foo'))) should equal ['<p>Foo</p>']
@@ -89,3 +89,12 @@ Feature: Path expressions
89
89
  And item 1 should be ['ccc']
90
90
  And item 2 should be ['dd']
91
91
 
92
+ @array
93
+ Scenario: Predicates after function calls
94
+ Given a context
95
+ And the prefix f as "http://dh.tamu.edu/ns/fabulator/1.0#"
96
+ When I run the expression (f:split('The brown faux fox fur', ' ')[f:starts-with?(., 'f')])
97
+ Then I should get 3 items
98
+ And item 0 should be ['faux']
99
+ And item 1 should be ['fox']
100
+ And item 2 should be ['fur']
@@ -226,11 +226,14 @@ Feature: Simple state machines
226
226
  </f:choose>
227
227
  </f:variable>
228
228
  <f:value f:path="/new-post/filter" f:select="$filter" />
229
+ <f:variable f:name="fillter" f:select="$filter" />
230
+ <f:value f:path="/new-post/fillter" f:select="$fillter" />
229
231
  </f:application>
230
232
  """
231
233
  Then the expression (/foo) should equal [3]
232
234
  Then the expression (/bar) should equal [3]
233
235
  Then the expression (/new-post/filter) should equal ['Markdown']
236
+ Then the expression (/new-post/fillter) should equal ['Markdown']
234
237
 
235
238
  @var
236
239
  Scenario: simple machine with a <variable /> and <value />
@@ -1396,7 +1396,7 @@ module_eval(<<'.,.,', 'xsm_expression_parser.racc', 115)
1396
1396
 
1397
1397
  module_eval(<<'.,.,', 'xsm_expression_parser.racc', 116)
1398
1398
  def _reduce_63(val, _values, result)
1399
- result = Fabulator::Expr::PathExpr.new(val[0], val[1], val[2])
1399
+ result = ((val[1].nil? || val[1].empty?) && (val[2].nil? || val[2].empty?)) ? val[0] : Fabulator::Expr::PathExpr.new(val[0], val[1], val[2])
1400
1400
  result
1401
1401
  end
1402
1402
  .,.,
@@ -3,7 +3,7 @@ module Fabulator
3
3
  class PathExpr
4
4
  def initialize(pe, predicates, segment)
5
5
  @primary_expr = pe
6
- @predicates = predicates
6
+ @predicates = Fabulator::Expr::Predicates.new(nil, predicates)
7
7
  @segment = (segment.is_a?(Array) ? segment : [ segment ]) - [nil]
8
8
  end
9
9
 
@@ -24,15 +24,8 @@ module Fabulator
24
24
 
25
25
  possible.each do |e|
26
26
  next if e.nil?
27
- not_pass = false
28
- @predicates.each do |p|
29
- if !p.test(context.with_root(e))
30
- not_pass = true
31
- break
32
- end
33
- end
34
- next if not_pass
35
- pos = [ e ]
27
+ pos = @predicates.run(context.with_root(e), autovivify)
28
+ next if pos.empty?
36
29
  @segment.each do |s|
37
30
  pos = pos.collect{ |p|
38
31
  s.run(context.with_root(p), autovivify)
@@ -10,7 +10,7 @@ module Fabulator
10
10
  # we want to run through all of the predicates and return true if
11
11
  # they all return true
12
12
  result = [ ]
13
- possible = @axis.run(context, autovivify)
13
+ possible = @axis.nil? ? [ context.root ] : @axis.run(context, autovivify)
14
14
  return possible if @predicates.nil? || @predicates.empty?
15
15
  @predicates.each do |p|
16
16
  n_p = [ ]
@@ -24,6 +24,10 @@ module Fabulator
24
24
  end
25
25
  ret
26
26
  end
27
+
28
+ def has_select?
29
+ @has_select
30
+ end
27
31
  end
28
32
 
29
33
  class ActionRef
@@ -54,7 +58,9 @@ module Fabulator
54
58
  ctx.set_var('actions', ctx.root.anon_node( @actions, [ FAB_NS, 'expression' ]))
55
59
  end
56
60
  if action.has_select?
57
- ctx.set_var('select', ctx.root.anon_node( @select, [ FAB_NS, 'expression' ]))
61
+ v = @context.attribute(Fabulator::FAB_NS, 'select', { :eval => true })
62
+
63
+ ctx.set_var('select', ctx.root.anon_node( v, [ FAB_NS, 'expression' ]))
58
64
  end
59
65
  ret = action.run(ctx)
60
66
  end
@@ -103,6 +103,14 @@ module Fabulator
103
103
  end
104
104
  end
105
105
  end
106
+ s.gsub!(/^\s+/, '')
107
+ s.gsub!(/\s+$/, '')
108
+ # we want to see if we need to remove a whitespace prefix
109
+ indent = s.
110
+ split(/[\x0a\0x0d]/).
111
+ map{|l| (v=l[/^([\s]+)/].to_s.length; v==0)? nil : v }.
112
+ compact.min
113
+ s.gsub!(/^#{' '*indent.to_i}/, '')
106
114
  s = @wrapper.first + s + @wrapper.last
107
115
  return [ context.root.anon_node(s, [ FAB_NS, 'string' ]) ]
108
116
  end
@@ -114,7 +114,7 @@ rule
114
114
  | union_expr_x PIPE path_expr { result = val[0] + [ val[2] ] }
115
115
 
116
116
  path_expr: location_path { result = Fabulator::Expr::PathExpr.new(nil, [], val[0]) } #result = Fabulator::Expr::PathExpr.new(nil, [], val[0]) }
117
- | primary_expr predicates segment { result = Fabulator::Expr::PathExpr.new(val[0], val[1], val[2]) }
117
+ | primary_expr predicates segment { result = ((val[1].nil? || val[1].empty?) && (val[2].nil? || val[2].empty?)) ? val[0] : Fabulator::Expr::PathExpr.new(val[0], val[1], val[2]) }
118
118
 
119
119
  segment:
120
120
  | SLASH relative_location_path { result = val[1] }
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: 1
4
+ hash: 63
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 15
10
- version: 0.0.15
9
+ - 16
10
+ version: 0.0.16
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-12-09 00:00:00 +00:00
18
+ date: 2010-12-28 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency