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,75 @@
1
+ require 'spec_helper'
2
+ require 'rspec/matchers.rb'
3
+
4
+ verify = lambda { |output|
5
+ output.gsub(/(^\s*\n|^\s*)/, '').should =~ %r(<div id="preamble">
6
+ <div class="sectionbody">
7
+ <div class="paragraph">
8
+ <p>This is <strong>AsciiDoc</strong> in Awestruct.</p>
9
+ </div>
10
+ </div>
11
+ </div>)
12
+ }
13
+
14
+ verify_front_matter = lambda { |output, page|
15
+ page.title.should == 'AwestructAsciiDoc'
16
+ output.should_not =~ %r(title: AwestructAsciiDoc)
17
+ }
18
+
19
+ verify_headers = lambda { |output, page|
20
+ extend RSpec::Matchers
21
+ page.author.should == 'Stuart Rackham'
22
+ page.title.should == 'AsciiDoc'
23
+ page.doctitle.should == 'AsciiDoc'
24
+ page.name.should == 'Awestruct'
25
+ page.tags.should be_a_kind_of(Array)
26
+ page.tags.should == %w(a b c)
27
+ page.date.should be_a_kind_of(Date)
28
+ output.should =~ %r(This is <strong>AsciiDoc</strong> in Awestruct.)
29
+ output.should =~ %r(#{Awestruct::VERSION})
30
+ }
31
+
32
+ theories =
33
+ [
34
+ {
35
+ :page => "asciidoc-page.ad",
36
+ :simple_name => "asciidoc-page",
37
+ :syntax => :asciidoc,
38
+ :extension => '.html',
39
+ :matcher => verify
40
+ },
41
+ {
42
+ :page => "asciidoc-page.adoc",
43
+ :simple_name => "asciidoc-page",
44
+ :syntax => :asciidoc,
45
+ :extension => '.html',
46
+ :matcher => verify
47
+ },
48
+ {
49
+ :page => "asciidoc-page.asciidoc",
50
+ :simple_name => "asciidoc-page",
51
+ :syntax => :asciidoc,
52
+ :extension => '.html',
53
+ :matcher => verify
54
+ },
55
+ {
56
+ :page => "asciidoctor_with_front_matter.ad",
57
+ :simple_name => "asciidoctor_with_front_matter",
58
+ :syntax => :asciidoc,
59
+ :extension => '.html' ,
60
+ :matcher => verify_front_matter
61
+ },
62
+ {
63
+ :page => "asciidoctor_with_headers.ad",
64
+ :simple_name => "asciidoctor_with_headers",
65
+ :syntax => :asciidoc,
66
+ :extension => '.html',
67
+ :matcher => verify_headers
68
+ }
69
+ ]
70
+
71
+ describe Awestruct::Handlers::AsciidoctorHandler do
72
+ let(:additional_config_page) { {:name => 'Awestruct', :test => 10} }
73
+ it_should_behave_like "a handler", theories
74
+
75
+ end
@@ -0,0 +1,52 @@
1
+
2
+ require 'awestruct/astruct'
3
+ require 'awestruct/page'
4
+
5
+ describe Awestruct::AStruct do
6
+
7
+ it "should initialize from hash provided in constructor" do
8
+ s = Awestruct::AStruct.new( :foo=>'bar', 'taco'=>'tasty' )
9
+ s[:foo].should == 'bar'
10
+ s['taco'].should == 'tasty'
11
+ end
12
+
13
+ it "should allow access to members through indifferent hash access" do
14
+ s = Awestruct::AStruct.new( :foo=>'bar', 'taco'=>'tasty' )
15
+ s['foo'].should == 'bar'
16
+ s[:foo].should == 'bar'
17
+
18
+ s['taco'].should == 'tasty'
19
+ s[:taco].should == 'tasty'
20
+ end
21
+
22
+ it "should allow method access to members" do
23
+ s = Awestruct::AStruct.new( :foo=>'bar', 'taco'=>'tasty' )
24
+ s.foo.should == 'bar'
25
+ s.taco.should == 'tasty'
26
+ end
27
+
28
+ it "should cascade AStructs to inner array members" do
29
+ s = Awestruct::AStruct.new( :foo=>[ { 'taco'=>'tasty' } ] )
30
+ s.foo.first.taco.should == 'tasty'
31
+ end
32
+
33
+ it "should preserve the actual array instance holding any inner structs" do
34
+ inner_hash = { 'taco'=>'tasty' }
35
+ array = [ inner_hash ]
36
+ s = Awestruct::AStruct.new( :foo=>array )
37
+ s.foo.first.taco.should == 'tasty'
38
+ s.foo.object_id.should == array.object_id
39
+ end
40
+
41
+ it "should cascade AStruct to inner hash value structs" do
42
+ s = Awestruct::AStruct.new( :foo=>{ 'taco'=>'tasty' } )
43
+ s.foo.taco.should == 'tasty'
44
+ end
45
+
46
+ it "should allow any method to be called, resulting in nil" do
47
+ s = Awestruct::AStruct.new( :foo=>'bar' )
48
+ s.foo.should == 'bar'
49
+ s.taco.should be_nil
50
+ end
51
+
52
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ verify = lambda { |output|
4
+ output.should =~ /function\(\)/
5
+ output.should =~ /call\(this\)/
6
+ }
7
+
8
+ theories =
9
+ [
10
+ {
11
+ :page => "coffeescript-page.coffee",
12
+ :simple_name => "coffeescript-page",
13
+ :syntax => :coffeescript,
14
+ :extension => '.js',
15
+ :matcher => verify
16
+ }
17
+ ]
18
+
19
+ describe Awestruct::Handlers::TiltHandler.to_s + "-CoffeeScript" do
20
+
21
+ it_should_behave_like "a handler", theories
22
+
23
+ end
@@ -0,0 +1,22 @@
1
+ require 'awestruct/config'
2
+ require 'spec_helper'
3
+ require 'awestruct/config'
4
+
5
+ describe Awestruct::Config do
6
+
7
+ it "should accept a list of files in .awestruct_ignore to ignore on site generation" do
8
+ site_dir = File.join(File.dirname(__FILE__), 'test-data')
9
+ config = Awestruct::Config.new(site_dir)
10
+ config.ignore.should == ["Rakefile", "Gemfile"]
11
+ end
12
+
13
+ it "should handle an empty .awestruct_ignore file without barfing" do
14
+ site_dir = File.join(File.dirname(__FILE__), 'test-data')
15
+ config_file = File.join(site_dir, ".awestruct_ignore")
16
+ File.open(config_file, "w")
17
+ config = Awestruct::Config.new(site_dir)
18
+ config.ignore.should == []
19
+ File.open(config_file, "w") { |f| f.write("Rakefile\nGemfile\n") }
20
+ end
21
+
22
+ end
@@ -0,0 +1,115 @@
1
+ require 'spec_helper'
2
+ require 'awestruct/context_helper'
3
+
4
+ class Tester
5
+ include Awestruct::ContextHelper
6
+ end
7
+
8
+ describe Awestruct::ContextHelper do
9
+ before :each do
10
+ @tester = Tester.new
11
+ end
12
+
13
+ describe "html_to_text" do
14
+
15
+ it "should strip HTML tags" do
16
+ str = "<h1>A Title</h1>"
17
+ @tester.html_to_text(str).should == "A Title"
18
+ end
19
+
20
+ it "should replace &nbsp; with a space" do
21
+ str = "foo&nbsp;bar"
22
+ @tester.html_to_text(str).should == "foo bar"
23
+ end
24
+ end
25
+
26
+ describe "clean_html" do
27
+ # this is an odd, less useful version of html_to_text
28
+ it "should replace &nbsp; with a space" do
29
+ str = "foo&nbsp;bar"
30
+ @tester.clean_html(str).should == "foo bar"
31
+ end
32
+ end
33
+
34
+ describe "without_images" do
35
+ it "should remove image tags, but not other tags" do
36
+ str = "<h1>Hello!</h1><img src='images/foo'/>"
37
+ @tester.without_images(str).should == "<h1>Hello!</h1>"
38
+ end
39
+
40
+ it "should remove surrounding anchor tags if they exist" do
41
+ str = "<h1>Hello!</h1><a href='foobar'><img src='images/foo'/></a>"
42
+ @tester.without_images(str).should == "<h1>Hello!</h1>"
43
+ end
44
+
45
+ it "should not remove anchor tags around text" do
46
+ str = "<h1>Hello!</h1><a href='foobar'>foobar</a>"
47
+ @tester.without_images(str).should == "<h1>Hello!</h1>foobar"
48
+ end
49
+ end
50
+
51
+ describe "close_tags"
52
+
53
+ describe "summarize" do
54
+
55
+ before :all do
56
+ @long_string = "Once upon a time there was a horse who loved apples. He loved them so much that he ate one every day."
57
+ end
58
+
59
+ it "should shorten a string to 20 words by default" do
60
+ @tester.summarize(@long_string).split(/ /).size.should == 20
61
+ end
62
+
63
+ it "should append the shortened string with an ellipses" do
64
+ @tester.summarize(@long_string)[-3..-1].should == "..."
65
+ end
66
+
67
+ it "should allow customization of the number of words" do
68
+ @tester.summarize(@long_string, 10).split(/ /).size.should == 10
69
+ end
70
+
71
+ it "should allow customization of the appended ellipses" do
72
+ @tester.summarize(@long_string, 5, "---")[-3..-1].should == "---"
73
+ end
74
+ end
75
+
76
+ describe "fully_qualify_urls" do
77
+ it "should fix anchor tags" do
78
+ str = "<a href='/foo'>foobar</a>"
79
+ @tester.fully_qualify_urls('http://foobar.com', str).should == "<a href=\"http://foobar.com/foo\">foobar</a>"
80
+ end
81
+
82
+ it "should fix link tags" do
83
+ str = "<link href='/foo' />"
84
+ #nokogiri html doesn't close optional ending tags
85
+ @tester.fully_qualify_urls('http://foobar.com', str).should == "<link href=\"http://foobar.com/foo\">"
86
+ end
87
+
88
+ it "should fix image tags" do
89
+ str = "<img src='/foo' />"
90
+ #nokogiri html doesn't close optional ending tags
91
+ @tester.fully_qualify_urls('http://foobar.com', str).should == "<img src=\"http://foobar.com/foo\">"
92
+ end
93
+
94
+ it "should leave anchor tags with no href attribute (for page anchors) unchanged" do
95
+ str = "<a target=\"#foo\">foobar</a>"
96
+ @tester.fully_qualify_urls('http://foobar.com', str).should == str
97
+ end
98
+ end
99
+
100
+ describe "fix_url" do # This method is simple minded and dresses funny
101
+
102
+ it "should return a fully qualified url unchanged" do
103
+ str = "http://foobar.com/foo/bar"
104
+ @tester.fix_url("http://foobar.com", str).should == str
105
+ end
106
+
107
+ it "should prepend the schema and hostname if required" do
108
+ str = "http://foobar.com/foo/bar"
109
+ @tester.fix_url("http://foobar.com", "/foo/bar").should == str
110
+ end
111
+
112
+ end
113
+
114
+ end
115
+
@@ -0,0 +1,41 @@
1
+
2
+ require 'awestruct/cli/deploy'
3
+
4
+ describe Awestruct::CLI::Deploy do
5
+
6
+ it "should use a given deploy[:type]" do
7
+ deployer = Awestruct::CLI::Deploy.new({}, {'type' => :foo})
8
+ deployer.deploy_type.should == :foo
9
+ end
10
+
11
+ it "should use rsync if no deploy[:type] is given" do
12
+ deployer = Awestruct::CLI::Deploy.new({}, {})
13
+ deployer.deploy_type.should == :rsync
14
+ end
15
+
16
+ it "should use github_pages if deploy['host'] is github_pages and no deploy[:type] is given" do
17
+ deployer = Awestruct::CLI::Deploy.new({}, {'host' => :github_pages})
18
+ deployer.deploy_type.should == :github_pages
19
+ end
20
+
21
+ it "should use a given deploy['type'] even if deploy['host'] is github_pages" do
22
+ deployer = Awestruct::CLI::Deploy.new({}, {'type' => :foo, 'host'=>:github_pages})
23
+ deployer.deploy_type.should == :foo
24
+ end
25
+
26
+ it "should use s3 if deploy['type'] is s3" do
27
+ deployer = Awestruct::CLI::Deploy.new({}, {'type' => :s3})
28
+ deployer.deploy_type.should == :s3
29
+ end
30
+
31
+ it "should work with strings for keys" do
32
+ deployer = Awestruct::CLI::Deploy.new({}, {'host' => :github_pages})
33
+ deployer.deploy_type.should == :github_pages
34
+ end
35
+
36
+ it "should work with strings for values" do
37
+ deployer = Awestruct::CLI::Deploy.new({}, {'host' => 'github_pages'})
38
+ deployer.deploy_type.should == :github_pages
39
+ end
40
+
41
+ end
@@ -0,0 +1,43 @@
1
+ require 'awestruct/page'
2
+ require 'awestruct/extensions/disqus'
3
+
4
+ describe Awestruct::Extensions::Disqus do
5
+
6
+ before :all do
7
+ @site = Awestruct::AStruct.new :encoding=>false, :disqus=>'spec', :base_url=>'http://example.org'
8
+ @disqus = Awestruct::Extensions::Disqus.new
9
+ end
10
+
11
+ before :each do
12
+ @page = Awestruct::Page.new @site
13
+ @page.date = Time.utc(2012,12,8)
14
+ @page.slug = 'spec-post'
15
+ @page.url = '/posts/2012/12/08/spec-post/'
16
+ @site.disqus_generate_id = true
17
+ @site.pages = [@page]
18
+ @disqus.execute(@site)
19
+ end
20
+
21
+ it "should assign the disqus short name" do
22
+ @page.disqus_comments().should match(/var disqus_shortname = '#{@site.disqus}';/)
23
+ @page.disqus_comments_count().should match(/var disqus_shortname = '#{@site.disqus}';/)
24
+ end
25
+
26
+ it "should generate an identifier if necessary when id generation is enabled" do
27
+ @page.disqus_comments().should match(/var disqus_identifier = "12bb52d0776930e01e9a410fd14f13382778e449";/)
28
+ @page.disqus_comments_link().should match(/ data-disqus-identifier="12bb52d0776930e01e9a410fd14f13382778e449"/)
29
+ end
30
+
31
+ it "should use the identifier specified in the page" do
32
+ @page.disqus_identifier = @page.slug
33
+ @page.disqus_comments().should match(/var disqus_identifier = "#{@page.disqus_identifier}";/)
34
+ @page.disqus_comments_link().should match(/ data-disqus-identifier="#{@page.disqus_identifier}"/)
35
+ end
36
+
37
+ it "should have a null identifier if no identifier is specified and id generation is disabled" do
38
+ @site.disqus_generate_id = false
39
+ @page.disqus_comments().should match(/var disqus_identifier = null;/)
40
+ @page.disqus_comments_link().should_not match(/ data-disqus-identifier=/)
41
+ end
42
+
43
+ end
@@ -0,0 +1,115 @@
1
+
2
+ require 'awestruct/engine'
3
+
4
+ require 'hashery/open_cascade'
5
+
6
+ describe Awestruct::Engine do
7
+
8
+ it "should be able to load default-site.yml" do
9
+ config = Awestruct::Config.new( File.dirname(__FILE__) + '/test-data/engine' )
10
+
11
+ engine = Awestruct::Engine.new(config)
12
+ engine.load_default_site_yaml
13
+
14
+ engine.site.asciidoctor.backend.should == 'html5'
15
+ end
16
+
17
+ it "should be able to override default with site" do
18
+ config = Awestruct::Config.new( File.dirname(__FILE__) + '/test-data/engine' )
19
+
20
+ engine = Awestruct::Engine.new(config)
21
+ engine.load_default_site_yaml
22
+ engine.load_site_yaml( 'development' )
23
+
24
+ engine.site.asciidoctor.attributes['backend'].should == 'html4'
25
+ end
26
+
27
+ it "should be able to load site.yml with the correct profile" do
28
+ config = Awestruct::Config.new( File.dirname(__FILE__) + '/test-data/engine' )
29
+
30
+ engine = Awestruct::Engine.new(config)
31
+ engine.load_site_yaml( 'development' )
32
+ engine.site.cook.should == 'microwave'
33
+ engine.site.title.should == 'Awestruction!'
34
+
35
+ engine = Awestruct::Engine.new(config)
36
+ engine.load_site_yaml( 'production' )
37
+ engine.site.cook.should == 'oven'
38
+ engine.site.title.should == 'Awestruction!'
39
+ end
40
+
41
+ it "should be able to load arbitrary _config/*.yml files" do
42
+ config = Awestruct::Config.new( File.dirname(__FILE__) + '/test-data/engine' )
43
+
44
+ engine = Awestruct::Engine.new(config)
45
+ engine.load_yaml( File.join( config.dir, '_config/arbitrary.yml' ) )
46
+ engine.site.arbitrary.name.should == 'randomness'
47
+ end
48
+
49
+ it "should be able to load all arbitary yamls" do
50
+ config = Awestruct::Config.new( File.dirname(__FILE__) + '/test-data/engine' )
51
+
52
+ engine = Awestruct::Engine.new(config)
53
+ engine.load_yamls
54
+
55
+ engine.site.arbitrary.name.should == 'randomness'
56
+ engine.site.other.tags.should == [ 'a', 'b', 'c' ]
57
+ end
58
+
59
+ it "should exclude line comments in compass by default in production mode" do
60
+ compass = compass_config
61
+ config = Awestruct::Config.new( File.dirname(__FILE__) + '/test-data/engine' )
62
+ engine = Awestruct::Engine.new(config)
63
+ engine.load_site_yaml( 'production' )
64
+ Compass.stub(:configuration).and_return(compass)
65
+ compass.should_receive(:line_comments=).with(false)
66
+ compass.should_receive(:output_style=).with(:compressed)
67
+ engine.configure_compass
68
+ end
69
+
70
+ it "should exclude minify in compass by default in production mode" do
71
+ compass = compass_config
72
+ config = Awestruct::Config.new( File.dirname(__FILE__) + '/test-data/engine' )
73
+ engine = Awestruct::Engine.new(config)
74
+ engine.load_site_yaml( 'production' )
75
+ Compass.stub(:configuration).and_return(compass)
76
+ compass.should_receive(:line_comments=).with(false)
77
+ compass.should_receive(:output_style=).with(:compressed)
78
+ engine.configure_compass
79
+ end
80
+
81
+ it "should include line comments in compass by default in development mode" do
82
+ compass = compass_config
83
+ config = Awestruct::Config.new( File.dirname(__FILE__) + '/test-data/engine' )
84
+ engine = Awestruct::Engine.new(config)
85
+ engine.load_site_yaml( 'development' )
86
+ Compass.stub(:configuration).and_return(compass)
87
+ compass.should_receive(:line_comments=).with(true)
88
+ compass.should_receive(:output_style=).with(:expanded)
89
+ engine.configure_compass
90
+ end
91
+
92
+ it "should accept site.compass_line_comments to configure behavior" do
93
+ compass = compass_config
94
+ config = Awestruct::Config.new( File.dirname(__FILE__) + '/test-data/engine' )
95
+ engine = Awestruct::Engine.new(config)
96
+ engine.load_site_yaml( 'staging' )
97
+ Compass.stub(:configuration).and_return(compass)
98
+ compass.should_receive(:line_comments=).with(false)
99
+ compass.should_receive(:output_style=).with(:expanded)
100
+ engine.configure_compass
101
+ end
102
+
103
+ end
104
+
105
+ def compass_config
106
+ config = mock
107
+ config.stub(:project_type=)
108
+ config.stub(:project_path=)
109
+ config.stub(:sass_dir=)
110
+ config.stub(:css_dir=)
111
+ config.stub(:javascripts_dir=)
112
+ config.stub(:images_dir=)
113
+ config.stub(:fonts_dir=)
114
+ config
115
+ end