machined 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,25 +2,25 @@ require 'spec_helper'
2
2
 
3
3
  describe Machined::Helpers::LocalsHelpers do
4
4
  let(:context) { build_context }
5
-
5
+
6
6
  describe '#locals=' do
7
7
  it 'sets psuedo local variables' do
8
8
  context.locals = { :text => 'Hello World', :body => nil }
9
9
  context.text.should == 'Hello World'
10
10
  context.body.should be_nil
11
11
  end
12
-
12
+
13
13
  it 'responds_to the local variable name' do
14
14
  context.locals = { :text => 'Hello World', :body => nil }
15
15
  context.respond_to?(:text).should be_true
16
16
  context.respond_to?(:body).should be_true
17
17
  end
18
-
18
+
19
19
  it "still raises errors if the method doesn't exist" do
20
20
  expect { context.not_a_local }.to raise_error(NoMethodError)
21
21
  context.respond_to?(:not_a_local).should be_false
22
22
  end
23
-
23
+
24
24
  it 'clears local variables when set to nil' do
25
25
  context.locals = { :text => 'Hello World' }
26
26
  context.locals = nil
@@ -28,7 +28,7 @@ describe Machined::Helpers::LocalsHelpers do
28
28
  context.respond_to?(:text).should be_false
29
29
  end
30
30
  end
31
-
31
+
32
32
  describe '#with_locals' do
33
33
  it 'temporarily changes the local variables' do
34
34
  context.locals = { :text => 'Hello World', :layout => 'main' }
@@ -5,43 +5,43 @@ describe Machined::Helpers::PageHelpers do
5
5
  it 'defaults to the default layout' do
6
6
  within_construct do |c|
7
7
  c.file 'pages/index.html.erb', '<%= layout %>'
8
-
8
+
9
9
  machined :layout => 'application'
10
10
  machined.pages['index.html'].to_s.should == 'application'
11
11
  end
12
12
  end
13
-
13
+
14
14
  it 'returns the layout set in the front matter' do
15
15
  within_construct do |c|
16
16
  c.file 'pages/index.html.erb', "---\nlayout: main\n---\n<%= layout %>"
17
17
  c.file 'pages/about.html.erb', "---\nlayout: false\n---\n<%= layout %>"
18
-
18
+
19
19
  machined.pages['index.html'].to_s.should == 'main'
20
20
  machined.pages['about.html'].to_s.should == 'false'
21
21
  end
22
22
  end
23
23
  end
24
-
24
+
25
25
  describe '#title' do
26
26
  it 'returns a titleized version of the filename' do
27
27
  within_construct do |c|
28
28
  c.file 'pages/about-us.html.erb', '<%= title %>'
29
29
  c.file 'pages/about/our-team.html.erb', '<%= title %>'
30
-
30
+
31
31
  machined.pages['about-us'].to_s.should == 'About Us'
32
32
  machined.pages['about/our-team'].to_s.should == 'Our Team'
33
33
  end
34
34
  end
35
-
35
+
36
36
  it 'returns the local set in the front matter' do
37
37
  within_construct do |c|
38
38
  c.file 'pages/index.html.erb', "---\ntitle: Homepage\n---\n<%= title %>"
39
-
39
+
40
40
  machined.pages['index'].to_s.should == 'Homepage'
41
41
  end
42
42
  end
43
43
  end
44
-
44
+
45
45
  describe '#url' do
46
46
  it 'returns the URL for the current page or asset' do
47
47
  within_construct do |c|
@@ -50,7 +50,7 @@ describe Machined::Helpers::PageHelpers do
50
50
  c.file 'pages/index.html.erb', '<%= url %>'
51
51
  c.file 'pages/about.html.erb', '<%= url %>'
52
52
  c.file 'pages/about/team.html.erb', '<%= url %>'
53
-
53
+
54
54
  machined.assets['main.js'].to_s.should == "/assets/main.js;\n"
55
55
  machined.assets['main.css'].to_s.should == '/assets/main.css'
56
56
  machined.pages['index.html'].to_s.should == '/'
@@ -12,7 +12,7 @@ describe Machined::Helpers::RenderHelpers do
12
12
  c.file 'views/partial1.md', '# Hello World'
13
13
  c.file 'views/_partial2.haml', "%p Here's some Content..."
14
14
  c.file 'views/partials/_partial3.html', "<p>And some more</p>\n"
15
-
15
+
16
16
  machined.pages['index.html'].to_s.should == <<-CONTENT.unindent
17
17
  <h1>Hello World</h1>
18
18
  <p>Here's some Content...</p>
@@ -20,16 +20,16 @@ describe Machined::Helpers::RenderHelpers do
20
20
  CONTENT
21
21
  end
22
22
  end
23
-
23
+
24
24
  it 'renders partials with locals' do
25
25
  within_construct do |c|
26
26
  c.file 'pages/index.html.erb', %(<%= render 'partial', :text => 'Hello World' %>)
27
27
  c.file 'views/partial.haml', '%h1= text'
28
-
28
+
29
29
  machined.pages['index.html'].to_s.should == "<h1>Hello World</h1>\n"
30
30
  end
31
31
  end
32
-
32
+
33
33
  it 'returns the original locals state once rendered' do
34
34
  within_construct do |c|
35
35
  c.file 'pages/index.html.erb', <<-CONTENT.unindent
@@ -41,7 +41,7 @@ describe Machined::Helpers::RenderHelpers do
41
41
  text: <%= respond_to?(:text) %>
42
42
  CONTENT
43
43
  c.file 'views/partial.html.erb', "title: <%= title %>\ntext: <%= text %>\n"
44
-
44
+
45
45
  machined.pages['index.html'].to_s.should == <<-CONTENT.unindent
46
46
  title: Title...
47
47
  text: Text...
@@ -50,56 +50,56 @@ describe Machined::Helpers::RenderHelpers do
50
50
  CONTENT
51
51
  end
52
52
  end
53
-
53
+
54
54
  it 'renders partial collections' do
55
55
  within_construct do |c|
56
56
  c.file 'pages/index.html.erb', %(<%= render 'number', :collection => [1,2,3] %>)
57
57
  c.file 'views/number.haml', "= number\n= number_counter"
58
-
58
+
59
59
  machined.pages['index.html'].to_s.should == "1\n1\n2\n2\n3\n3\n"
60
60
  end
61
61
  end
62
-
62
+
63
63
  it 'does not wrap the partial in a layout' do
64
64
  within_construct do |c|
65
65
  c.file 'pages/index.html.erb', %(<%= render 'partial' %>)
66
66
  c.file 'views/layouts/application.html.erb', '<h1><%= yield %></h1>'
67
67
  c.file 'views/partial.html.erb', 'Hello World'
68
-
68
+
69
69
  machined.pages['index.html'].to_s.should == '<h1>Hello World</h1>'
70
70
  end
71
71
  end
72
-
72
+
73
73
  it 'optionally wraps the partial in a layout' do
74
74
  within_construct do |c|
75
75
  c.file 'pages/index.html.erb', %(<%= render 'partial', :layout => 'partial' %>)
76
76
  c.file 'views/layouts/partial.html.erb', '<h1><%= yield %></h1>'
77
77
  c.file 'views/partial.html.erb', 'Hello World'
78
-
78
+
79
79
  machined.pages['index.html'].to_s.should == '<h1>Hello World</h1>'
80
80
  end
81
81
  end
82
-
82
+
83
83
  it 'adds the partial as a dependency' do
84
84
  within_construct do |c|
85
85
  c.file 'pages/index.html.erb', %(<%= render 'partial' %>)
86
86
  dep = c.file 'views/partial.haml', 'Hello World'
87
-
87
+
88
88
  asset = machined.pages['index.html']
89
89
  asset.should be_fresh(machined.pages)
90
-
90
+
91
91
  dep.open('w') { |f| f.write('%h1 Hello World') }
92
92
  mtime = Time.now + 600
93
93
  dep.utime mtime, mtime
94
-
94
+
95
95
  asset.should_not be_fresh(machined.pages)
96
96
  end
97
97
  end
98
-
98
+
99
99
  it 'raises a Sprockets::FileNotFound error if the partial is missing' do
100
100
  within_construct do |c|
101
101
  c.file 'pages/index.html.erb', %(<%= render 'partial' %>)
102
-
102
+
103
103
  expect {
104
104
  machined.pages['index.html'].to_s
105
105
  }.to raise_error(Sprockets::FileNotFound)
@@ -5,11 +5,11 @@ describe Machined::Initializable do
5
5
  include Machined::Initializable
6
6
  attr_accessor :count
7
7
  end
8
-
8
+
9
9
  after(:each) do
10
10
  BasicInitializer.instance_variable_set :@initializers, nil
11
11
  end
12
-
12
+
13
13
  it 'runs initializers in order' do
14
14
  array = []
15
15
  BasicInitializer.initializer(:one) { array << 1 }
@@ -18,7 +18,7 @@ describe Machined::Initializable do
18
18
  BasicInitializer.new.run_initializers
19
19
  array.should == [ 1, 2, 3 ]
20
20
  end
21
-
21
+
22
22
  # it 'runs initializers only once' do
23
23
  # count = 0
24
24
  # BasicInitializer.initializer(:count) { count += 1 }
@@ -27,7 +27,7 @@ describe Machined::Initializable do
27
27
  # basic.run_initializers
28
28
  # count.should == 1
29
29
  # end
30
-
30
+
31
31
  it 'executes in the instance scope' do
32
32
  BasicInitializer.initializer(:init_count) { @count = 0 }
33
33
  BasicInitializer.initializer(:one) { @count += 1 }
@@ -36,14 +36,14 @@ describe Machined::Initializable do
36
36
  basic.run_initializers
37
37
  basic.count.should == 2
38
38
  end
39
-
39
+
40
40
  it 'runs the initializers with the given args' do
41
41
  BasicInitializer.initializer(:sum) { |*args| @count = args.inject(&:+) }
42
42
  basic = BasicInitializer.new
43
43
  basic.run_initializers 1, 2, 3
44
44
  basic.count.should == 6
45
45
  end
46
-
46
+
47
47
  it 'adds initializers after specific initializers' do
48
48
  array = []
49
49
  BasicInitializer.initializer(:one) { array << 1 }
@@ -52,7 +52,7 @@ describe Machined::Initializable do
52
52
  BasicInitializer.new.run_initializers
53
53
  array.should == [ 1, 3, 2 ]
54
54
  end
55
-
55
+
56
56
  it 'adds initializers before specific initializers' do
57
57
  array = []
58
58
  BasicInitializer.initializer(:one) { array << 1 }
@@ -61,12 +61,12 @@ describe Machined::Initializable do
61
61
  BasicInitializer.new.run_initializers
62
62
  array.should == [ 1, 3, 2 ]
63
63
  end
64
-
64
+
65
65
  it "raises an error if the specified initializer doesn't exist" do
66
66
  expect {
67
67
  BasicInitializer.initializer(:wtf, :after => :omg) { }
68
68
  }.to raise_error('The specified initializer, :omg, does not exist')
69
-
69
+
70
70
  expect {
71
71
  BasicInitializer.initializer(:omg, :before => :wtf) { }
72
72
  }.to raise_error('The specified initializer, :wtf, does not exist')
@@ -13,14 +13,14 @@ describe Machined::Processors::FrontMatterProcessor do
13
13
  = title.inspect
14
14
  = tags.inspect
15
15
  CONTENT
16
-
16
+
17
17
  machined.pages['index.html'].to_s.should == <<-CONTENT.unindent
18
18
  "Hello"
19
19
  [1, 2]
20
20
  CONTENT
21
21
  end
22
22
  end
23
-
23
+
24
24
  it 'ignores pages without front matter' do
25
25
  within_construct do |c|
26
26
  c.file 'pages/index.html.md', <<-CONTENT.unindent
@@ -32,9 +32,9 @@ describe Machined::Processors::FrontMatterProcessor do
32
32
  CONTENT
33
33
  machined.pages['index.html'].to_s.should == <<-CONTENT.unindent
34
34
  <h2>Title</h2>
35
-
35
+
36
36
  <h2>Another Title</h2>
37
-
37
+
38
38
  <p>Content...</p>
39
39
  CONTENT
40
40
  end
@@ -5,43 +5,43 @@ describe Machined::Processors::LayoutProcessor do
5
5
  within_construct do |c|
6
6
  c.file 'pages/index.html', '<h1>Hello World</h1>'
7
7
  c.file 'views/layouts/application.html.haml', '#layout= yield'
8
-
8
+
9
9
  machined.pages['index.html'].to_s.should == "<div id='layout'><h1>Hello World</h1></div>\n"
10
10
  end
11
11
  end
12
-
12
+
13
13
  it 'uses the default layout set in the configuration' do
14
14
  within_construct do |c|
15
15
  c.file 'pages/index.html', '<h1>Hello World</h1>'
16
16
  c.file 'views/layouts/main.html.haml', '#layout= yield'
17
-
17
+
18
18
  machined :layout => 'main'
19
19
  machined.pages['index.html'].to_s.should == "<div id='layout'><h1>Hello World</h1></div>\n"
20
20
  end
21
21
  end
22
-
22
+
23
23
  it 'does not wrap the content with a layout when layout is false' do
24
24
  within_construct do |c|
25
25
  c.file 'pages/index.html', '<h1>Hello World</h1>'
26
26
  c.file 'views/layouts/application.html.haml', '#layout= yield'
27
-
27
+
28
28
  machined :layout => false
29
29
  machined.pages['index.html'].to_s.should == '<h1>Hello World</h1>'
30
30
  end
31
31
  end
32
-
32
+
33
33
  it 'adds the layout file as a dependency' do
34
34
  within_construct do |c|
35
35
  c.file 'pages/index.html', '<h1>Hello World</h1>'
36
36
  dep = c.file 'views/layouts/application.html.haml', '= yield'
37
-
37
+
38
38
  asset = machined.pages['index.html']
39
39
  asset.should be_fresh(machined.pages)
40
-
40
+
41
41
  dep.open('w') { |f| f.write('#layout= yield') }
42
42
  mtime = Time.now + 600
43
43
  dep.utime mtime, mtime
44
-
44
+
45
45
  asset.should_not be_fresh(machined.pages)
46
46
  end
47
47
  end
@@ -6,7 +6,7 @@ describe Machined::Sprocket do
6
6
  sprocket = create_sprocket
7
7
  sprocket.machined.should be(machined)
8
8
  end
9
-
9
+
10
10
  it 'sets the root path' do
11
11
  sprocket = create_sprocket
12
12
  sprocket.root.should == Pathname.new('.').expand_path.to_s
@@ -14,7 +14,7 @@ describe Machined::Sprocket do
14
14
  sprocket.root.should == Pathname.new('spec/machined').expand_path.to_s
15
15
  end
16
16
  end
17
-
17
+
18
18
  describe '#context_class' do
19
19
  it 'subclasses Machined::Context' do
20
20
  sprocket = create_sprocket
@@ -22,7 +22,7 @@ describe Machined::Sprocket do
22
22
  sprocket.context_class.should < Machined::Context
23
23
  end
24
24
  end
25
-
25
+
26
26
  describe '#use_all_templates' do
27
27
  it 'registers available templates as engines' do
28
28
  sprocket = create_sprocket :assets => true
@@ -3,10 +3,10 @@ require 'spec_helper'
3
3
  describe Machined::StaticCompiler do
4
4
  it 'generates all of the static files' do
5
5
  within_construct do |c|
6
- c.file 'assets/javascripts/application.js', '//= require _dep'
7
- c.file 'assets/javascripts/_dep.js', 'var app = {};'
6
+ c.file 'assets/javascripts/application.js', '//= require _dep'
7
+ c.file 'assets/javascripts/_dep.js', 'var app = {};'
8
8
  c.file 'assets/stylesheets/application.css.scss', %(@import "dep";\nbody { color: $color; })
9
- c.file 'assets/stylesheets/_dep.scss', '$color: red;'
9
+ c.file 'assets/stylesheets/_dep.scss', '$color: red;'
10
10
  c.file 'assets/images/logo.jpg'
11
11
  c.file 'pages/index.html.md.erb', <<-CONTENT.unindent
12
12
  ---
@@ -42,6 +42,28 @@ describe Machined::StaticCompiler do
42
42
  end
43
43
  end
44
44
 
45
+ it 'generates the files into the correct output path' do
46
+ within_construct do |c|
47
+ c.file 'app/assets/javascripts/application.js', '//= require _dep'
48
+ c.file 'app/assets/javascripts/_dep.js', 'var app = {};'
49
+ c.file 'app/assets/stylesheets/application.css.scss', %(@import "dep";\nbody { color: $color; })
50
+ c.file 'app/assets/stylesheets/_dep.scss', '$color: red;'
51
+ c.file 'app/assets/images/logo.jpg'
52
+
53
+ machined(:root => 'app', :output_path => '../output/site').compile
54
+
55
+ File.read('output/site/assets/application.js').should == "var app = {};\n"
56
+ File.read('output/site/assets/application.css').should == "body {\n color: red; }\n"
57
+ File.exist?('output/site/assets/logo.jpg').should be_true
58
+ File.exist?('public/assets/application.js').should be_false
59
+ File.exist?('public/assets/application.js').should be_false
60
+ File.exist?('public/assets/logo.jpg').should be_false
61
+ File.exist?('output/site/application.js').should be_false
62
+ File.exist?('output/site/application.js').should be_false
63
+ File.exist?('output/site/logo.jpg').should be_false
64
+ end
65
+ end
66
+
45
67
  it 'generates digests when configured' do
46
68
  within_construct do |c|
47
69
  c.file '_/js/application.js', 'var app = {};'
@@ -10,18 +10,18 @@ describe Machined::Utils do
10
10
  available_templates['.haml'].should be(Tilt::HamlTemplate)
11
11
  end
12
12
  end
13
-
13
+
14
14
  describe '.existent_directories' do
15
15
  it 'returns directories that exist in the given path' do
16
16
  within_construct do |c|
17
17
  c.directory 'dir1'
18
18
  c.directory 'dir2'
19
19
  c.directory 'dir3'
20
-
20
+
21
21
  Machined::Utils.existent_directories(c).should match_paths(%w(dir1 dir2 dir3)).with_root(c)
22
22
  end
23
23
  end
24
-
24
+
25
25
  it 'returns an empty array when the path is not a directory' do
26
26
  within_construct do |c|
27
27
  Machined::Utils.existent_directories(c.join('blank')).should == []