inversion 1.3.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/Examples.md +134 -0
  4. data/GettingStarted.md +50 -0
  5. data/Guide.md +14 -0
  6. data/{History.rdoc → History.md} +59 -43
  7. data/{README.rdoc → README.md} +43 -34
  8. data/Tags.md +555 -0
  9. data/bin/inversion +4 -8
  10. data/lib/inversion/cli/api.rb +75 -0
  11. data/lib/inversion/cli/tagtokens.rb +34 -0
  12. data/lib/inversion/cli/tree.rb +70 -0
  13. data/lib/inversion/cli.rb +406 -0
  14. data/lib/inversion/exceptions.rb +0 -1
  15. data/lib/inversion/mixins.rb +10 -11
  16. data/lib/inversion/parser.rb +5 -6
  17. data/lib/inversion/refinements.rb +18 -0
  18. data/lib/inversion/renderstate.rb +24 -25
  19. data/lib/inversion/sinatra.rb +0 -1
  20. data/lib/inversion/template/attrtag.rb +7 -5
  21. data/lib/inversion/template/begintag.rb +0 -1
  22. data/lib/inversion/template/calltag.rb +0 -1
  23. data/lib/inversion/template/codetag.rb +37 -28
  24. data/lib/inversion/template/commenttag.rb +0 -1
  25. data/lib/inversion/template/configtag.rb +3 -4
  26. data/lib/inversion/template/containertag.rb +1 -2
  27. data/lib/inversion/template/defaulttag.rb +1 -2
  28. data/lib/inversion/template/elsetag.rb +0 -1
  29. data/lib/inversion/template/elsiftag.rb +0 -1
  30. data/lib/inversion/template/endtag.rb +2 -3
  31. data/lib/inversion/template/escapetag.rb +1 -2
  32. data/lib/inversion/template/fortag.rb +2 -3
  33. data/lib/inversion/template/fragmenttag.rb +1 -2
  34. data/lib/inversion/template/iftag.rb +3 -1
  35. data/lib/inversion/template/importtag.rb +2 -3
  36. data/lib/inversion/template/includetag.rb +1 -2
  37. data/lib/inversion/template/node.rb +4 -5
  38. data/lib/inversion/template/pptag.rb +1 -2
  39. data/lib/inversion/template/publishtag.rb +2 -3
  40. data/lib/inversion/template/rescuetag.rb +1 -2
  41. data/lib/inversion/template/subscribetag.rb +3 -4
  42. data/lib/inversion/template/tag.rb +3 -4
  43. data/lib/inversion/template/textnode.rb +1 -2
  44. data/lib/inversion/template/timedeltatag.rb +1 -2
  45. data/lib/inversion/template/unlesstag.rb +0 -1
  46. data/lib/inversion/template/uriencodetag.rb +1 -2
  47. data/lib/inversion/template/yieldtag.rb +0 -1
  48. data/lib/inversion/template.rb +18 -22
  49. data/lib/inversion/tilt.rb +1 -2
  50. data/lib/inversion.rb +2 -3
  51. data/lib/roda/plugins/inversion.rb +225 -0
  52. data/spec/helpers.rb +19 -13
  53. data/spec/inversion/mixins_spec.rb +1 -1
  54. data/spec/inversion/parser_spec.rb +1 -1
  55. data/spec/inversion/refinements_spec.rb +22 -0
  56. data/spec/inversion/renderstate_spec.rb +1 -1
  57. data/spec/inversion/sinatra_spec.rb +1 -1
  58. data/spec/inversion/template/attrtag_spec.rb +1 -1
  59. data/spec/inversion/template/begintag_spec.rb +1 -1
  60. data/spec/inversion/template/calltag_spec.rb +1 -1
  61. data/spec/inversion/template/codetag_spec.rb +24 -1
  62. data/spec/inversion/template/commenttag_spec.rb +1 -1
  63. data/spec/inversion/template/configtag_spec.rb +1 -1
  64. data/spec/inversion/template/containertag_spec.rb +1 -1
  65. data/spec/inversion/template/defaulttag_spec.rb +1 -1
  66. data/spec/inversion/template/elsetag_spec.rb +1 -1
  67. data/spec/inversion/template/elsiftag_spec.rb +1 -1
  68. data/spec/inversion/template/endtag_spec.rb +1 -1
  69. data/spec/inversion/template/escapetag_spec.rb +1 -1
  70. data/spec/inversion/template/fortag_spec.rb +1 -1
  71. data/spec/inversion/template/fragmenttag_spec.rb +1 -1
  72. data/spec/inversion/template/iftag_spec.rb +1 -1
  73. data/spec/inversion/template/importtag_spec.rb +1 -1
  74. data/spec/inversion/template/includetag_spec.rb +1 -1
  75. data/spec/inversion/template/node_spec.rb +1 -1
  76. data/spec/inversion/template/pptag_spec.rb +1 -1
  77. data/spec/inversion/template/publishtag_spec.rb +1 -1
  78. data/spec/inversion/template/rescuetag_spec.rb +1 -1
  79. data/spec/inversion/template/subscribetag_spec.rb +1 -1
  80. data/spec/inversion/template/tag_spec.rb +1 -1
  81. data/spec/inversion/template/textnode_spec.rb +1 -1
  82. data/spec/inversion/template/timedeltatag_spec.rb +1 -1
  83. data/spec/inversion/template/unlesstag_spec.rb +1 -1
  84. data/spec/inversion/template/uriencodetag_spec.rb +1 -1
  85. data/spec/inversion/template/yieldtag_spec.rb +1 -1
  86. data/spec/inversion/template_spec.rb +1 -1
  87. data/spec/inversion/tilt_spec.rb +1 -1
  88. data/spec/inversion_spec.rb +1 -1
  89. data/spec/roda/plugins/inversion_spec.rb +91 -0
  90. data.tar.gz.sig +0 -0
  91. metadata +90 -58
  92. metadata.gz.sig +0 -0
  93. data/Examples.rdoc +0 -134
  94. data/GettingStarted.rdoc +0 -44
  95. data/Guide.rdoc +0 -47
  96. data/Manifest.txt +0 -86
  97. data/Rakefile +0 -7
  98. data/Tags.rdoc +0 -560
  99. data/lib/inversion/command.rb +0 -278
  100. data/lib/inversion/monkeypatches.rb +0 -21
  101. data/spec/inversion/monkeypatches_spec.rb +0 -25
@@ -13,7 +13,7 @@ rescue LoadError => err
13
13
  $sinatra_support = false
14
14
  end
15
15
 
16
- describe "Sinatra support", :if => $sinatra_support do
16
+ RSpec.describe "Sinatra support", :if => $sinatra_support do
17
17
  include Rack::Test::Methods if defined?( ::Rack )
18
18
 
19
19
  before( :each ) do
@@ -5,7 +5,7 @@ require_relative '../../helpers'
5
5
 
6
6
  require 'inversion/template/attrtag'
7
7
 
8
- describe Inversion::Template::AttrTag do
8
+ RSpec.describe Inversion::Template::AttrTag do
9
9
 
10
10
  describe "parsing" do
11
11
 
@@ -11,7 +11,7 @@ require 'inversion/template/rescuetag'
11
11
  require 'inversion/template/endtag'
12
12
  require 'inversion/renderstate'
13
13
 
14
- describe Inversion::Template::BeginTag do
14
+ RSpec.describe Inversion::Template::BeginTag do
15
15
 
16
16
 
17
17
  context "without any rescue clauses" do
@@ -5,7 +5,7 @@ require_relative '../../helpers'
5
5
 
6
6
  require 'inversion/template/calltag'
7
7
 
8
- describe Inversion::Template::CallTag do
8
+ RSpec.describe Inversion::Template::CallTag do
9
9
 
10
10
  # Since call is just an alias, the attrtag_spec already tests all of
11
11
  # this.
@@ -5,7 +5,7 @@ require_relative '../../helpers'
5
5
 
6
6
  require 'inversion/template/codetag'
7
7
 
8
- describe Inversion::Template::CodeTag do
8
+ RSpec.describe Inversion::Template::CodeTag do
9
9
 
10
10
 
11
11
  it "is an abstract class" do
@@ -70,4 +70,27 @@ describe Inversion::Template::CodeTag do
70
70
  }.to raise_exception( ScriptError, /patterns already exist/i )
71
71
  end
72
72
  end
73
+
74
+
75
+ it "throws an error if trying to declare a tag pattern with an invalid character" do
76
+ expect {
77
+ Class.new( described_class ) do
78
+ tag_pattern "°°°" do |tag, match|
79
+ :foo
80
+ end
81
+ end
82
+ }.to raise_error( Ripper::TokenPattern::CompileError, /invalid char/i )
83
+ end
84
+
85
+
86
+ it "throws an error if given an invalid tag pattern" do
87
+ expect {
88
+ Class.new( described_class ) do
89
+ tag_pattern "$(ident)$(" do |tag, match|
90
+ :foo
91
+ end
92
+ end
93
+ }.to raise_error( Ripper::TokenPattern::CompileError, /unmatched paren/i )
94
+ end
95
+
73
96
  end
@@ -8,7 +8,7 @@ require 'inversion/template/attrtag'
8
8
  require 'inversion/template/textnode'
9
9
  require 'inversion/renderstate'
10
10
 
11
- describe Inversion::Template::CommentTag do
11
+ RSpec.describe Inversion::Template::CommentTag do
12
12
 
13
13
  it "allows any free-form text in its body" do
14
14
  # <?comment Disabled for now ?>...<?end?>
@@ -5,7 +5,7 @@ require_relative '../../helpers'
5
5
 
6
6
  require 'inversion/template/configtag'
7
7
 
8
- describe Inversion::Template::ConfigTag do
8
+ RSpec.describe Inversion::Template::ConfigTag do
9
9
 
10
10
  # <?config comment_start: /* ?>
11
11
  # <?config comment_end: */ ?>
@@ -5,7 +5,7 @@ require_relative '../../helpers'
5
5
 
6
6
  require 'inversion/template/containertag'
7
7
 
8
- describe Inversion::Template::ContainerTag do
8
+ RSpec.describe Inversion::Template::ContainerTag do
9
9
 
10
10
  context "instances of including classes" do
11
11
 
@@ -5,7 +5,7 @@ require_relative '../../helpers'
5
5
 
6
6
  require 'inversion/template/defaulttag'
7
7
 
8
- describe Inversion::Template::DefaultTag do
8
+ RSpec.describe Inversion::Template::DefaultTag do
9
9
 
10
10
 
11
11
  it "sets a template attribute to a default value" do
@@ -10,7 +10,7 @@ require 'inversion/template/commenttag'
10
10
  require 'inversion/template/fortag'
11
11
  require 'inversion/renderstate'
12
12
 
13
- describe Inversion::Template::ElseTag do
13
+ RSpec.describe Inversion::Template::ElseTag do
14
14
 
15
15
  it "handles a non-existant body" do
16
16
  Inversion::Template::ElseTag.new( nil )
@@ -9,7 +9,7 @@ require 'inversion/template/unlesstag'
9
9
  require 'inversion/template/textnode'
10
10
  require 'inversion/renderstate'
11
11
 
12
- describe Inversion::Template::ElsifTag do
12
+ RSpec.describe Inversion::Template::ElsifTag do
13
13
 
14
14
 
15
15
  it "can be appended to an 'if' tag" do
@@ -8,7 +8,7 @@ require 'inversion/template/textnode'
8
8
  require 'inversion/template/endtag'
9
9
  require 'inversion/renderstate'
10
10
 
11
- describe Inversion::Template::EndTag do
11
+ RSpec.describe Inversion::Template::EndTag do
12
12
 
13
13
  before( :each ) do
14
14
  @tag = Inversion::Template::EndTag.new
@@ -5,7 +5,7 @@ require_relative '../../helpers'
5
5
 
6
6
  require 'inversion/template/escapetag'
7
7
 
8
- describe Inversion::Template::EscapeTag do
8
+ RSpec.describe Inversion::Template::EscapeTag do
9
9
 
10
10
  before( :each ) do
11
11
  @attribute_object = double( "template attribute" )
@@ -9,7 +9,7 @@ require 'inversion/template/attrtag'
9
9
  require 'inversion/template/textnode'
10
10
  require 'inversion/renderstate'
11
11
 
12
- describe Inversion::Template::ForTag do
12
+ RSpec.describe Inversion::Template::ForTag do
13
13
 
14
14
  it "knows which identifiers should be added to the template" do
15
15
  tag = Inversion::Template::ForTag.new( 'foo in bar' )
@@ -8,7 +8,7 @@ require 'inversion/template/attrtag'
8
8
  require 'inversion/template/textnode'
9
9
  require 'inversion/renderstate'
10
10
 
11
- describe Inversion::Template::FragmentTag do
11
+ RSpec.describe Inversion::Template::FragmentTag do
12
12
 
13
13
  it "raises a parse error if the body isn't a simple attribute" do
14
14
  expect {
@@ -7,7 +7,7 @@ require 'inversion/template/iftag'
7
7
  require 'inversion/template/textnode'
8
8
  require 'inversion/renderstate'
9
9
 
10
- describe Inversion::Template::IfTag do
10
+ RSpec.describe Inversion::Template::IfTag do
11
11
 
12
12
 
13
13
  it "renders its contents if its attribute is true" do
@@ -5,7 +5,7 @@ require_relative '../../helpers'
5
5
 
6
6
  require 'inversion/template/importtag'
7
7
 
8
- describe Inversion::Template::ImportTag do
8
+ RSpec.describe Inversion::Template::ImportTag do
9
9
 
10
10
  it "can import a single attribute" do
11
11
  tag = Inversion::Template::ImportTag.new( 'txn ' )
@@ -7,7 +7,7 @@ require 'timeout'
7
7
  require 'inversion/template'
8
8
  require 'inversion/template/includetag'
9
9
 
10
- describe Inversion::Template::IncludeTag do
10
+ RSpec.describe Inversion::Template::IncludeTag do
11
11
 
12
12
  it "renders the IncludeTag as an empty string" do
13
13
  included_path = Pathname.pwd + 'included.tmpl'
@@ -5,7 +5,7 @@ require_relative '../../helpers'
5
5
 
6
6
  require 'inversion/template/node'
7
7
 
8
- describe Inversion::Template::Node do
8
+ RSpec.describe Inversion::Template::Node do
9
9
 
10
10
  let( :concrete_subclass ) { Class.new(Inversion::Template::Node) }
11
11
 
@@ -5,7 +5,7 @@ require_relative '../../helpers'
5
5
 
6
6
  require 'inversion/template/pptag'
7
7
 
8
- describe Inversion::Template::PpTag do
8
+ RSpec.describe Inversion::Template::PpTag do
9
9
 
10
10
  before( :each ) do
11
11
  @attribute_object = double( "template attribute" )
@@ -5,7 +5,7 @@ require_relative '../../helpers'
5
5
 
6
6
  require 'inversion/template/publishtag'
7
7
 
8
- describe Inversion::Template::PublishTag do
8
+ RSpec.describe Inversion::Template::PublishTag do
9
9
 
10
10
  class TestSubscriber
11
11
  def initialize
@@ -9,7 +9,7 @@ require 'inversion/template/commenttag'
9
9
  require 'inversion/template/fortag'
10
10
  require 'inversion/renderstate'
11
11
 
12
- describe Inversion::Template::RescueTag do
12
+ RSpec.describe Inversion::Template::RescueTag do
13
13
 
14
14
  it "handles a non-existant body" do
15
15
  tag = Inversion::Template::RescueTag.new( nil )
@@ -7,7 +7,7 @@ require 'inversion/template'
7
7
  require 'inversion/template/textnode'
8
8
  require 'inversion/template/subscribetag'
9
9
 
10
- describe Inversion::Template::SubscribeTag do
10
+ RSpec.describe Inversion::Template::SubscribeTag do
11
11
 
12
12
 
13
13
  it "raises a parse error if the key isn't a simple attribute" do
@@ -5,7 +5,7 @@ require_relative '../../helpers'
5
5
 
6
6
  require 'inversion/template/tag'
7
7
 
8
- describe Inversion::Template::Tag do
8
+ RSpec.describe Inversion::Template::Tag do
9
9
 
10
10
  before( :all ) do
11
11
  @real_derivatives = Inversion::Template::Tag.derivatives.dup
@@ -5,7 +5,7 @@ require_relative '../../helpers'
5
5
 
6
6
  require 'inversion/template/textnode'
7
7
 
8
- describe Inversion::Template::TextNode do
8
+ RSpec.describe Inversion::Template::TextNode do
9
9
 
10
10
  before( :each ) do
11
11
  @state = Inversion::RenderState.new
@@ -5,7 +5,7 @@ require_relative '../../helpers'
5
5
 
6
6
  require 'inversion/template/timedeltatag'
7
7
 
8
- describe Inversion::Template::TimeDeltaTag do
8
+ RSpec.describe Inversion::Template::TimeDeltaTag do
9
9
 
10
10
  MINUTES = 60
11
11
  HOURS = 60 * MINUTES
@@ -7,7 +7,7 @@ require 'inversion/template/unlesstag'
7
7
  require 'inversion/template/textnode'
8
8
  require 'inversion/renderstate'
9
9
 
10
- describe Inversion::Template::UnlessTag do
10
+ RSpec.describe Inversion::Template::UnlessTag do
11
11
 
12
12
 
13
13
  it "renders its contents if its attribute is false" do
@@ -5,7 +5,7 @@ require_relative '../../helpers'
5
5
 
6
6
  require 'inversion/template/uriencodetag'
7
7
 
8
- describe Inversion::Template::UriencodeTag do
8
+ RSpec.describe Inversion::Template::UriencodeTag do
9
9
 
10
10
  before( :each ) do
11
11
  @attribute_object = double( "template attribute" )
@@ -5,7 +5,7 @@ require_relative '../../helpers'
5
5
 
6
6
  require 'inversion/template/yieldtag'
7
7
 
8
- describe Inversion::Template::YieldTag do
8
+ RSpec.describe Inversion::Template::YieldTag do
9
9
 
10
10
 
11
11
  it "calls the renderstate's block before rendering, and renders as its return value" do
@@ -7,7 +7,7 @@ require 'stringio'
7
7
 
8
8
  require 'inversion/template'
9
9
 
10
- describe Inversion::Template do
10
+ RSpec.describe Inversion::Template do
11
11
 
12
12
  before( :all ) do
13
13
  @default_template_path = Inversion::Template.template_paths
@@ -12,7 +12,7 @@ rescue LoadError => err
12
12
  $tilt_support = false
13
13
  end
14
14
 
15
- describe "Tilt support", :if => $tilt_support do
15
+ RSpec.describe "Tilt support", :if => $tilt_support do
16
16
 
17
17
  before( :all ) do
18
18
  setup_logging( :fatal )
@@ -5,7 +5,7 @@ require_relative 'helpers'
5
5
 
6
6
  require 'inversion'
7
7
 
8
- describe Inversion do
8
+ RSpec.describe Inversion do
9
9
 
10
10
  it "defines a version" do
11
11
  expect( described_class::VERSION ).to match( /^\d+(\.\d+)*$/ )
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env rspec -cfd -b
2
+ # vim: set noet nosta sw=4 ts=4 :
3
+
4
+ require_relative '../../helpers'
5
+
6
+ begin
7
+ require 'roda'
8
+ $roda_support = true
9
+ rescue LoadError => err
10
+ warn "Roda support testing disabled: %p: %s" % [ err.class, err.message ]
11
+ $roda_support = false
12
+ end
13
+
14
+
15
+ RSpec.describe "Roda support", :if => $roda_support do
16
+ include Rack::Test::Methods if defined?( ::Rack )
17
+
18
+ before( :all ) do
19
+ setup_logging( :fatal )
20
+ end
21
+
22
+ before( :each ) do
23
+ allow( Inversion::Template ).to receive( :load ).and_return( tmpl )
24
+ app.app # looks weird, but creates an instance for Rack::Test.
25
+ end
26
+
27
+ let( :tmpl ) { Inversion::Template.new("Hi <?attr name ?>!") }
28
+
29
+ let( :app ) do
30
+ Class.new( Roda ) do
31
+ plugin :inversion
32
+ templates \
33
+ tmpl: 'template.tmpl'
34
+
35
+ route do |r|
36
+ r.get "symbol" do
37
+ :tmpl
38
+ end
39
+
40
+ r.get "unknown" do
41
+ template( :nope )
42
+ end
43
+
44
+ r.get "template" do
45
+ tmpl = template( :tmpl )
46
+ tmpl.name = "handsome"
47
+ return tmpl
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+
54
+ it "registers itself with Roda on demand" do
55
+ plugs = Roda::RodaPlugins.instance_variable_get( :@plugins )
56
+ expect( plugs[:inversion] ).to be( Roda::RodaPlugins::Inversion )
57
+ end
58
+
59
+
60
+ it "extends the Roda DSL with a #template helper method" do
61
+ expect( app.instance_methods ).to include( :template )
62
+ end
63
+
64
+
65
+ it "falls through to Roda default behavior on unmapped symbols" do
66
+ get '/nonexistent'
67
+ expect( last_response ).to_not be_ok
68
+ end
69
+
70
+
71
+ it "can reference a known template via symbol" do
72
+ get '/symbol'
73
+ expect( last_response ).to be_ok
74
+ expect( last_response.body ).to eq( 'Hi !' )
75
+ end
76
+
77
+
78
+ it "can render a returned template via template()" do
79
+ get '/template'
80
+ expect( last_response ).to be_ok
81
+ expect( last_response.body ).to eq( 'Hi handsome!' )
82
+ end
83
+
84
+
85
+ it "fails fast if referencing an unknown template at runtime" do
86
+ expect {
87
+ get '/unknown'
88
+ }.to raise_error( ArgumentError, /no :nope template registered/ )
89
+ end
90
+ end
91
+
data.tar.gz.sig CHANGED
Binary file