inversion 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/Examples.md +134 -0
- data/GettingStarted.md +50 -0
- data/Guide.md +14 -0
- data/{History.rdoc → History.md} +52 -43
- data/{README.rdoc → README.md} +43 -34
- data/Tags.md +555 -0
- data/bin/inversion +4 -8
- data/lib/inversion/cli/api.rb +75 -0
- data/lib/inversion/cli/tagtokens.rb +34 -0
- data/lib/inversion/cli/tree.rb +70 -0
- data/lib/inversion/cli.rb +406 -0
- data/lib/inversion/exceptions.rb +0 -1
- data/lib/inversion/mixins.rb +10 -11
- data/lib/inversion/parser.rb +5 -6
- data/lib/inversion/refinements.rb +18 -0
- data/lib/inversion/renderstate.rb +24 -25
- data/lib/inversion/sinatra.rb +0 -1
- data/lib/inversion/template/attrtag.rb +7 -5
- data/lib/inversion/template/begintag.rb +0 -1
- data/lib/inversion/template/calltag.rb +0 -1
- data/lib/inversion/template/codetag.rb +37 -28
- data/lib/inversion/template/commenttag.rb +0 -1
- data/lib/inversion/template/configtag.rb +3 -4
- data/lib/inversion/template/containertag.rb +1 -2
- data/lib/inversion/template/defaulttag.rb +1 -2
- data/lib/inversion/template/elsetag.rb +0 -1
- data/lib/inversion/template/elsiftag.rb +0 -1
- data/lib/inversion/template/endtag.rb +2 -3
- data/lib/inversion/template/escapetag.rb +1 -2
- data/lib/inversion/template/fortag.rb +2 -3
- data/lib/inversion/template/fragmenttag.rb +1 -2
- data/lib/inversion/template/iftag.rb +3 -1
- data/lib/inversion/template/importtag.rb +2 -3
- data/lib/inversion/template/includetag.rb +1 -2
- data/lib/inversion/template/node.rb +4 -5
- data/lib/inversion/template/pptag.rb +1 -2
- data/lib/inversion/template/publishtag.rb +2 -3
- data/lib/inversion/template/rescuetag.rb +1 -2
- data/lib/inversion/template/subscribetag.rb +3 -4
- data/lib/inversion/template/tag.rb +3 -4
- data/lib/inversion/template/textnode.rb +1 -2
- data/lib/inversion/template/timedeltatag.rb +1 -2
- data/lib/inversion/template/unlesstag.rb +0 -1
- data/lib/inversion/template/uriencodetag.rb +1 -2
- data/lib/inversion/template/yieldtag.rb +0 -1
- data/lib/inversion/template.rb +18 -22
- data/lib/inversion/tilt.rb +1 -2
- data/lib/inversion.rb +2 -3
- data/spec/helpers.rb +19 -13
- data/spec/inversion/mixins_spec.rb +1 -1
- data/spec/inversion/monkeypatches_spec.rb +1 -1
- data/spec/inversion/parser_spec.rb +1 -1
- data/spec/inversion/renderstate_spec.rb +1 -1
- data/spec/inversion/sinatra_spec.rb +1 -1
- data/spec/inversion/template/attrtag_spec.rb +1 -1
- data/spec/inversion/template/begintag_spec.rb +1 -1
- data/spec/inversion/template/calltag_spec.rb +1 -1
- data/spec/inversion/template/codetag_spec.rb +24 -1
- data/spec/inversion/template/commenttag_spec.rb +1 -1
- data/spec/inversion/template/configtag_spec.rb +1 -1
- data/spec/inversion/template/containertag_spec.rb +1 -1
- data/spec/inversion/template/defaulttag_spec.rb +1 -1
- data/spec/inversion/template/elsetag_spec.rb +1 -1
- data/spec/inversion/template/elsiftag_spec.rb +1 -1
- data/spec/inversion/template/endtag_spec.rb +1 -1
- data/spec/inversion/template/escapetag_spec.rb +1 -1
- data/spec/inversion/template/fortag_spec.rb +1 -1
- data/spec/inversion/template/fragmenttag_spec.rb +1 -1
- data/spec/inversion/template/iftag_spec.rb +1 -1
- data/spec/inversion/template/importtag_spec.rb +1 -1
- data/spec/inversion/template/includetag_spec.rb +1 -1
- data/spec/inversion/template/node_spec.rb +1 -1
- data/spec/inversion/template/pptag_spec.rb +1 -1
- data/spec/inversion/template/publishtag_spec.rb +1 -1
- data/spec/inversion/template/rescuetag_spec.rb +1 -1
- data/spec/inversion/template/subscribetag_spec.rb +1 -1
- data/spec/inversion/template/tag_spec.rb +1 -1
- data/spec/inversion/template/textnode_spec.rb +1 -1
- data/spec/inversion/template/timedeltatag_spec.rb +1 -1
- data/spec/inversion/template/unlesstag_spec.rb +1 -1
- data/spec/inversion/template/uriencodetag_spec.rb +1 -1
- data/spec/inversion/template/yieldtag_spec.rb +1 -1
- data/spec/inversion/template_spec.rb +1 -1
- data/spec/inversion/tilt_spec.rb +1 -1
- data/spec/inversion_spec.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +59 -45
- metadata.gz.sig +0 -0
- data/Examples.rdoc +0 -134
- data/GettingStarted.rdoc +0 -44
- data/Guide.rdoc +0 -47
- data/Manifest.txt +0 -86
- data/Rakefile +0 -7
- data/Tags.rdoc +0 -560
- data/lib/inversion/command.rb +0 -278
- data/lib/inversion/monkeypatches.rb +0 -21
@@ -1,5 +1,4 @@
|
|
1
1
|
# -*- ruby -*-
|
2
|
-
# frozen_string_literal: true
|
3
2
|
# vim: set noet nosta sw=4 ts=4 :
|
4
3
|
|
5
4
|
require 'loggability'
|
@@ -21,26 +20,26 @@ class Inversion::RenderState
|
|
21
20
|
class Scope < BasicObject
|
22
21
|
|
23
22
|
### Create a new RenderState::Scope with its initial tag locals set to
|
24
|
-
###
|
23
|
+
### `locals`.
|
25
24
|
def initialize( locals={}, fragments={} )
|
26
25
|
@locals = locals
|
27
26
|
@fragments = fragments
|
28
27
|
end
|
29
28
|
|
30
29
|
|
31
|
-
### Return the tag local with the specified
|
30
|
+
### Return the tag local with the specified `name`.
|
32
31
|
def []( name )
|
33
32
|
return @locals[ name.to_sym ]
|
34
33
|
end
|
35
34
|
|
36
35
|
|
37
|
-
### Set the tag local with the specified
|
36
|
+
### Set the tag local with the specified `name` to `value`.
|
38
37
|
def []=( name, value )
|
39
38
|
@locals[ name.to_sym ] = value
|
40
39
|
end
|
41
40
|
|
42
41
|
|
43
|
-
### Return a copy of the receiving Scope merged with the given
|
42
|
+
### Return a copy of the receiving Scope merged with the given `values`,
|
44
43
|
### which can be either another Scope or a Hash.
|
45
44
|
def +( values )
|
46
45
|
return Scope.new( self.__locals__.merge(values), self.__fragments__ )
|
@@ -75,9 +74,9 @@ class Inversion::RenderState
|
|
75
74
|
|
76
75
|
|
77
76
|
### Create a new RenderState. If the template is being rendered inside another one, the
|
78
|
-
### containing template's RenderState will be passed as the
|
79
|
-
###
|
80
|
-
### Inversion::Template::DEFAULT_CONFIG. The
|
77
|
+
### containing template's RenderState will be passed as the `containerstate`. The
|
78
|
+
### `initial_attributes` will be deep-copied, and the `options` will be merged with
|
79
|
+
### Inversion::Template::DEFAULT_CONFIG. The `block` is stored for use by
|
81
80
|
### template nodes.
|
82
81
|
def initialize( containerstate=nil, initial_attributes={}, options={}, &block )
|
83
82
|
|
@@ -165,7 +164,7 @@ class Inversion::RenderState
|
|
165
164
|
end
|
166
165
|
|
167
166
|
|
168
|
-
### Evaluate the specified
|
167
|
+
### Evaluate the specified `code` in the context of itself and
|
169
168
|
### return the result.
|
170
169
|
def eval( code )
|
171
170
|
# self.log.debug "Evaling: %p" [ code ]
|
@@ -179,7 +178,7 @@ class Inversion::RenderState
|
|
179
178
|
end
|
180
179
|
|
181
180
|
|
182
|
-
### Override the state's attributes with the given
|
181
|
+
### Override the state's attributes with the given `overrides`, call the `block`, then
|
183
182
|
### restore the attributes to their original values.
|
184
183
|
def with_attributes( overrides )
|
185
184
|
raise LocalJumpError, "no block given" unless block_given?
|
@@ -228,8 +227,8 @@ class Inversion::RenderState
|
|
228
227
|
end
|
229
228
|
|
230
229
|
|
231
|
-
### Set the state's error handler to
|
232
|
-
### the previous handler after the block exits.
|
230
|
+
### Set the state's error handler to `handler` for the duration of the block, restoring
|
231
|
+
### the previous handler after the block exits. `Handler` must respond to #call, and will
|
233
232
|
### be called with two arguments: the node that raised the exception, and the exception object
|
234
233
|
### itself.
|
235
234
|
def with_error_handler( handler )
|
@@ -251,7 +250,7 @@ class Inversion::RenderState
|
|
251
250
|
|
252
251
|
|
253
252
|
### Returns a new RenderState containing the attributes and options of the receiver
|
254
|
-
### merged with those of the
|
253
|
+
### merged with those of the `otherstate`.
|
255
254
|
def merge( otherstate )
|
256
255
|
merged = self.dup
|
257
256
|
merged.merge!( otherstate )
|
@@ -259,7 +258,7 @@ class Inversion::RenderState
|
|
259
258
|
end
|
260
259
|
|
261
260
|
|
262
|
-
### Merge the attributes and options of the
|
261
|
+
### Merge the attributes and options of the `otherstate` with those of the receiver,
|
263
262
|
### replacing any with the same keys.
|
264
263
|
def merge!( otherstate )
|
265
264
|
@scopes.push( @scopes.pop + otherstate.scope )
|
@@ -269,7 +268,7 @@ class Inversion::RenderState
|
|
269
268
|
end
|
270
269
|
|
271
270
|
|
272
|
-
### Append operator -- add an node to the final rendered output. If the
|
271
|
+
### Append operator -- add an node to the final rendered output. If the `node` renders
|
273
272
|
### as an object that itself responds to the #render method, #render will be called and
|
274
273
|
### the return value will be appended instead. This will continue until the returned
|
275
274
|
### object either doesn't respond to #render or #renders as itself.
|
@@ -312,7 +311,7 @@ class Inversion::RenderState
|
|
312
311
|
end
|
313
312
|
|
314
313
|
|
315
|
-
### Publish the given
|
314
|
+
### Publish the given `nodes` to all subscribers to the specified `key`.
|
316
315
|
def publish( key, *nodes )
|
317
316
|
key = key.to_sym
|
318
317
|
# self.log.debug "[0x%016x] Publishing %p nodes: %p" % [ self.object_id * 2, key, nodes ]
|
@@ -328,7 +327,7 @@ class Inversion::RenderState
|
|
328
327
|
alias_method :publish_nodes, :publish
|
329
328
|
|
330
329
|
|
331
|
-
### Subscribe the given
|
330
|
+
### Subscribe the given `node` to nodes published with the specified `key`.
|
332
331
|
def subscribe( key, node )
|
333
332
|
key = key.to_sym
|
334
333
|
self.log.debug "Adding subscription to %p nodes for %p" % [ key, node ]
|
@@ -342,8 +341,8 @@ class Inversion::RenderState
|
|
342
341
|
end
|
343
342
|
|
344
343
|
|
345
|
-
### Add one or more rendered
|
346
|
-
### with the specified
|
344
|
+
### Add one or more rendered `nodes` to the state as a reusable fragment associated
|
345
|
+
### with the specified `name`.
|
347
346
|
def add_fragment( name, *nodes )
|
348
347
|
self.log.debug "Adding a %s fragment with %d nodes." % [ name, nodes.size ]
|
349
348
|
nodes.flatten!
|
@@ -361,7 +360,7 @@ class Inversion::RenderState
|
|
361
360
|
end
|
362
361
|
|
363
362
|
|
364
|
-
### Handle an
|
363
|
+
### Handle an `exception` that was raised while appending a node by calling the
|
365
364
|
### #errhandler.
|
366
365
|
def handle_render_error( node, exception )
|
367
366
|
self.log.error "%s while rendering %p: %s" %
|
@@ -386,7 +385,7 @@ class Inversion::RenderState
|
|
386
385
|
end
|
387
386
|
|
388
387
|
|
389
|
-
### Default exception handler: Handle an
|
388
|
+
### Default exception handler: Handle an `exception` while rendering `node` according to the
|
390
389
|
### behavior specified by the `on_render_error` option. Returns the string which should be
|
391
390
|
### appended to the output, if any.
|
392
391
|
def default_error_handler( state, node, exception )
|
@@ -414,7 +413,7 @@ class Inversion::RenderState
|
|
414
413
|
end
|
415
414
|
|
416
415
|
|
417
|
-
### Return
|
416
|
+
### Return `true` if rendered nodes are being saved for output.
|
418
417
|
def rendering_enabled?
|
419
418
|
return @rendering_enabled ? true : false
|
420
419
|
end
|
@@ -461,14 +460,14 @@ class Inversion::RenderState
|
|
461
460
|
protected
|
462
461
|
#########
|
463
462
|
|
464
|
-
### Return the
|
463
|
+
### Return the `node` as a comment if debugging comments are enabled.
|
465
464
|
def make_node_comment( node )
|
466
465
|
comment_body = node.as_comment_body or return ''
|
467
466
|
return self.make_comment( comment_body )
|
468
467
|
end
|
469
468
|
|
470
469
|
|
471
|
-
### Return the specified
|
470
|
+
### Return the specified `content` inside of the configured comment characters.
|
472
471
|
def make_comment( content )
|
473
472
|
return [
|
474
473
|
self.options[:comment_start],
|
@@ -478,7 +477,7 @@ class Inversion::RenderState
|
|
478
477
|
end
|
479
478
|
|
480
479
|
|
481
|
-
### Return the given
|
480
|
+
### Return the given `nodes` as a String in the configured encoding.
|
482
481
|
def stringify_nodes( nodes )
|
483
482
|
# self.log.debug "Rendering nodes: %p" % [ nodes ]
|
484
483
|
strings = nodes.flatten.map( &:to_s )
|
data/lib/inversion/sinatra.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# -*- ruby -*-
|
2
|
-
# frozen_string_literal: true
|
3
2
|
# vim: set noet nosta sw=4 ts=4 :
|
4
3
|
|
5
4
|
require 'inversion/template' unless defined?( Inversion::Template )
|
6
5
|
require 'inversion/template/codetag'
|
7
6
|
|
7
|
+
using Inversion::Refinements
|
8
|
+
|
9
|
+
|
8
10
|
# Inversion attribute tag.
|
9
11
|
#
|
10
12
|
# Attribute tags add an accessor to a template like 'attr_accessor' does for Ruby classes.
|
@@ -49,8 +51,8 @@ class Inversion::Template::AttrTag < Inversion::Template::CodeTag
|
|
49
51
|
|
50
52
|
|
51
53
|
|
52
|
-
### Create a new AttrTag with the given
|
53
|
-
### Ruby identifier. The
|
54
|
+
### Create a new AttrTag with the given `name`, which should be a valid
|
55
|
+
### Ruby identifier. The `linenum` and `colnum` should be the line and column of
|
54
56
|
### the tag in the template source, if available.
|
55
57
|
def initialize( body, linenum=nil, colnum=nil )
|
56
58
|
@name = nil
|
@@ -79,7 +81,7 @@ class Inversion::Template::AttrTag < Inversion::Template::CodeTag
|
|
79
81
|
attr_accessor :methodchain
|
80
82
|
|
81
83
|
|
82
|
-
### Render the tag attributes of the specified
|
84
|
+
### Render the tag attributes of the specified `renderstate` and return them.
|
83
85
|
def render( renderstate )
|
84
86
|
value = self.evaluate( renderstate ) # :FIXME: or return value # nil or false?
|
85
87
|
|
@@ -92,7 +94,7 @@ class Inversion::Template::AttrTag < Inversion::Template::CodeTag
|
|
92
94
|
end
|
93
95
|
|
94
96
|
|
95
|
-
### Evaluate the body of the tag in the context of
|
97
|
+
### Evaluate the body of the tag in the context of `renderstate` and return the results.
|
96
98
|
def evaluate( renderstate )
|
97
99
|
code = [ self.name.to_s, self.methodchain ].join( '' )
|
98
100
|
return renderstate.eval( code )
|
@@ -1,15 +1,19 @@
|
|
1
1
|
# -*- ruby -*-
|
2
|
-
# frozen_string_literal: true
|
3
2
|
# vim: set noet nosta sw=4 ts=4 :
|
4
3
|
|
4
|
+
require 'loggability'
|
5
|
+
|
5
6
|
require 'ripper'
|
6
7
|
require 'inversion/template' unless defined?( Inversion::Template )
|
7
8
|
require 'inversion/template/tag'
|
8
9
|
|
10
|
+
using Inversion::Refinements
|
11
|
+
|
12
|
+
|
9
13
|
# The base class for Inversion tags that parse the body section of the tag using
|
10
14
|
# a Ruby parser.
|
11
15
|
#
|
12
|
-
# It provides a
|
16
|
+
# It provides a `tag_pattern` declarative method that is used to specify a pattern of
|
13
17
|
# tokens to match, and a block for handling tag instances that match the pattern.
|
14
18
|
#
|
15
19
|
# class Inversion::Template::MyTag < Inversion::Template::CodeTag
|
@@ -21,7 +25,7 @@ require 'inversion/template/tag'
|
|
21
25
|
#
|
22
26
|
# end
|
23
27
|
#
|
24
|
-
# The tokens in the
|
28
|
+
# The tokens in the `tag_pattern` are Ruby token names used by the parser. If you're creating
|
25
29
|
# your own tag, you can dump the tokens for a particular snippet using the 'inversion'
|
26
30
|
# command-line tool that comes with the gem:
|
27
31
|
#
|
@@ -36,49 +40,53 @@ class Inversion::Template::CodeTag < Inversion::Template::Tag
|
|
36
40
|
include Inversion::AbstractClass
|
37
41
|
|
38
42
|
|
39
|
-
### A subclass of Ripper::TokenPattern that binds matches to the beginning and
|
40
|
-
### end of the matched string.
|
41
43
|
class TokenPattern < Ripper::TokenPattern
|
44
|
+
extend Loggability
|
45
|
+
|
46
|
+
# Loggability API -- use Inversion's logger
|
47
|
+
log_to :inversion
|
42
48
|
|
43
|
-
# the
|
49
|
+
# Expose the source attribute
|
44
50
|
attr_reader :source
|
45
51
|
|
46
|
-
#########
|
47
|
-
protected
|
48
|
-
#########
|
49
52
|
|
50
|
-
###
|
53
|
+
### Overloaded to generate a bound regex.
|
51
54
|
def compile( pattern )
|
55
|
+
self.log.debug "Compiling token pattern from: %p" % [ pattern ]
|
56
|
+
|
52
57
|
if m = /[^\w\s$()\[\]{}?*+\.]/.match( pattern )
|
53
|
-
raise Ripper::TokenPattern::CompileError,
|
54
|
-
"invalid char in pattern: #{m[0].inspect}"
|
58
|
+
raise Ripper::TokenPattern::CompileError, "invalid char in pattern: #{m[0].inspect}"
|
55
59
|
end
|
56
60
|
|
57
|
-
buf =
|
58
|
-
pattern.scan(
|
61
|
+
buf = +'\\A'
|
62
|
+
pattern.scan(/(?:\w+|\$\(|[()\[\]\{\}?*+\.]+)/) do |tok|
|
59
63
|
case tok
|
60
64
|
when /\w/
|
61
|
-
buf
|
65
|
+
buf.concat( map_token(tok) )
|
62
66
|
when '$('
|
63
|
-
buf
|
67
|
+
buf.concat( '(' )
|
64
68
|
when '('
|
65
|
-
buf
|
69
|
+
buf.concat( '(?:' )
|
66
70
|
when /[?*\[\])\.]/
|
67
|
-
buf
|
71
|
+
buf.concat( tok )
|
68
72
|
else
|
69
|
-
raise
|
73
|
+
raise 'must not happen'
|
70
74
|
end
|
71
75
|
end
|
72
|
-
buf
|
76
|
+
buf.concat( '\z' )
|
77
|
+
|
78
|
+
self.log.debug " resulting token pattern is: %p" % [ buf ]
|
79
|
+
return Regexp.compile( buf )
|
73
80
|
|
74
|
-
Regexp.compile( buf )
|
75
81
|
rescue RegexpError => err
|
76
82
|
raise Ripper::TokenPattern::CompileError, err.message
|
77
83
|
end
|
78
84
|
|
85
|
+
|
79
86
|
end # class TokenPattern
|
80
87
|
|
81
88
|
|
89
|
+
|
82
90
|
#################################################################
|
83
91
|
### C L A S S M E T H O D S
|
84
92
|
#################################################################
|
@@ -91,10 +99,10 @@ class Inversion::Template::CodeTag < Inversion::Template::Tag
|
|
91
99
|
end
|
92
100
|
|
93
101
|
|
94
|
-
### Declare a
|
95
|
-
### be called when a tag matching the pattern is instantiated. The
|
102
|
+
### Declare a `token_pattern` for tag bodies along with a `callback` that will
|
103
|
+
### be called when a tag matching the pattern is instantiated. The `callback` will
|
96
104
|
### be called with the tag instance, and the MatchData object that resulted from
|
97
|
-
### matching the input, and should set up the yielded
|
105
|
+
### matching the input, and should set up the yielded `tag` object appropriately.
|
98
106
|
def self::tag_pattern( token_pattern, &callback ) #:yield: tag, match_data
|
99
107
|
pattern = TokenPattern.compile( token_pattern )
|
100
108
|
@tag_patterns = [] unless defined?( @tag_patterns )
|
@@ -104,7 +112,7 @@ class Inversion::Template::CodeTag < Inversion::Template::Tag
|
|
104
112
|
|
105
113
|
### Declarative that forces a tag to inherit existing patterns from
|
106
114
|
### its parent, rather than replacing them. Afterwards, you can use
|
107
|
-
###
|
115
|
+
### `tag_pattern` regularly, appending to the list.
|
108
116
|
def self::inherit_tag_patterns
|
109
117
|
raise ScriptError, "Patterns already exist for this tag." if defined?( @tag_patterns )
|
110
118
|
@tag_patterns = self.superclass.tag_patterns
|
@@ -115,8 +123,8 @@ class Inversion::Template::CodeTag < Inversion::Template::Tag
|
|
115
123
|
### I N S T A N C E M E T H O D S
|
116
124
|
#################################################################
|
117
125
|
|
118
|
-
### Initialize a new tag that expects Ruby code in its
|
119
|
-
### tag's #parse_pi_body method with the specified
|
126
|
+
### Initialize a new tag that expects Ruby code in its `body`. Calls the
|
127
|
+
### tag's #parse_pi_body method with the specified `body`.
|
120
128
|
def initialize( body, linenum=nil, colnum=nil ) # :notnew:
|
121
129
|
super
|
122
130
|
|
@@ -146,12 +154,13 @@ class Inversion::Template::CodeTag < Inversion::Template::Tag
|
|
146
154
|
protected
|
147
155
|
#########
|
148
156
|
|
149
|
-
### Match the given
|
157
|
+
### Match the given `body` against one of the tag's tag patterns, calling the
|
150
158
|
### block associated with the first one that matches and returning the matching
|
151
159
|
### pattern.
|
152
160
|
def match_tag_pattern( body )
|
153
161
|
|
154
162
|
self.class.tag_patterns.each do |tp, callback|
|
163
|
+
self.log.debug "Testing for a match against %p" % [ tp ]
|
155
164
|
if match = tp.match( body.strip )
|
156
165
|
self.log.debug "Matched tag pattern: %p, match is: %p" % [ tp, match ]
|
157
166
|
callback.call( self, match )
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# -*- ruby -*-
|
2
|
-
# frozen_string_literal: true
|
3
2
|
# vim: set noet nosta sw=4 ts=4 :
|
4
3
|
|
5
4
|
require 'yaml'
|
@@ -32,7 +31,7 @@ class Inversion::Template::ConfigTag < Inversion::Template::Tag
|
|
32
31
|
include Inversion::HashUtilities
|
33
32
|
|
34
33
|
|
35
|
-
### Create a new ConfigTag with the specified
|
34
|
+
### Create a new ConfigTag with the specified `body`.
|
36
35
|
def initialize( body, linenum=nil, colnum=nil )
|
37
36
|
raise Inversion::ParseError, 'Empty config settings' if
|
38
37
|
body.nil? || body.strip.empty?
|
@@ -57,14 +56,14 @@ class Inversion::Template::ConfigTag < Inversion::Template::Tag
|
|
57
56
|
attr_reader :options
|
58
57
|
|
59
58
|
|
60
|
-
### Override the options in the
|
59
|
+
### Override the options in the `parsestate` when the config is appended to
|
61
60
|
### the tree.
|
62
61
|
def before_appending( parsestate )
|
63
62
|
parsestate.options.merge!( self.options )
|
64
63
|
end
|
65
64
|
|
66
65
|
|
67
|
-
### Override the options in the
|
66
|
+
### Override the options in the `renderstate` when the config is rendered.
|
68
67
|
def before_rendering( renderstate )
|
69
68
|
renderstate.options.merge!( self.options )
|
70
69
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# -*- ruby -*-
|
2
|
-
# frozen_string_literal: true
|
3
2
|
# vim: set noet nosta sw=4 ts=4 :
|
4
3
|
|
5
4
|
require 'inversion/template' unless defined?( Inversion::Template )
|
@@ -40,7 +39,7 @@ module Inversion::Template::ContainerTag
|
|
40
39
|
end
|
41
40
|
|
42
41
|
|
43
|
-
### Append the container's subnodes to the
|
42
|
+
### Append the container's subnodes to the `renderstate`.
|
44
43
|
def render_subnodes( renderstate )
|
45
44
|
self.subnodes.each {|node| renderstate << node }
|
46
45
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# -*- ruby -*-
|
2
|
-
# frozen_string_literal: true
|
3
2
|
# vim: set noet nosta sw=4 ts=4 :
|
4
3
|
|
5
4
|
require 'inversion/template' unless defined?( Inversion::Template )
|
@@ -55,7 +54,7 @@ class Inversion::Template::DefaultTag < Inversion::Template::CodeTag
|
|
55
54
|
end
|
56
55
|
|
57
56
|
|
58
|
-
### Create a new DefaultTag with the given
|
57
|
+
### Create a new DefaultTag with the given `name`, which should be a valid
|
59
58
|
### Ruby identifier.
|
60
59
|
def initialize( body, linenum=nil, colnum=nil )
|
61
60
|
@name = nil
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# -*- ruby -*-
|
2
|
-
# frozen_string_literal: true
|
3
2
|
# vim: set noet nosta sw=4 ts=4 :
|
4
3
|
|
5
4
|
require 'inversion/template' unless defined?( Inversion::Template )
|
@@ -8,7 +7,7 @@ require 'inversion/template/tag'
|
|
8
7
|
# Closing tag class
|
9
8
|
class Inversion::Template::EndTag < Inversion::Template::Tag
|
10
9
|
|
11
|
-
### Overridden to provide a default
|
10
|
+
### Overridden to provide a default `body`.
|
12
11
|
def initialize( body='', linenum=nil, colnum=nil )
|
13
12
|
super
|
14
13
|
@opener = nil
|
@@ -23,7 +22,7 @@ class Inversion::Template::EndTag < Inversion::Template::Tag
|
|
23
22
|
attr_reader :opener
|
24
23
|
|
25
24
|
|
26
|
-
### Parser callback -- close the given
|
25
|
+
### Parser callback -- close the given `state`'s currently-open container node.
|
27
26
|
def before_appending( state )
|
28
27
|
@opener = state.pop
|
29
28
|
self.log.debug "End tag for %s at %s" % [ @opener.tagname, @opener.location ]
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# -*- ruby -*-
|
2
|
-
# frozen_string_literal: true
|
3
2
|
# vim: set noet nosta sw=4 ts=4 :
|
4
3
|
|
5
4
|
require 'inversion/template' unless defined?( Inversion::Template )
|
@@ -18,7 +17,7 @@ require 'inversion/template/attrtag'
|
|
18
17
|
class Inversion::Template::EscapeTag < Inversion::Template::AttrTag
|
19
18
|
include Inversion::Escaping
|
20
19
|
|
21
|
-
### Render the method chains against the attributes of the specified
|
20
|
+
### Render the method chains against the attributes of the specified `render_state`
|
22
21
|
### and return them.
|
23
22
|
def render( render_state )
|
24
23
|
return self.escape( super, render_state )
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# -*- ruby -*-
|
2
|
-
# frozen_string_literal: true
|
3
2
|
# vim: set noet nosta sw=4 ts=4 :
|
4
3
|
|
5
4
|
require 'inversion/template' unless defined?( Inversion::Template )
|
@@ -59,7 +58,7 @@ class Inversion::Template::ForTag < Inversion::Template::CodeTag
|
|
59
58
|
|
60
59
|
|
61
60
|
|
62
|
-
### Create a new ForTag with the specified
|
61
|
+
### Create a new ForTag with the specified `body`.
|
63
62
|
def initialize( body, linenum=nil, colnum=nil )
|
64
63
|
@block_args = []
|
65
64
|
@enumerator = nil
|
@@ -80,7 +79,7 @@ class Inversion::Template::ForTag < Inversion::Template::CodeTag
|
|
80
79
|
attr_accessor :enumerator
|
81
80
|
|
82
81
|
|
83
|
-
### Iterate over the enumerator in
|
82
|
+
### Iterate over the enumerator in `state` and render the tag's
|
84
83
|
### contents for each iteration.
|
85
84
|
def render( state )
|
86
85
|
lvalue = state.eval( self.enumerator ) or return nil
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# -*- ruby -*-
|
2
|
-
# frozen_string_literal: true
|
3
2
|
# vim: set noet nosta sw=4 ts=4 :
|
4
3
|
|
5
4
|
require 'inversion/template' unless defined?( Inversion::Template )
|
@@ -21,7 +20,7 @@ class Inversion::Template::FragmentTag < Inversion::Template::Tag
|
|
21
20
|
include Inversion::Template::ContainerTag
|
22
21
|
|
23
22
|
|
24
|
-
### Create a new FragmentTag with the given
|
23
|
+
### Create a new FragmentTag with the given `body`.
|
25
24
|
def initialize( body, line=nil, column=nil )
|
26
25
|
super
|
27
26
|
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# -*- ruby -*-
|
2
|
-
# frozen_string_literal: true
|
3
2
|
# vim: set noet nosta sw=4 ts=4 :
|
4
3
|
|
5
4
|
require 'inversion/mixins'
|
@@ -7,6 +6,9 @@ require 'inversion/template' unless defined?( Inversion::Template )
|
|
7
6
|
require 'inversion/template/attrtag'
|
8
7
|
require 'inversion/template/containertag'
|
9
8
|
|
9
|
+
using Inversion::Refinements
|
10
|
+
|
11
|
+
|
10
12
|
# Inversion 'if' tag.
|
11
13
|
#
|
12
14
|
# This tag causes a section of the template to be rendered only if its methodchain or attribute
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# -*- ruby -*-
|
2
|
-
# frozen_string_literal: true
|
3
2
|
# vim: set noet nosta sw=4 ts=4 :
|
4
3
|
|
5
4
|
require 'inversion/template' unless defined?( Inversion::Template )
|
@@ -17,7 +16,7 @@ require 'inversion/template/tag'
|
|
17
16
|
#
|
18
17
|
class Inversion::Template::ImportTag < Inversion::Template::Tag
|
19
18
|
|
20
|
-
### Create a new ImportTag with the given
|
19
|
+
### Create a new ImportTag with the given `name`, which should be a valid
|
21
20
|
### Ruby identifier.
|
22
21
|
def initialize( body, linenum=nil, colnum=nil )
|
23
22
|
super
|
@@ -33,7 +32,7 @@ class Inversion::Template::ImportTag < Inversion::Template::Tag
|
|
33
32
|
attr_reader :attributes
|
34
33
|
|
35
34
|
|
36
|
-
### Merge the inherited renderstate into the current template's
|
35
|
+
### Merge the inherited renderstate into the current template's `renderstate`.
|
37
36
|
def render( renderstate )
|
38
37
|
if (( cstate = renderstate.containerstate ))
|
39
38
|
# self.log.debug "Importing inherited attributes: %p from %p" %
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# -*- ruby -*-
|
2
|
-
# frozen_string_literal: true
|
3
2
|
# vim: set noet nosta sw=4 ts=4 :
|
4
3
|
|
5
4
|
require 'pathname'
|
@@ -20,7 +19,7 @@ require 'inversion/template/tag'
|
|
20
19
|
#
|
21
20
|
class Inversion::Template::IncludeTag < Inversion::Template::Tag
|
22
21
|
|
23
|
-
### Create a new IncludeTag with the specified
|
22
|
+
### Create a new IncludeTag with the specified `path`.
|
24
23
|
def initialize( path, linenum=nil, colnum=nil )
|
25
24
|
super
|
26
25
|
self.log.debug "Body is: %p" % [ @body ]
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# -*- ruby -*-
|
2
|
-
# frozen_string_literal: true
|
3
2
|
# vim: set noet nosta sw=4 ts=4 :
|
4
3
|
|
5
4
|
require 'loggability'
|
@@ -21,7 +20,7 @@ class Inversion::Template::Node
|
|
21
20
|
log_to :inversion
|
22
21
|
|
23
22
|
|
24
|
-
### Create a new TextNode with the specified
|
23
|
+
### Create a new TextNode with the specified `source`.
|
25
24
|
def initialize( body, linenum=nil, colnum=nil )
|
26
25
|
@body = body
|
27
26
|
@linenum = linenum
|
@@ -40,8 +39,8 @@ class Inversion::Template::Node
|
|
40
39
|
attr_reader :colnum
|
41
40
|
|
42
41
|
|
43
|
-
### Render the node using the given
|
44
|
-
### returns
|
42
|
+
### Render the node using the given `render_state`. By default, rendering a node
|
43
|
+
### returns `nil`.
|
45
44
|
def render( render_state )
|
46
45
|
return nil
|
47
46
|
end
|
@@ -53,7 +52,7 @@ class Inversion::Template::Node
|
|
53
52
|
end
|
54
53
|
|
55
54
|
|
56
|
-
### Returns
|
55
|
+
### Returns `true` if the node introduces a new parsing/rendering scope.
|
57
56
|
def is_container?
|
58
57
|
return false
|
59
58
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# -*- ruby -*-
|
2
|
-
# frozen_string_literal: true
|
3
2
|
# vim: set noet nosta sw=4 ts=4 :
|
4
3
|
|
5
4
|
require 'pp'
|
@@ -17,7 +16,7 @@ require 'inversion/template/calltag'
|
|
17
16
|
class Inversion::Template::PpTag < Inversion::Template::CallTag
|
18
17
|
include Inversion::Escaping
|
19
18
|
|
20
|
-
### Render the method chains against the attributes of the specified
|
19
|
+
### Render the method chains against the attributes of the specified `render_state`
|
21
20
|
### and return them.
|
22
21
|
def render( render_state )
|
23
22
|
raw = super
|