inversion 0.12.1 → 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3abf2d4030db2c2d5c772d68dcd717ede7fa6855
4
- data.tar.gz: ae7a4178935ef854e28ca3d35cb67c2e08be061e
3
+ metadata.gz: ee01a480a807741a298355b17197ed2f27e95331
4
+ data.tar.gz: 4a7cb73e31268fa057178f347ace82ac1424d185
5
5
  SHA512:
6
- metadata.gz: 0c859f59041d2d7f3226dcb32eb3efdbcbbc13fe88437345aa51379698dd26448b6f0e1e9d83ad42dd8d6a253f5f54499ab7f48a08dfc6ae421a71cfd12acb2e
7
- data.tar.gz: 7412d7af509f67477c45858427e5e152aefc095884c4e3044914407584763535a04f89b211b1573cd7a79cf88d871a4d7ea002b5405cc3d4c79b21066b9e63a6
6
+ metadata.gz: 17b2389918625d5ca52bdc85266d2f5b2e5dba57eb1f13ed89d3645c614095ed1ffb329174cfd8ed8ea909248ca479fa8f6f4e48d0fcc85a1f62913205096ae0
7
+ data.tar.gz: fd494f03728ff030c95589eb40fdc67ce7332d14dd9ee176343e343c7b1925e9f91d304eeeccb7ab74b550c7f00c54167b2b35cf47f6361530a470a3fb243113
checksums.yaml.gz.sig CHANGED
@@ -1 +1,2 @@
1
- SMrr68�O���\Pu���8P��e*nj(����F��&���Iƭ5q`fX��,JG{Տ�c�5*4�d�a�S�8):c�I-�~4�mU#��x!��΅����.��<E�8E1�W�� J~��BL���mov UgqB�!����*��T�rV�:����[�t��IE8S��!�ÿ?un��1��Tz/����rmdT,�@ٓ� ��̍��qDW"�gZ4a��̈/��b�M�A�; �!�m�Yj
1
+ ���`}����l�?ڨ5��\h��\��N����dj뮷4�@Q#�z��}c���ygfU��8e+�Fnd��.Ҵ����v�<�Q��DHYN%� f�=}����i탞��/���8�������t
2
+ ;&u�ШrIE�|�N��L����=�>}u���:��SCBW�J�t�؏x�b �A%���uu��v3a�\��.軧�B#�蚶�!�໯�ϻۤ��Ѩ��)A,؅��CnՉ2Z(�^V�
data.tar.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,3 +1,9 @@
1
+ == v0.12.2 [2013-06-19] Michael Granger <ged@FaerieMUD.org>
2
+
3
+ - Fix propagation of config tags into subtemplates (fixes #1)
4
+ - Use replacement in transcoding instead of raising encoding errors
5
+
6
+
1
7
  == v0.12.1 [2013-03-05] Michael Granger <ged@FaerieMUD.org>
2
8
 
3
9
  A bunch of optimization and inspect-encoding fixes.
data/Manifest.txt CHANGED
@@ -41,6 +41,7 @@ lib/inversion/template/uriencodetag.rb
41
41
  lib/inversion/template/yieldtag.rb
42
42
  lib/inversion/tilt.rb
43
43
  spec/data/sinatra/hello.inversion
44
+ spec/data/unknown-tag.tmpl
44
45
  spec/inversion/mixins_spec.rb
45
46
  spec/inversion/monkeypatches_spec.rb
46
47
  spec/inversion/parser_spec.rb
data/lib/inversion.rb CHANGED
@@ -26,10 +26,10 @@ module Inversion
26
26
  warn ">>> Inversion requires Ruby 1.9.2 or later. <<<" if RUBY_VERSION < '1.9.2'
27
27
 
28
28
  # Library version constant
29
- VERSION = '0.12.1'
29
+ VERSION = '0.12.2'
30
30
 
31
31
  # Version-control revision constant
32
- REVISION = %q$Revision: 4bc01301cf22 $
32
+ REVISION = %q$Revision: 0444a00c5e64 $
33
33
 
34
34
 
35
35
  ### Get the Inversion version.
@@ -4,7 +4,7 @@
4
4
  require 'inversion' unless defined?( Inversion )
5
5
  require 'ripper'
6
6
 
7
- # Monkeypatch mixin to expose the 'tokens' instance variable of
7
+ # Monkeypatch mixin to expose the 'tokens' instance variable of
8
8
  # Ripper::TokenPattern::MatchData. Included in Ripper::TokenPattern::MatchData.
9
9
  module Inversion::RipperAdditions
10
10
 
@@ -97,7 +97,7 @@ class Inversion::Parser
97
97
  end
98
98
 
99
99
  # self.log.debug " found a tag at offset: %d (%p) (line %d, col %d)" %
100
- # [ start_pos, abbrevstring(match[0]), linenum, colnum ]
100
+ # [ start_pos, abbrevstring(match[0]), linenum, colnum ]
101
101
 
102
102
  # If there were characters between the end of the last match and
103
103
  # the beginning of the tag, create a text node with them
@@ -108,7 +108,7 @@ class Inversion::Parser
108
108
  end
109
109
 
110
110
  # self.log.debug " creating tag with tagname: %p, body: %p" %
111
- # [ match[:tagname], match[:body] ]
111
+ # [ match[:tagname], match[:body] ]
112
112
 
113
113
  tag = Inversion::Template::Tag.create( match[:tagname], match[:body], linenum, colnum )
114
114
  if tag.nil?
@@ -167,7 +167,7 @@ class Inversion::Parser
167
167
  class State
168
168
  extend Loggability
169
169
 
170
- #
170
+ # Write logs to the Inversion logger
171
171
  log_to :inversion
172
172
 
173
173
  ### Create a new State object
@@ -67,7 +67,7 @@ class Inversion::RenderState
67
67
 
68
68
 
69
69
  ### Create a new RenderState. If the template is being rendered inside another one, the
70
- ### containing template's RenderState will be passed as the +containerstate+. The
70
+ ### containing template's RenderState will be passed as the +containerstate+. The
71
71
  ### +initial_attributes+ will be deep-copied, and the +options+ will be merged with
72
72
  ### Inversion::Template::DEFAULT_CONFIG. The +block+ is stored for use by
73
73
  ### template nodes.
@@ -257,8 +257,8 @@ class Inversion::RenderState
257
257
  end
258
258
 
259
259
 
260
- ### Append operator -- add an node to the final rendered output. If the +node+ renders
261
- ### as an object that itself responds to the #render method, #render will be called and
260
+ ### Append operator -- add an node to the final rendered output. If the +node+ renders
261
+ ### as an object that itself responds to the #render method, #render will be called and
262
262
  ### the return value will be appended instead. This will continue until the returned
263
263
  ### object either doesn't respond to #render or #renders as itself.
264
264
  def <<( node )
@@ -300,7 +300,7 @@ class Inversion::RenderState
300
300
 
301
301
  if enc = self.options[ :encoding ]
302
302
  self.log.debug "Encoding rendered template parts to %s" % [ enc ]
303
- strings.map! {|str| str.encode(enc) }
303
+ strings.map! {|str| str.encode(enc, invalid: :replace, undef: :replace) }
304
304
  end
305
305
 
306
306
  return strings.join
@@ -315,7 +315,7 @@ class Inversion::RenderState
315
315
  self.containerstate.publish( key, *nodes ) if self.containerstate
316
316
  self.subscriptions[ key ].each do |subscriber|
317
317
  # self.log.debug " sending %d nodes to subscriber: %p (a %p)" %
318
- # [ nodes.length, subscriber, subscriber.class ]
318
+ # [ nodes.length, subscriber, subscriber.class ]
319
319
  subscriber.publish( *nodes )
320
320
  end
321
321
  self.published_nodes[ key ].concat( nodes )
@@ -362,7 +362,7 @@ class Inversion::RenderState
362
362
  end
363
363
 
364
364
 
365
- ### Default exception handler: Handle an +exception+ while rendering +node+ according to the
365
+ ### Default exception handler: Handle an +exception+ while rendering +node+ according to the
366
366
  ### behavior specified by the `on_render_error` option. Returns the string which should be
367
367
  ### appended to the output, if any.
368
368
  def default_error_handler( state, node, exception )
@@ -50,16 +50,18 @@ class Inversion::Template
50
50
 
51
51
  ### Default config values
52
52
  DEFAULT_CONFIG = {
53
+ # Loading/parsing options
53
54
  :ignore_unknown_tags => true,
54
55
  :template_paths => [],
56
+ :stat_delay => 0,
55
57
 
58
+ # Rendering options
56
59
  :on_render_error => :comment,
57
60
  :debugging_comments => false,
58
61
  :comment_start => '<!-- ',
59
62
  :comment_end => ' -->',
60
63
  :escape_format => :html,
61
64
  :strip_tag_lines => true,
62
- :stat_delay => 0
63
65
  }.freeze
64
66
 
65
67
 
@@ -211,7 +213,10 @@ class Inversion::Template
211
213
  ### template is being rendered inside another template).
212
214
  def render( parentstate=nil, &block )
213
215
  self.log.info "rendering template 0x%08x" % [ self.object_id/2 ]
214
- state = Inversion::RenderState.new( parentstate, self.attributes, self.options, &block )
216
+ opts = self.options
217
+ opts.merge!( parentstate.options ) if parentstate
218
+
219
+ state = Inversion::RenderState.new( parentstate, self.attributes, opts, &block )
215
220
 
216
221
  # self.log.debug " rendering node tree: %p" % [ @node_tree ]
217
222
  self.walk_tree {|node| state << node }
@@ -11,12 +11,12 @@ require 'inversion/template/tag'
11
11
  # tokens to match, and a block for handling tag instances that match the pattern.
12
12
  #
13
13
  # class Inversion::Template::MyTag < Inversion::Template::CodeTag
14
- #
14
+ #
15
15
  # # Match a tag that looks like: <?my "string of stuff" ?>
16
16
  # tag_pattern 'tstring_beg $(tstring_content) tstring_end' do |tag, match|
17
17
  # tag.string = match.string( 1 )
18
18
  # end
19
- #
19
+ #
20
20
  # end
21
21
  #
22
22
  # The tokens in the +tag_pattern+ are Ruby token names used by the parser. If you're creating
@@ -90,8 +90,10 @@ class Inversion::Template::CodeTag < Inversion::Template::Tag
90
90
 
91
91
 
92
92
  ### Declare a +token_pattern+ for tag bodies along with a +callback+ that will
93
- ### be called when a tag matching the pattern is instantiated.
94
- def self::tag_pattern( token_pattern, &callback ) #:yield:
93
+ ### be called when a tag matching the pattern is instantiated. The +callback+ will
94
+ ### be called with the tag instance, and the MatchData object that resulted from
95
+ ### matching the input, and should set up the yielded +tag+ object appropriately.
96
+ def self::tag_pattern( token_pattern, &callback ) #:yield: tag, match_data
95
97
  pattern = TokenPattern.compile( token_pattern )
96
98
  @tag_patterns = [] unless defined?( @tag_patterns )
97
99
  @tag_patterns << [ pattern, callback ]
@@ -30,7 +30,7 @@ class Inversion::Template::CommentTag < Inversion::Template::Tag
30
30
  end
31
31
 
32
32
 
33
- ### Render the tag as the body of a comment, suitable for template
33
+ ### Render the tag as the body of a comment, suitable for template
34
34
  ### debugging.
35
35
  def as_comment_body
36
36
  firstnode, lastnode = self.subnodes.first, self.subnodes.last
@@ -33,7 +33,7 @@ module Inversion::Template::ContainerTag
33
33
  alias_method :container?, :is_container?
34
34
 
35
35
 
36
- ### Default render method for containertags; rendering each of its subnodes and
36
+ ### Default render method for containertags; rendering each of its subnodes and
37
37
  ### don't render anything for the container itself.
38
38
  def render( renderstate )
39
39
  self.render_subnodes( renderstate )
@@ -6,7 +6,7 @@ require 'inversion/template/tag'
6
6
 
7
7
  # Inversion 'else' tag.
8
8
  #
9
- # This tag adds a logical switch to an IfTag. If the IfTag's condition was false,
9
+ # This tag adds a logical switch to an IfTag. If the IfTag's condition was false,
10
10
  # start rendering.
11
11
  #
12
12
  # == Syntax
@@ -38,7 +38,7 @@ class Inversion::Template::ElseTag < Inversion::Template::Tag
38
38
  case node
39
39
 
40
40
  # If there was a previous 'if' or 'unless', the else belongs to it. Also
41
- # allow it to be appended to a 'comment' section so you can comment out an
41
+ # allow it to be appended to a 'comment' section so you can comment out an
42
42
  # else clause
43
43
  when Inversion::Template::IfTag,
44
44
  Inversion::Template::UnlessTag,
@@ -9,7 +9,7 @@ require 'inversion/template/iftag' unless
9
9
 
10
10
  # Inversion 'elsif' tag.
11
11
  #
12
- # This tag adds a conditional logical switch to an IfTag. If the IfTag's condition was false,
12
+ # This tag adds a conditional logical switch to an IfTag. If the IfTag's condition was false,
13
13
  # but the attribute or methodchain of the elsif is true, start rendering.
14
14
  #
15
15
  # == Syntax
@@ -95,7 +95,7 @@ class Inversion::Template::ForTag < Inversion::Template::CodeTag
95
95
  # the arguments names and values
96
96
  overrides = Hash[ self.block_args.zip(args) ]
97
97
 
98
- # Overlay the block args from the 'for' over the template attributes and render
98
+ # Overlay the block args from the 'for' over the template attributes and render
99
99
  # each subnode
100
100
  state.with_attributes( overrides ) do
101
101
  super
@@ -9,7 +9,7 @@ require 'inversion/template' unless defined?( Inversion::Template )
9
9
  # Inversion template node base class. Template text is parsed by the
10
10
  # Inversion::Parser into nodes, and appended to a tree
11
11
  # that is later walked when the template is rendered.
12
- #
12
+ #
13
13
  # This class is abstract; it just defines the API that other nodes
14
14
  # are expected to implement.
15
15
  class Inversion::Template::Node
@@ -11,7 +11,7 @@ require 'inversion/mixins'
11
11
 
12
12
  # Inversion template tag node base class. Represents a directive in a template
13
13
  # that defines behavior and/or state.
14
- #
14
+ #
15
15
  # This class supports the RubyGems plugin API: to provide one or more Inversion tags
16
16
  # in a gem of your own, put them into a directory named 'inversion/template' and
17
17
  # name the files <tt><tagname>tag.rb</tt> and the classes <tagname.capitalize>Tag.
@@ -16,7 +16,7 @@ require 'inversion/template/attrtag'
16
16
  class Inversion::Template::UriencodeTag < Inversion::Template::AttrTag
17
17
 
18
18
  # Unreserved characters from section 2.3 of RFC 3986
19
- # ALPHA / DIGIT / "-" / "." / "_" / "~"
19
+ # ALPHA / DIGIT / "-" / "." / "_" / "~"
20
20
  DEFAULT_ENCODED_CHARACTERS = /[^\w\-\.~]/
21
21
 
22
22
  ### Render the method chains against the attributes of the specified +render_state+
@@ -26,7 +26,7 @@ class Inversion::Template::YieldTag < Inversion::Template::Tag
26
26
  def before_rendering( renderstate )
27
27
  if renderstate.block
28
28
  self.log.debug "Yielding to %p before rendering." % [ renderstate.block ]
29
- renderstate.tag_data[ self ] = renderstate.block.call( renderstate )
29
+ renderstate.tag_data[ self ] = renderstate.block.call( renderstate )
30
30
  self.log.debug " render block returned: %p" % [ @block_value ]
31
31
  end
32
32
  end
@@ -0,0 +1,5 @@
1
+ <!-- $Id$ -->
2
+ <?unknown This is an unknown tag type ?>
3
+ <?comment Some stuff. ?>
4
+ Stuff
5
+ <?end comment ?>
@@ -158,7 +158,7 @@ describe Inversion::RenderState do
158
158
  describe "context-aware tag state" do
159
159
 
160
160
  before( :each ) do
161
- @renderstate = Inversion::RenderState.new
161
+ @renderstate = Inversion::RenderState.new
162
162
  end
163
163
 
164
164
  it "provides a mechanism for storing tag state for the current render" do
@@ -412,6 +412,23 @@ describe Inversion::RenderState do
412
412
  state.to_s.encoding.should be( Encoding::UTF_8 )
413
413
  end
414
414
 
415
+ it "replaces characters with undefined conversions instead of raising an encoding error" do
416
+ bogus = "this character doesn't translate: \xc3 "
417
+ bogus.force_encoding( 'binary' )
418
+
419
+ attributes = {
420
+ bogus: bogus,
421
+ okay: "this stuff will transcode fine"
422
+ }
423
+
424
+ state = Inversion::RenderState.new( attributes, encoding: 'utf-8' )
425
+
426
+ state << Inversion::Template::AttrTag.new( 'okay' )
427
+ state << Inversion::Template::AttrTag.new( 'bogus' )
428
+
429
+ state.to_s.encoding.should be( Encoding::UTF_8 )
430
+ end
431
+
415
432
  end
416
433
 
417
434
  end
@@ -105,7 +105,7 @@ describe Inversion::Template::BeginTag do
105
105
 
106
106
  context "with a single rescue clause with an exception type" do
107
107
  before( :each ) do
108
-
108
+
109
109
  @tag = Inversion::Template::BeginTag.new( ' ' )
110
110
 
111
111
  @attrtag = Inversion::Template::AttrTag.new( 'foo.baz' )
@@ -18,9 +18,11 @@ describe Inversion::Template::ConfigTag do
18
18
 
19
19
  before( :all ) do
20
20
  setup_logging( :fatal )
21
+ Inversion::Template.template_paths << 'spec/data'
21
22
  end
22
23
 
23
24
  after( :all ) do
25
+ Inversion::Template.template_paths.delete( 'spec/data' )
24
26
  reset_logging()
25
27
  end
26
28
 
@@ -46,24 +48,26 @@ describe Inversion::Template::ConfigTag do
46
48
  comment_end: "*/"
47
49
  YAML
48
50
  tag = Inversion::Template::ConfigTag.new( yaml )
49
- tag.options.should == {
51
+
52
+ expect( tag.options ).to eq({
50
53
  :on_render_error => 'propagate',
51
54
  :debugging_comments => true,
52
55
  :comment_start => '/*',
53
56
  :comment_end => '*/'
54
- }
57
+ })
55
58
  end
56
59
 
57
60
  # <?config { comment_start: "/*", comment_end: "*/" } ?>
58
61
  it "can contain multiple configuration settings using an inline hash" do
59
62
  tag = Inversion::Template::ConfigTag.new( '{ comment_start: "/*", comment_end: "*/" }' )
60
- tag.options.should == { :comment_start => '/*', :comment_end => '*/' }
63
+ expect( tag.options ).to eq({ :comment_start => '/*', :comment_end => '*/' })
61
64
  end
62
65
 
63
66
  it "renders invisibly" do
64
67
  tag = Inversion::Template::ConfigTag.new( 'comment_start: /*' )
65
68
  state = Inversion::RenderState.new
66
- tag.render( state ).should == nil
69
+
70
+ expect( tag.render(state) ).to be nil
67
71
  end
68
72
 
69
73
  it "raises an error on an empty body" do
@@ -94,7 +98,29 @@ describe Inversion::Template::ConfigTag do
94
98
  something else
95
99
  TEMPLATE
96
100
  tmpl = Inversion::Template.new( source )
97
- tmpl.render.should include( "<!-- If: { template.foo } -->" )
101
+
102
+ expect( tmpl.render ).to include( "<!-- If: { template.foo } -->" )
103
+ end
104
+
105
+ it "propagates options to subtemplates during parsing" do
106
+ source = <<-TEMPLATE
107
+ <?config ignore_unknown_tags: false ?>
108
+ <?include unknown-tag.tmpl ?>
109
+ TEMPLATE
110
+ expect {
111
+ Inversion::Template.new( source )
112
+ }.to raise_error( Inversion::ParseError, /unknown tag "unknown"/i )
113
+ end
114
+
115
+ it "propagates options to subtemplates during rendering" do
116
+ source = <<-TEMPLATE
117
+ <?config debugging_comments: true ?>
118
+ <?attr subtemplate ?>
119
+ TEMPLATE
120
+ tmpl = Inversion::Template.new( source )
121
+ tmpl.subtemplate = Inversion::Template.load( 'unknown-tag.tmpl' )
122
+
123
+ expect( tmpl.render ).to match( /commented out 1 nodes on line 3: some stuff/i )
98
124
  end
99
125
 
100
126
  end
@@ -76,7 +76,7 @@ describe Inversion::Template::TextNode do
76
76
  expected_content = LONGER_CONTENT[0,40].dump
77
77
  expected_content[-1,0] = '...'
78
78
 
79
- @node.as_comment_body.should ==
79
+ @node.as_comment_body.should ==
80
80
  %Q{Text (488 bytes): "\\t\\t<p>Lorem ipsum dolor sit amet, consect..."}
81
81
  end
82
82
 
data/spec/lib/helpers.rb CHANGED
@@ -26,6 +26,7 @@ end
26
26
 
27
27
  require 'rspec'
28
28
  require 'loggability'
29
+ require 'loggability/spechelpers'
29
30
 
30
31
  require 'inversion'
31
32
  require 'spec/lib/constants'
@@ -45,31 +46,6 @@ module Inversion::SpecHelpers
45
46
  end
46
47
 
47
48
 
48
- ### Reset the logging subsystem to its default state.
49
- def reset_logging
50
- Loggability.formatter = nil
51
- Loggability.output_to( $stderr )
52
- Loggability.level = :fatal
53
- end
54
-
55
-
56
- ### Alter the output of the default log formatter to be pretty in SpecMate output
57
- def setup_logging( level=:fatal )
58
-
59
- # Only do this when executing from a spec in TextMate
60
- if ENV['HTML_LOGGING'] || (ENV['TM_FILENAME'] && ENV['TM_FILENAME'] =~ /_spec\.rb/)
61
- $stderr.puts "Setting up HTML logs."
62
- logarray = []
63
- Thread.current['logger-output'] = logarray
64
- Loggability.output_to( logarray )
65
- Loggability.format_as( :html )
66
- Loggability.level = :debug
67
- else
68
- Loggability.level = level
69
- end
70
- end
71
-
72
-
73
49
  ### Create a string containing an XML Processing Instruction with the given +name+
74
50
  ### and +data+.
75
51
  def create_pi( name, data )
@@ -83,9 +59,13 @@ end
83
59
  ### Mock with RSpec
84
60
  RSpec.configure do |c|
85
61
  include Inversion::TestConstants
62
+ include Loggability::SpecHelpers
86
63
 
87
64
  c.mock_with :rspec
65
+
88
66
  c.include( Inversion::SpecHelpers )
67
+ c.include( Loggability::SpecHelpers )
68
+
89
69
  c.filter_run_excluding( :ruby_1_9_only => true ) if
90
70
  Inversion::SpecHelpers.vvec( RUBY_VERSION ) < Inversion::SpecHelpers.vvec('1.9.0')
91
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inversion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Granger
@@ -31,7 +31,7 @@ cert_chain:
31
31
  6mKCwjpegytE0oifXfF8k75A9105cBnNiMZOe1tXiqYc/exCgWvbggurzDOcRkZu
32
32
  /YSusaiDXHKU2O3Akc3htA==
33
33
  -----END CERTIFICATE-----
34
- date: 2013-03-20 00:00:00.000000000 Z
34
+ date: 2013-06-19 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: loggability
@@ -302,6 +302,7 @@ files:
302
302
  - lib/inversion/template/yieldtag.rb
303
303
  - lib/inversion/tilt.rb
304
304
  - spec/data/sinatra/hello.inversion
305
+ - spec/data/unknown-tag.tmpl
305
306
  - spec/inversion/mixins_spec.rb
306
307
  - spec/inversion/monkeypatches_spec.rb
307
308
  - spec/inversion/parser_spec.rb
metadata.gz.sig CHANGED
Binary file