awestruct 0.4.8 → 0.5.0.cr

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. data/lib/awestruct/astruct.rb +4 -0
  2. data/lib/awestruct/astruct_mixin.rb +3 -0
  3. data/lib/awestruct/cli/auto.rb +6 -6
  4. data/lib/awestruct/cli/deploy.rb +3 -3
  5. data/lib/awestruct/cli/generate.rb +5 -3
  6. data/lib/awestruct/cli/init.rb +1 -1
  7. data/lib/awestruct/cli/invoker.rb +10 -3
  8. data/lib/awestruct/cli/manifest.rb +18 -17
  9. data/lib/awestruct/cli/options.rb +7 -6
  10. data/lib/awestruct/cli/server.rb +7 -14
  11. data/lib/awestruct/config.rb +7 -1
  12. data/lib/awestruct/config/default-site.yml +30 -0
  13. data/lib/awestruct/context_helper.rb +7 -7
  14. data/lib/awestruct/dependencies.rb +14 -11
  15. data/lib/awestruct/deploy/base_deploy.rb +2 -2
  16. data/lib/awestruct/deploy/github_pages_deploy.rb +1 -1
  17. data/lib/awestruct/deploy/rsync_deploy.rb +11 -15
  18. data/lib/awestruct/deploy/s3_deploy.rb +9 -0
  19. data/lib/awestruct/engine.rb +72 -21
  20. data/lib/awestruct/extensions/minify.rb +21 -20
  21. data/lib/awestruct/extensions/paginator.rb +5 -5
  22. data/lib/awestruct/extensions/partial.rb +1 -1
  23. data/lib/awestruct/extensions/pipeline.rb +5 -1
  24. data/lib/awestruct/extensions/posts.rb +8 -4
  25. data/lib/awestruct/extensions/relative.rb +7 -2
  26. data/lib/awestruct/extensions/remotePartial.rb +1 -1
  27. data/lib/awestruct/extensions/sitemap.rb +1 -1
  28. data/lib/awestruct/frameworks/bootstrap/base_index.html.haml +1 -1
  29. data/lib/awestruct/frameworks/bootstrap/base_layout.html.haml +1 -1
  30. data/lib/awestruct/handler_chains.rb +8 -23
  31. data/lib/awestruct/handlers/asciidoctor_handler.rb +114 -0
  32. data/lib/awestruct/handlers/base_tilt_handler.rb +114 -0
  33. data/lib/awestruct/handlers/css_tilt_handler.rb +43 -0
  34. data/lib/awestruct/handlers/front_matter_handler.rb +1 -1
  35. data/lib/awestruct/handlers/interpolation_handler.rb +3 -3
  36. data/lib/awestruct/handlers/layout_handler.rb +6 -4
  37. data/lib/awestruct/handlers/restructuredtext_handler.rb +5 -5
  38. data/lib/awestruct/handlers/template/asciidoc.rb +41 -0
  39. data/lib/awestruct/handlers/template/mustache.rb +25 -0
  40. data/lib/awestruct/handlers/tilt_handler.rb +73 -0
  41. data/lib/awestruct/layouts.rb +1 -1
  42. data/lib/awestruct/logger.rb +59 -0
  43. data/lib/awestruct/page.rb +16 -3
  44. data/lib/awestruct/page_loader.rb +5 -5
  45. data/lib/awestruct/version.rb +1 -1
  46. data/man/awestruct.1 +163 -0
  47. data/spec/asciidoc_handler_spec.rb +75 -0
  48. data/spec/astruct_spec.rb +52 -0
  49. data/spec/coffeescript_handler_spec.rb +23 -0
  50. data/spec/config_spec.rb +22 -0
  51. data/spec/context_helper_spec.rb +115 -0
  52. data/spec/deploy_spec.rb +41 -0
  53. data/spec/disqus_spec.rb +43 -0
  54. data/spec/engine_spec.rb +115 -0
  55. data/spec/erb_handler_spec.rb +52 -0
  56. data/spec/file_handler_spec.rb +57 -0
  57. data/spec/front_matter_handler_spec.rb +42 -0
  58. data/spec/github_pages_deploy_spec.rb +56 -0
  59. data/spec/haml_handler_spec.rb +93 -0
  60. data/spec/handler_chain_spec.rb +44 -0
  61. data/spec/handler_chains_spec.rb +25 -0
  62. data/spec/interpolation_handler_spec.rb +35 -0
  63. data/spec/invoker_spec.rb +74 -0
  64. data/spec/javascript_handler_spec.rb +23 -0
  65. data/spec/layout_handler_spec.rb +77 -0
  66. data/spec/layouts_spec.rb +32 -0
  67. data/spec/less_handler_spec.rb +33 -0
  68. data/spec/markdown_handler_spec.rb +41 -0
  69. data/spec/minify_spec.rb +61 -0
  70. data/spec/mustache_handler_spec.rb +29 -0
  71. data/spec/options_spec.rb +97 -0
  72. data/spec/orgmode_handler_spec.rb +24 -0
  73. data/spec/page_delegating_handler_spec.rb +79 -0
  74. data/spec/page_loader_spec.rb +43 -0
  75. data/spec/page_loader_spec_for_layouts.rb +36 -0
  76. data/spec/page_spec.rb +65 -0
  77. data/spec/pipeline_spec.rb +12 -0
  78. data/spec/posts_archive_spec.rb +108 -0
  79. data/spec/redirect_handler_spec.rb +32 -0
  80. data/spec/restructuredtext_handler_spec.rb +22 -0
  81. data/spec/rsync_deploy_spec.rb +9 -0
  82. data/spec/sass_handler_spec.rb +23 -0
  83. data/spec/scss_handler_spec.rb +23 -0
  84. data/spec/server_spec.rb +45 -0
  85. data/spec/slim_handler_spec.rb +81 -0
  86. data/spec/spec_helper.rb +18 -0
  87. data/spec/support/nokogiri_matchers.rb +21 -0
  88. data/spec/support/shared_handler_example.rb +98 -0
  89. data/spec/test-data/engine/_config/arbitrary.yml +2 -0
  90. data/spec/test-data/engine/_config/other.yml +1 -0
  91. data/spec/test-data/engine/_config/site.yml +14 -0
  92. data/spec/test-data/front-matter-file-no-content.txt +2 -0
  93. data/spec/test-data/front-matter-file-no-front.txt +1 -0
  94. data/spec/test-data/front-matter-file.txt +4 -0
  95. data/spec/test-data/handlers/asciidoc-page.ad +3 -0
  96. data/spec/test-data/handlers/asciidoc-page.adoc +3 -0
  97. data/spec/test-data/handlers/asciidoc-page.asciidoc +3 -0
  98. data/spec/test-data/handlers/asciidoctor_with_front_matter.ad +6 -0
  99. data/spec/test-data/handlers/asciidoctor_with_headers.ad +8 -0
  100. data/spec/test-data/handlers/coffeescript-page.coffee +8 -0
  101. data/spec/test-data/handlers/erb-page.html.erb +6 -0
  102. data/spec/test-data/handlers/erb-page.xml.erb +2 -0
  103. data/spec/test-data/handlers/erb-utf-page.html.erb +2 -0
  104. data/spec/test-data/handlers/haml-layout-two.html.haml +7 -0
  105. data/spec/test-data/handlers/haml-layout.html.haml +4 -0
  106. data/spec/test-data/handlers/haml-page.atom.haml +4 -0
  107. data/spec/test-data/handlers/haml-page.html.haml +2 -0
  108. data/spec/test-data/handlers/haml-page.xml.haml +1 -0
  109. data/spec/test-data/handlers/haml-with-markdown-page.html.haml +6 -0
  110. data/spec/test-data/handlers/haml-with-textile-page.html.haml +6 -0
  111. data/spec/test-data/handlers/haml-with-utf.html.haml +2 -0
  112. data/spec/test-data/handlers/haml-with-variables.html.haml +2 -0
  113. data/spec/test-data/handlers/inner-page.html.haml +4 -0
  114. data/spec/test-data/handlers/javascript-page.js +1 -0
  115. data/spec/test-data/handlers/less-page-include.less +1 -0
  116. data/spec/test-data/handlers/less-page-with-import.less +4 -0
  117. data/spec/test-data/handlers/less-page.less +4 -0
  118. data/spec/test-data/handlers/markdown-page.markdown +2 -0
  119. data/spec/test-data/handlers/markdown-page.md +2 -0
  120. data/spec/test-data/handlers/markdown-page.mkd +2 -0
  121. data/spec/test-data/handlers/mustache-page.html.mustache +2 -0
  122. data/spec/test-data/handlers/mustache-page.xml.mustache +1 -0
  123. data/spec/test-data/handlers/orgmode-page.org +6 -0
  124. data/spec/test-data/handlers/outer-layout.html.haml +2 -0
  125. data/spec/test-data/handlers/outside_relative/git_keep +3 -0
  126. data/spec/test-data/handlers/redirect-page.redirect +1 -0
  127. data/spec/test-data/handlers/restructuredtext-page.rst +8 -0
  128. data/spec/test-data/handlers/sass-page-include.sass +1 -0
  129. data/spec/test-data/handlers/sass-page.sass +4 -0
  130. data/spec/test-data/handlers/scss-page-include.scss +1 -0
  131. data/spec/test-data/handlers/scss-page.scss +5 -0
  132. data/spec/test-data/handlers/simple-redirect-page.redirect +1 -0
  133. data/spec/test-data/handlers/slim-page.atom.slim +4 -0
  134. data/spec/test-data/handlers/slim-page.html.slim +1 -0
  135. data/spec/test-data/handlers/slim-page.xml.slim +1 -0
  136. data/spec/test-data/handlers/slim-with-markdown-page.html.slim +5 -0
  137. data/spec/test-data/handlers/slim-with-utf.html.slim +2 -0
  138. data/spec/test-data/handlers/slim-with-variables.html.slim +1 -0
  139. data/spec/test-data/handlers/textile-page.textile +1 -0
  140. data/spec/test-data/images/logo.png +0 -0
  141. data/spec/test-data/index.html +242 -0
  142. data/spec/test-data/javascript/bootstrap-dropdown.js +92 -0
  143. data/spec/test-data/out-of-site/page-three.html.haml +2 -0
  144. data/spec/test-data/page-loader/_layouts/layout-one.md +2 -0
  145. data/spec/test-data/page-loader/_layouts/layout-two.html.haml +2 -0
  146. data/spec/test-data/page-loader/page-draft.md +5 -0
  147. data/spec/test-data/page-loader/page-one.md +2 -0
  148. data/spec/test-data/page-loader/page-two.html.haml +2 -0
  149. data/spec/test-data/simple-data.yaml +1 -0
  150. data/spec/test-data/simple-file.txt +1 -0
  151. data/spec/test-data/stylesheets/screen.css +688 -0
  152. data/spec/textile_handler_spec.rb +22 -0
  153. data/spec/tilt_handler_spec.rb +81 -0
  154. data/spec/yaml_handler_spec.rb +21 -0
  155. metadata +243 -202
  156. data/lib/awestruct/handlers/asciidoc_handler.rb +0 -86
  157. data/lib/awestruct/handlers/base_sass_handler.rb +0 -42
  158. data/lib/awestruct/handlers/coffeescript_handler.rb +0 -48
  159. data/lib/awestruct/handlers/erb_handler.rb +0 -43
  160. data/lib/awestruct/handlers/haml_handler.rb +0 -54
  161. data/lib/awestruct/handlers/less_handler.rb +0 -37
  162. data/lib/awestruct/handlers/markdown_handler.rb +0 -50
  163. data/lib/awestruct/handlers/mustache_handler.rb +0 -44
  164. data/lib/awestruct/handlers/orgmode_handler.rb +0 -48
  165. data/lib/awestruct/handlers/sass_handler.rb +0 -21
  166. data/lib/awestruct/handlers/scss_handler.rb +0 -21
  167. data/lib/awestruct/handlers/textile_handler.rb +0 -58
@@ -0,0 +1,52 @@
1
+ # -*- coding: UTF-8 -*-
2
+ require 'spec_helper'
3
+ require 'rbconfig'
4
+
5
+ verify = lambda { |output|
6
+ output.should =~ %r(<h1>This is an ERB page</h1>)
7
+ output.should =~ %r(<h2>The fruit of the day is: apples</h2>)
8
+ output.should =~ %r(<h3>bacon</h3>) ## interpolated
9
+ }
10
+
11
+ verify_with_xml = lambda { |output|
12
+ output.should =~ %r(<h>bacon</h>) ## interpolated
13
+ }
14
+
15
+ verify_with_utf8 = lambda { |output|
16
+ if(RbConfig::CONFIG['target_os'] !~ /mswin|mingw/)
17
+ output.should == "Besøg fra Danmark\n"
18
+ else
19
+ output.should == "\r\nBesøg fra Danmark\r\n"
20
+ end
21
+ }
22
+
23
+ theories =
24
+ [
25
+ {
26
+ :page => "erb-page.html.erb",
27
+ :simple_name => "erb-page",
28
+ :syntax => :erb,
29
+ :extension => '.html',
30
+ :matcher => verify
31
+ },
32
+ {
33
+ :page => "erb-page.xml.erb",
34
+ :simple_name => "erb-page",
35
+ :syntax => :erb,
36
+ :extension => '.xml',
37
+ :matcher => verify_with_xml
38
+ },
39
+ {
40
+ :page => "erb-utf-page.html.erb",
41
+ :simple_name => "erb-utf-page",
42
+ :syntax => :erb,
43
+ :extension => '.html',
44
+ :matcher => verify_with_utf8
45
+ }
46
+ ]
47
+
48
+ describe Awestruct::Handlers::TiltHandler.to_s + "-Erb" do
49
+ let(:additional_config) { {:crunchy => 'bacon'} }
50
+ it_should_behave_like "a handler", theories
51
+
52
+ end
@@ -0,0 +1,57 @@
1
+ require 'fileutils'
2
+
3
+ require 'awestruct/handlers/file_handler'
4
+
5
+ describe Awestruct::Handlers::FileHandler do
6
+
7
+ before :all do
8
+ @site = OpenCascade.new :encoding=>false, :dir=>Pathname.new( File.dirname( __FILE__ ) + '/test-data' )
9
+ end
10
+
11
+ it "should be able to read a valid absolute file handler" do
12
+ filename = Pathname.new( File.dirname(__FILE__) + "/test-data/simple-file.txt" )
13
+ handler = Awestruct::Handlers::FileHandler.new( @site, filename )
14
+ handler.raw_content.strip.should == 'howdy'
15
+ end
16
+
17
+ it "should be able to read a valid relative file handler" do
18
+ filename = Pathname.new( File.dirname(__FILE__) + "/test-data/simple-file.txt" )
19
+ pwd = Pathname.new( Dir.pwd )
20
+ handler = Awestruct::Handlers::FileHandler.new( @site, filename.relative_path_from( pwd ) )
21
+ handler.raw_content.strip.should == 'howdy'
22
+ end
23
+
24
+ it "should be stale before being read" do
25
+ filename = Pathname.new( File.dirname(__FILE__) + "/test-data/simple-file.txt" )
26
+ handler = Awestruct::Handlers::FileHandler.new( @site, filename )
27
+ handler.should be_stale
28
+ end
29
+
30
+ it "should not be stale after being read" do
31
+ filename = Pathname.new( File.dirname(__FILE__) + "/test-data/simple-file.txt" )
32
+ handler = Awestruct::Handlers::FileHandler.new( @site, filename )
33
+ handler.raw_content.strip.should == 'howdy'
34
+ handler.should_not be_stale
35
+ end
36
+
37
+ it "should be stale if touched after being read" do
38
+ filename = Pathname.new( File.dirname(__FILE__) + "/test-data/simple-file.txt" )
39
+ handler = Awestruct::Handlers::FileHandler.new( @site, filename )
40
+ handler.raw_content.strip.should == 'howdy'
41
+ handler.should_not be_stale
42
+ sleep(1)
43
+ FileUtils.touch( filename )
44
+ handler.should be_stale
45
+ end
46
+
47
+ it "should provide reasonable paths" do
48
+ filename = Pathname.new( File.dirname(__FILE__) + "/test-data/simple-file.txt" )
49
+ handler = Awestruct::Handlers::FileHandler.new( @site, filename )
50
+ handler.relative_source_path.should == '/simple-file.txt'
51
+ handler.output_filename.should == 'simple-file.txt'
52
+ handler.output_extension.should == '.txt'
53
+ handler.output_path.should == '/simple-file.txt'
54
+ end
55
+
56
+ end
57
+
@@ -0,0 +1,42 @@
1
+ require 'fileutils'
2
+
3
+ require 'awestruct/handlers/file_handler'
4
+ require 'awestruct/handlers/front_matter_handler'
5
+
6
+ describe Awestruct::Handlers::FrontMatterHandler do
7
+
8
+ before :all do
9
+ @site = OpenCascade.new :encoding=>false
10
+ end
11
+
12
+ before :each do
13
+ end
14
+
15
+ def file_input(filename)
16
+ filename = Pathname.new( File.dirname(__FILE__) + "/test-data/#{filename}" )
17
+ Awestruct::Handlers::FileHandler.new( @site, filename )
18
+ end
19
+
20
+ it "should be able to split front-matter from content" do
21
+ handler = Awestruct::Handlers::FrontMatterHandler.new( @site, file_input( "front-matter-file.txt" ) )
22
+ handler.front_matter.should_not be_nil
23
+ handler.front_matter['foo'].should == 'bar'
24
+ handler.raw_content.strip.should == 'This is some content'
25
+ end
26
+
27
+ it "should be able to split front-matter from content for files without actual front-matter" do
28
+ handler = Awestruct::Handlers::FrontMatterHandler.new( @site, file_input( "front-matter-file-no-front.txt" ) )
29
+ handler.front_matter.should_not be_nil
30
+ handler.front_matter.should be_empty
31
+ handler.raw_content.strip.should == 'This is some content'
32
+ end
33
+
34
+ it "should be able to split front-matter from content for files without actual content" do
35
+ handler = Awestruct::Handlers::FrontMatterHandler.new( @site, file_input( "front-matter-file-no-content.txt" ) )
36
+ handler.front_matter.should_not be_nil
37
+ handler.front_matter['foo'].should == 'bar'
38
+ handler.raw_content.should be_nil
39
+ end
40
+
41
+ end
42
+
@@ -0,0 +1,56 @@
1
+ require 'awestruct/deploy/github_pages_deploy'
2
+
3
+ describe Awestruct::Deploy::GitHubPagesDeploy do
4
+
5
+ before :each do
6
+ site_config = mock
7
+ site_config.stub(:output_dir).and_return '_site'
8
+
9
+ @deploy_config = mock
10
+ @deploy_config.stub(:[]).with('branch').and_return('the-branch')
11
+ @deploy_config.stub(:[]).with('repository').and_return('the-repo')
12
+ @deploy_config.stub(:[]).with('uncommitted').and_return('false')
13
+ @deployer = Awestruct::Deploy::GitHubPagesDeploy.new( site_config, @deploy_config )
14
+
15
+ @git = mock
16
+ @git.stub_chain(:status, :changed, :empty?).and_return true
17
+ ::Git.stub(:open).with('.').and_return @git
18
+ end
19
+
20
+ it "should be auto-registered" do
21
+ Awestruct::Deployers.instance[ :github_pages ].should == Awestruct::Deploy::GitHubPagesDeploy
22
+ end
23
+
24
+ it "should publish the site if there have been changes to the git repo" do
25
+ ::Git.should_receive(:open).with('.').and_return @git
26
+ @deployer.should_receive(:publish_site)
27
+ @deployer.run(@deploy_config)
28
+ end
29
+
30
+ it "should warn and noop if no changes have been committed" do
31
+ @git.stub_chain(:status, :changed, :empty?).and_return false
32
+ $LOG.should_receive(:error).with(Awestruct::Deploy::Base::UNCOMMITTED_CHANGES)
33
+ @deployer.run(@deploy_config)
34
+ end
35
+
36
+ it "should save and restore the current branch when publishing" do
37
+ @git.should_receive(:current_branch).and_return( 'bacon' )
38
+ @git.stub_chain(:branch, :checkout)
39
+ @git.should_receive(:push).with('the-repo', 'the-branch')
40
+ @git.should_receive(:checkout).with( 'bacon' )
41
+
42
+ @deployer.stub(:add_and_commit_site)
43
+ @deployer.run(@deploy_config)
44
+ end
45
+
46
+ it "should save and restore the current detached branch when publishing" do
47
+ @git.should_receive(:current_branch).and_return( '(no branch)' )
48
+ @git.should_receive(:revparse).with( 'HEAD' ).and_return( '0123456789' )
49
+ @git.stub_chain(:branch, :checkout)
50
+ @git.should_receive(:push).with('the-repo', 'the-branch')
51
+ @git.should_receive(:checkout).with( '0123456789' )
52
+
53
+ @deployer.stub(:add_and_commit_site)
54
+ @deployer.run(@deploy_config)
55
+ end
56
+ end
@@ -0,0 +1,93 @@
1
+ # -*- coding: UTF-8 -*-
2
+ require 'spec_helper'
3
+
4
+ verify = lambda { |output|
5
+ output.should =~ %r(<h1>This is a HAML page</h1>)
6
+ }
7
+
8
+ verify_atom = lambda { |output|
9
+ output.should == %(<?xml version="1.0" encoding="utf-8" ?>
10
+ <feed xmlns="http://www.w3.org/2005/Atom">
11
+ <id>http://example.com</id>
12
+ <title>A News Feed</title>
13
+ </feed>
14
+ )
15
+ }
16
+
17
+ verify_with_markdown = lambda { |output|
18
+ output.should =~ %r(<h1[^>]*?>Hello From Markdown</h1>)
19
+ }
20
+
21
+ verify_with_textile = lambda { |output|
22
+ output.should =~ %r(<h1>Hello From Textile</h1>)
23
+ }
24
+
25
+ verify_with_utf8 = lambda { |output|
26
+ output.should == "<h1>Besøg fra Danmark</h1>\n"
27
+ }
28
+
29
+ verify_with_variables = lambda { |output|
30
+ output.should =~ %r(<h1>bacon</h1>)
31
+ }
32
+
33
+ theories =
34
+ [
35
+ {
36
+ :page => "haml-page.html.haml",
37
+ :simple_name => "haml-page",
38
+ :syntax => :haml,
39
+ :extension => '.html',
40
+ :format => :html5,
41
+ :matcher => verify
42
+ },
43
+ {
44
+ :page => "haml-page.xml.haml",
45
+ :simple_name => "haml-page",
46
+ :syntax => :haml,
47
+ :extension => '.xml',
48
+ :format => :xhtml,
49
+ :matcher => verify
50
+ },
51
+ {
52
+ :page => 'haml-page.atom.haml',
53
+ :simple_name => 'haml-page',
54
+ :syntax => :haml,
55
+ :extension => '.atom',
56
+ :format => :xhtml,
57
+ :matcher => verify_atom
58
+ },
59
+ {
60
+ :page => "haml-with-markdown-page.html.haml",
61
+ :simple_name => "haml-with-markdown-page",
62
+ :syntax => :haml,
63
+ :extension => '.html',
64
+ :matcher => verify_with_markdown
65
+ },
66
+ {
67
+ :page => "haml-with-textile-page.html.haml",
68
+ :simple_name => "haml-with-textile-page",
69
+ :syntax => :haml,
70
+ :extension => '.html',
71
+ :matcher => verify_with_textile
72
+ },
73
+ {
74
+ :page => "haml-with-utf.html.haml",
75
+ :simple_name => "haml-with-utf",
76
+ :syntax => :haml,
77
+ :extension => '.html',
78
+ :matcher => verify_with_utf8
79
+ },
80
+ {
81
+ :page => "haml-with-variables.html.haml",
82
+ :simple_name => "haml-with-variables",
83
+ :syntax => :haml,
84
+ :extension => '.html',
85
+ :matcher => verify_with_variables
86
+ }
87
+ ]
88
+
89
+ describe Awestruct::Handlers::TiltHandler.to_s + "-Haml" do
90
+ let(:additional_config) { {:crunchy => 'bacon'} }
91
+ it_should_behave_like "a handler", theories
92
+
93
+ end
@@ -0,0 +1,44 @@
1
+
2
+ require 'awestruct/handler_chain'
3
+
4
+ require 'hashery/open_cascade'
5
+
6
+ describe Awestruct::HandlerChain do
7
+
8
+ class BaseMockHandler
9
+ attr_reader :site, :arg
10
+ def initialize(site, arg)
11
+ @site, @arg = site, arg
12
+ end
13
+ end
14
+
15
+ class HandlerOne < BaseMockHandler; end
16
+ class HandlerTwo < BaseMockHandler; end
17
+ class HandlerThree < BaseMockHandler; end
18
+
19
+
20
+ before :all do
21
+ @site = OpenCascade.new :encoding=>false
22
+ end
23
+
24
+ it "should use a regexp to match" do
25
+ chain = Awestruct::HandlerChain.new( /foo/ )
26
+ chain.should be_matches( "foot" )
27
+ chain.should_not be_matches( "hand" )
28
+ end
29
+
30
+ it "should nest handlers in order, first being deepest" do
31
+ chain = Awestruct::HandlerChain.new( /foo/ )
32
+ chain.handler_classes << HandlerOne
33
+ chain.handler_classes << HandlerTwo
34
+ chain.handler_classes << HandlerThree
35
+
36
+ result = chain.create( @site, "foot" )
37
+
38
+ result.should be_a HandlerThree
39
+ result.arg.should be_a HandlerTwo
40
+ result.arg.arg.should be_a HandlerOne
41
+ result.arg.arg.arg.should == "foot"
42
+ end
43
+
44
+ end
@@ -0,0 +1,25 @@
1
+
2
+ require 'awestruct/handler_chain'
3
+ require 'awestruct/handler_chains'
4
+
5
+ describe Awestruct::HandlerChains do
6
+
7
+ it "should perform matching in-order" do
8
+
9
+ chains = Awestruct::HandlerChains.new(false)
10
+
11
+ chain1 = Awestruct::HandlerChain.new( /foot/ )
12
+ chain2 = Awestruct::HandlerChain.new( /foo/ )
13
+ chain3 = Awestruct::HandlerChain.new( /.*/ )
14
+
15
+ chains << chain1
16
+ chains << chain2
17
+ chains << chain3
18
+
19
+ chains[ 'foot' ].should == chain1
20
+ chains[ 'foo' ].should == chain2
21
+ chains[ 'hand' ].should == chain3
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,35 @@
1
+ require 'hashery/open_cascade'
2
+ require 'awestruct/handlers/string_handler'
3
+ require 'awestruct/handlers/interpolation_handler'
4
+
5
+ describe Awestruct::Handlers::InterpolationHandler do
6
+
7
+ before :all do
8
+ @site = OpenCascade.new :encoding=>false
9
+ end
10
+
11
+ it "should interpolate content when rendered" do
12
+ handler = build_handler( 'This is #{cheese}' )
13
+
14
+ context = OpenCascade.new :cheese=>'swiss'
15
+ content = handler.rendered_content( context )
16
+ content.should == 'This is swiss'
17
+ end
18
+
19
+ it "should correctly interpolate complicated stuff that includes regular expressions [Issue #139]" do
20
+ if RUBY_VERSION >= '1.9'
21
+ input = %q(url = url.replace(/\/?#$/, '');)
22
+ handler = build_handler( input )
23
+ content = handler.rendered_content( OpenCascade.new )
24
+ content.should == input
25
+ else
26
+ pending "Cannot yet handle this test case with ruby 1.8"
27
+ end
28
+ end
29
+
30
+ def build_handler( input )
31
+ Awestruct::Handlers::InterpolationHandler.new( @site, Awestruct::Handlers::StringHandler.new( @site, input ) )
32
+ end
33
+ end
34
+
35
+
@@ -0,0 +1,74 @@
1
+
2
+ require 'awestruct/cli/invoker'
3
+
4
+ describe Awestruct::CLI::Invoker do
5
+
6
+ it "should invoke generation by default" do
7
+ invoker = Awestruct::CLI::Invoker.new
8
+ invoker.should_not_receive( :invoke_init )
9
+ invoker.should_not_receive( :invoke_script )
10
+ invoker.should_not_receive( :invoke_force )
11
+ invoker.should_receive( :invoke_generate )
12
+ invoker.should_not_receive( :invoke_deploy )
13
+ invoker.should_not_receive( :invoke_auto )
14
+ invoker.should_not_receive( :invoke_server )
15
+ invoker.invoke!
16
+ end
17
+
18
+ it "should only invoke initialization things when initializing" do
19
+ invoker = Awestruct::CLI::Invoker.new( '--init' )
20
+ invoker.should_receive( :invoke_init )
21
+ invoker.should_not_receive( :invoke_script )
22
+ invoker.should_not_receive( :invoke_force )
23
+ invoker.should_not_receive( :invoke_generate )
24
+ invoker.should_not_receive( :invoke_deploy )
25
+ invoker.should_not_receive( :invoke_auto )
26
+ invoker.should_not_receive( :invoke_server )
27
+ invoker.invoke!
28
+ end
29
+
30
+ it "should invoke generation and server when servered" do
31
+ invoker = Awestruct::CLI::Invoker.new( '--server' )
32
+ invoker.should_not_receive( :invoke_init )
33
+ invoker.should_not_receive( :invoke_script )
34
+ invoker.should_not_receive( :invoke_force )
35
+ invoker.should_receive( :invoke_generate )
36
+ invoker.should_not_receive( :invoke_deploy )
37
+ invoker.should_not_receive( :invoke_auto )
38
+ invoker.should_receive( :invoke_server )
39
+ invoker.invoke!
40
+ end
41
+
42
+ it "should invoke generation and server and auto when dev-mode" do
43
+ invoker = Awestruct::CLI::Invoker.new( '-d' )
44
+ invoker.should_not_receive( :invoke_init )
45
+ invoker.should_not_receive( :invoke_script )
46
+ invoker.should_not_receive( :invoke_force )
47
+ invoker.should_receive( :invoke_generate )
48
+ invoker.should_not_receive( :invoke_deploy )
49
+ invoker.should_receive( :invoke_auto )
50
+ invoker.should_receive( :invoke_server )
51
+ invoker.invoke!
52
+ end
53
+
54
+ it "should invoke init without generating" do
55
+ invoker = Awestruct::CLI::Invoker.new( '--init' )
56
+ invoker.should_receive( :invoke_init )
57
+ invoker.should_not_receive( :invoke_script )
58
+ invoker.should_not_receive( :invoke_force )
59
+ invoker.should_not_receive( :invoke_generate )
60
+ invoker.should_not_receive( :invoke_deploy )
61
+ invoker.should_not_receive( :invoke_auto )
62
+ invoker.should_not_receive( :invoke_server )
63
+ invoker.invoke!
64
+ end
65
+
66
+ it "should return false on failure" do
67
+ generator = mock
68
+ Awestruct::CLI::Generate.should_receive( :new ).and_return( generator )
69
+ generator.should_receive( :run ).and_return( false )
70
+ Awestruct::CLI::Invoker.new( '--generate' ).invoke!.should be_false
71
+ end
72
+
73
+
74
+ end