machined 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +2 -2
- data/bin/machined +3 -3
- data/lib/machined.rb +17 -17
- data/lib/machined/cli.rb +35 -35
- data/lib/machined/context.rb +4 -4
- data/lib/machined/environment.rb +57 -31
- data/lib/machined/helpers/asset_tag_helpers.rb +4 -4
- data/lib/machined/helpers/locals_helpers.rb +1 -1
- data/lib/machined/helpers/output_helpers.rb +15 -15
- data/lib/machined/helpers/page_helpers.rb +1 -1
- data/lib/machined/helpers/render_helpers.rb +16 -16
- data/lib/machined/index.rb +1 -1
- data/lib/machined/initializable.rb +9 -11
- data/lib/machined/processors/front_matter_processor.rb +2 -2
- data/lib/machined/processors/layout_processor.rb +1 -1
- data/lib/machined/server.rb +2 -2
- data/lib/machined/sprocket.rb +4 -4
- data/lib/machined/static_compiler.rb +2 -2
- data/lib/machined/templates/site/Gemfile.tt +4 -4
- data/lib/machined/templates/site/config.ru +1 -1
- data/lib/machined/templates/site/machined.rb +2 -2
- data/lib/machined/templates/site/views/layouts/application.html.erb +2 -2
- data/lib/machined/utils.rb +3 -3
- data/lib/machined/version.rb +1 -1
- data/machined.gemspec +29 -31
- data/spec/machined/cli_spec.rb +56 -56
- data/spec/machined/context_spec.rb +6 -6
- data/spec/machined/environment_spec.rb +94 -94
- data/spec/machined/helpers/asset_tag_helpers_spec.rb +42 -42
- data/spec/machined/helpers/locals_helper_spec.rb +17 -17
- data/spec/machined/helpers/output_helpers_spec.rb +27 -27
- data/spec/machined/helpers/page_helpers_spec.rb +32 -32
- data/spec/machined/helpers/render_helpers_spec.rb +42 -42
- data/spec/machined/initializable_spec.rb +9 -9
- data/spec/machined/processors/front_matter_processor_spec.rb +7 -7
- data/spec/machined/processors/layout_processor_spec.rb +19 -19
- data/spec/machined/server_spec.rb +36 -36
- data/spec/machined/sprocket_spec.rb +15 -15
- data/spec/machined/utils_spec.rb +14 -14
- data/spec/spec_helper.rb +7 -7
- data/spec/support/be_fresh_matcher.rb +2 -2
- data/spec/support/helpers.rb +6 -6
- metadata +177 -301
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Machined::Helpers::LocalsHelpers do
|
4
|
-
describe
|
5
|
-
it
|
6
|
-
context.locals = { :text =>
|
7
|
-
context.text.should ==
|
4
|
+
describe '#locals=' do
|
5
|
+
it 'sets psuedo local variables' do
|
6
|
+
context.locals = { :text => 'Hello World', :body => nil }
|
7
|
+
context.text.should == 'Hello World'
|
8
8
|
context.body.should be_nil
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
12
|
-
context.locals = { :text =>
|
11
|
+
it 'responds_to the local variable name' do
|
12
|
+
context.locals = { :text => 'Hello World', :body => nil }
|
13
13
|
context.respond_to?(:text).should be_true
|
14
14
|
context.respond_to?(:body).should be_true
|
15
15
|
end
|
@@ -19,24 +19,24 @@ describe Machined::Helpers::LocalsHelpers do
|
|
19
19
|
context.respond_to?(:not_a_local).should be_false
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
23
|
-
context.locals = { :text =>
|
22
|
+
it 'clears local variables when set to nil' do
|
23
|
+
context.locals = { :text => 'Hello World' }
|
24
24
|
context.locals = nil
|
25
25
|
expect { context.text }.to raise_error(NoMethodError)
|
26
26
|
context.respond_to?(:text).should be_false
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
describe
|
31
|
-
it
|
32
|
-
context.locals = { :text =>
|
33
|
-
context.with_locals(:layout => false, :body =>
|
34
|
-
context.text.should ==
|
35
|
-
context.body.should ==
|
30
|
+
describe '#with_locals' do
|
31
|
+
it 'temporarily changes the local variables' do
|
32
|
+
context.locals = { :text => 'Hello World', :layout => 'main' }
|
33
|
+
context.with_locals(:layout => false, :body => '...') do
|
34
|
+
context.text.should == 'Hello World'
|
35
|
+
context.body.should == '...'
|
36
36
|
context.layout.should be_false
|
37
37
|
end
|
38
|
-
context.text.should ==
|
39
|
-
context.layout.should ==
|
38
|
+
context.text.should == 'Hello World'
|
39
|
+
context.layout.should == 'main'
|
40
40
|
context.respond_to?(:body).should be_false
|
41
41
|
end
|
42
42
|
end
|
@@ -1,80 +1,80 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Machined::Helpers::OutputHelpers do
|
4
|
-
describe
|
5
|
-
it
|
4
|
+
describe '#current_engine' do
|
5
|
+
it 'returns :haml within a Haml template' do
|
6
6
|
within_construct do |c|
|
7
|
-
c.file
|
8
|
-
machined.pages[
|
7
|
+
c.file 'pages/index.haml', '= current_engine.inspect'
|
8
|
+
machined.pages['index'].to_s.should == ":haml\n"
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it 'returns :erb within an ERB template' do
|
13
13
|
within_construct do |c|
|
14
|
-
c.file
|
15
|
-
machined.pages[
|
14
|
+
c.file 'pages/index.erb', '<%= current_engine.inspect %>'
|
15
|
+
machined.pages['index'].to_s.should == ':erb'
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'returns :erubis within an Erubis template' do
|
20
20
|
within_construct do |c|
|
21
|
-
c.file
|
22
|
-
machined.pages[
|
21
|
+
c.file 'pages/index.erubis', '<%= current_engine.inspect %>'
|
22
|
+
machined.pages['index'].to_s.should == ':erubis'
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it 'returns :slim within a Slim template' do
|
27
27
|
within_construct do |c|
|
28
|
-
c.file
|
29
|
-
machined.pages[
|
28
|
+
c.file 'pages/index.slim', '= current_engine.inspect'
|
29
|
+
machined.pages['index'].to_s.should == ':slim'
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe
|
35
|
-
it
|
34
|
+
describe '#capture and #concat' do
|
35
|
+
it 'captures blocks in haml' do
|
36
36
|
within_construct do |c|
|
37
|
-
c.file
|
37
|
+
c.file 'pages/index.haml', <<-CONTENT.unindent
|
38
38
|
- content_tag :h1 do
|
39
39
|
Hello World
|
40
40
|
CONTENT
|
41
41
|
|
42
|
-
machined.pages[
|
42
|
+
machined.pages['index'].to_s.strip.should == "<h1>Hello World\n</h1>"
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
it
|
46
|
+
it 'captures blocks in erb' do
|
47
47
|
within_construct do |c|
|
48
|
-
c.file
|
48
|
+
c.file 'pages/index.erb', <<-CONTENT.unindent
|
49
49
|
<% content_tag :h1 do %>
|
50
50
|
Hello World
|
51
51
|
<% end %>
|
52
52
|
CONTENT
|
53
53
|
|
54
|
-
machined.pages[
|
54
|
+
machined.pages['index'].to_s.strip.should == "<h1> Hello World\n</h1>"
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
it
|
58
|
+
it 'captures blocks in erubis' do
|
59
59
|
within_construct do |c|
|
60
|
-
c.file
|
60
|
+
c.file 'pages/index.erubis', <<-CONTENT.unindent
|
61
61
|
<% content_tag :h1 do %>
|
62
62
|
Hello World
|
63
63
|
<% end %>
|
64
64
|
CONTENT
|
65
65
|
|
66
|
-
machined.pages[
|
66
|
+
machined.pages['index'].to_s.strip.should == "<h1> Hello World\n</h1>"
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
it
|
70
|
+
it 'captures blocks in slim' do
|
71
71
|
within_construct do |c|
|
72
|
-
c.file
|
72
|
+
c.file 'pages/index.slim', <<-CONTENT.unindent
|
73
73
|
- content_tag :h1 do
|
74
74
|
| Hello World
|
75
75
|
CONTENT
|
76
76
|
|
77
|
-
machined.pages[
|
77
|
+
machined.pages['index'].to_s.strip.should == '<h1>Hello World</h1>'
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
@@ -1,61 +1,61 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Machined::Helpers::PageHelpers do
|
4
|
-
describe
|
5
|
-
it
|
4
|
+
describe '#layout' do
|
5
|
+
it 'defaults to the default layout' do
|
6
6
|
within_construct do |c|
|
7
|
-
c.file
|
7
|
+
c.file 'pages/index.html.erb', '<%= layout %>'
|
8
8
|
|
9
|
-
machined :layout =>
|
10
|
-
machined.pages[
|
9
|
+
machined :layout => 'application'
|
10
|
+
machined.pages['index.html'].to_s.should == 'application'
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it 'returns the layout set in the front matter' do
|
15
15
|
within_construct do |c|
|
16
|
-
c.file
|
17
|
-
c.file
|
16
|
+
c.file 'pages/index.html.erb', "---\nlayout: main\n---\n<%= layout %>"
|
17
|
+
c.file 'pages/about.html.erb', "---\nlayout: false\n---\n<%= layout %>"
|
18
18
|
|
19
|
-
machined.pages[
|
20
|
-
machined.pages[
|
19
|
+
machined.pages['index.html'].to_s.should == 'main'
|
20
|
+
machined.pages['about.html'].to_s.should == 'false'
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
describe
|
26
|
-
it
|
25
|
+
describe '#title' do
|
26
|
+
it 'returns a titleized version of the filename' do
|
27
27
|
within_construct do |c|
|
28
|
-
c.file
|
29
|
-
c.file
|
28
|
+
c.file 'pages/about-us.html.erb', '<%= title %>'
|
29
|
+
c.file 'pages/about/our-team.html.erb', '<%= title %>'
|
30
30
|
|
31
|
-
machined.pages[
|
32
|
-
machined.pages[
|
31
|
+
machined.pages['about-us'].to_s.should == 'About Us'
|
32
|
+
machined.pages['about/our-team'].to_s.should == 'Our Team'
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
36
|
+
it 'returns the local set in the front matter' do
|
37
37
|
within_construct do |c|
|
38
|
-
c.file
|
38
|
+
c.file 'pages/index.html.erb', "---\ntitle: Homepage\n---\n<%= title %>"
|
39
39
|
|
40
|
-
machined.pages[
|
40
|
+
machined.pages['index'].to_s.should == 'Homepage'
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
describe
|
46
|
-
it
|
45
|
+
describe '#url' do
|
46
|
+
it 'returns the URL for the current page or asset' do
|
47
47
|
within_construct do |c|
|
48
|
-
c.file
|
49
|
-
c.file
|
50
|
-
c.file
|
51
|
-
c.file
|
52
|
-
c.file
|
48
|
+
c.file 'assets/javascripts/main.js.erb', '<%= url %>'
|
49
|
+
c.file 'assets/stylesheets/main.css.erb', '<%= url %>'
|
50
|
+
c.file 'pages/index.html.erb', '<%= url %>'
|
51
|
+
c.file 'pages/about.html.erb', '<%= url %>'
|
52
|
+
c.file 'pages/about/team.html.erb', '<%= url %>'
|
53
53
|
|
54
|
-
machined.assets[
|
55
|
-
machined.assets[
|
56
|
-
machined.pages[
|
57
|
-
machined.pages[
|
58
|
-
machined.pages[
|
54
|
+
machined.assets['main.js'].to_s.should == "/assets/main.js;\n"
|
55
|
+
machined.assets['main.css'].to_s.should == '/assets/main.css'
|
56
|
+
machined.pages['index.html'].to_s.should == '/'
|
57
|
+
machined.pages['about.html'].to_s.should == '/about'
|
58
|
+
machined.pages['about/team.html'].to_s.should == '/about/team'
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Machined::Helpers::RenderHelpers do
|
4
|
-
describe
|
5
|
-
it
|
4
|
+
describe '#render' do
|
5
|
+
it 'renders partials' do
|
6
6
|
within_construct do |c|
|
7
|
-
c.file
|
8
|
-
<%= render
|
9
|
-
<%= render
|
10
|
-
<%= render
|
7
|
+
c.file 'pages/index.html.erb', <<-CONTENT.unindent
|
8
|
+
<%= render 'partial1' %>
|
9
|
+
<%= render 'partial2' %>
|
10
|
+
<%= render 'partials/partial3' %>
|
11
11
|
CONTENT
|
12
|
-
c.file
|
13
|
-
c.file
|
14
|
-
c.file
|
12
|
+
c.file 'views/partial1.md', '# Hello World'
|
13
|
+
c.file 'views/_partial2.haml', "%p Here's some Content..."
|
14
|
+
c.file 'views/partials/_partial3.html', "<p>And some more</p>\n"
|
15
15
|
|
16
|
-
machined.pages[
|
16
|
+
machined.pages['index.html'].to_s.should == <<-CONTENT.unindent
|
17
17
|
<h1>Hello World</h1>
|
18
18
|
<p>Here's some Content...</p>
|
19
19
|
<p>And some more</p>
|
@@ -21,28 +21,28 @@ describe Machined::Helpers::RenderHelpers do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it 'renders partials with locals' do
|
25
25
|
within_construct do |c|
|
26
|
-
c.file
|
27
|
-
c.file
|
26
|
+
c.file 'pages/index.html.erb', %(<%= render 'partial', :text => 'Hello World' %>)
|
27
|
+
c.file 'views/partial.haml', '%h1= text'
|
28
28
|
|
29
|
-
machined.pages[
|
29
|
+
machined.pages['index.html'].to_s.should == "<h1>Hello World</h1>\n"
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
it
|
33
|
+
it 'returns the original locals state once rendered' do
|
34
34
|
within_construct do |c|
|
35
|
-
c.file
|
35
|
+
c.file 'pages/index.html.erb', <<-CONTENT.unindent
|
36
36
|
---
|
37
37
|
title: Hello World
|
38
38
|
---
|
39
|
-
<%= render
|
39
|
+
<%= render 'partial', :title => 'Title...', :text => 'Text...' %>
|
40
40
|
title: <%= title %>
|
41
41
|
text: <%= respond_to?(:text) %>
|
42
42
|
CONTENT
|
43
|
-
c.file
|
43
|
+
c.file 'views/partial.html.erb', "title: <%= title %>\ntext: <%= text %>\n"
|
44
44
|
|
45
|
-
machined.pages[
|
45
|
+
machined.pages['index.html'].to_s.should == <<-CONTENT.unindent
|
46
46
|
title: Title...
|
47
47
|
text: Text...
|
48
48
|
title: Hello World
|
@@ -51,44 +51,44 @@ describe Machined::Helpers::RenderHelpers do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
it
|
54
|
+
it 'renders partial collections' do
|
55
55
|
within_construct do |c|
|
56
|
-
c.file
|
57
|
-
c.file
|
56
|
+
c.file 'pages/index.html.erb', %(<%= render 'number', :collection => [1,2,3] %>)
|
57
|
+
c.file 'views/number.haml', "= number\n= number_counter"
|
58
58
|
|
59
|
-
machined.pages[
|
59
|
+
machined.pages['index.html'].to_s.should == "1\n1\n2\n2\n3\n3\n"
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
it
|
63
|
+
it 'does not wrap the partial in a layout' do
|
64
64
|
within_construct do |c|
|
65
|
-
c.file
|
66
|
-
c.file
|
67
|
-
c.file
|
65
|
+
c.file 'pages/index.html.erb', %(<%= render 'partial' %>)
|
66
|
+
c.file 'views/layouts/application.html.erb', '<h1><%= yield %></h1>'
|
67
|
+
c.file 'views/partial.html.erb', 'Hello World'
|
68
68
|
|
69
|
-
machined.pages[
|
69
|
+
machined.pages['index.html'].to_s.should == '<h1>Hello World</h1>'
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
it
|
73
|
+
it 'optionally wraps the partial in a layout' do
|
74
74
|
within_construct do |c|
|
75
|
-
c.file
|
76
|
-
c.file
|
77
|
-
c.file
|
75
|
+
c.file 'pages/index.html.erb', %(<%= render 'partial', :layout => 'partial' %>)
|
76
|
+
c.file 'views/layouts/partial.html.erb', '<h1><%= yield %></h1>'
|
77
|
+
c.file 'views/partial.html.erb', 'Hello World'
|
78
78
|
|
79
|
-
machined.pages[
|
79
|
+
machined.pages['index.html'].to_s.should == '<h1>Hello World</h1>'
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
it
|
83
|
+
it 'adds the partial as a dependency' do
|
84
84
|
within_construct do |c|
|
85
|
-
c.file
|
86
|
-
dep = c.file
|
85
|
+
c.file 'pages/index.html.erb', %(<%= render 'partial' %>)
|
86
|
+
dep = c.file 'views/partial.haml', 'Hello World'
|
87
87
|
|
88
|
-
asset = machined.pages[
|
88
|
+
asset = machined.pages['index.html']
|
89
89
|
asset.should be_fresh(machined.pages)
|
90
90
|
|
91
|
-
dep.open(
|
91
|
+
dep.open('w') { |f| f.write('%h1 Hello World') }
|
92
92
|
mtime = Time.now + 600
|
93
93
|
dep.utime mtime, mtime
|
94
94
|
|
@@ -96,12 +96,12 @@ describe Machined::Helpers::RenderHelpers do
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
it
|
99
|
+
it 'raises a Sprockets::FileNotFound error if the partial is missing' do
|
100
100
|
within_construct do |c|
|
101
|
-
c.file
|
101
|
+
c.file 'pages/index.html.erb', %(<%= render 'partial' %>)
|
102
102
|
|
103
103
|
expect {
|
104
|
-
machined.pages[
|
104
|
+
machined.pages['index.html'].to_s
|
105
105
|
}.to raise_error(Sprockets::FileNotFound)
|
106
106
|
end
|
107
107
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Machined::Initializable do
|
4
4
|
class BasicInitializer
|
@@ -10,7 +10,7 @@ describe Machined::Initializable do
|
|
10
10
|
BasicInitializer.instance_variable_set :@initializers, nil
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'runs initializers in order' do
|
14
14
|
array = []
|
15
15
|
BasicInitializer.initializer(:one) { array << 1 }
|
16
16
|
BasicInitializer.initializer(:two) { array << 2 }
|
@@ -19,7 +19,7 @@ describe Machined::Initializable do
|
|
19
19
|
array.should == [ 1, 2, 3 ]
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'runs initializers only once' do
|
23
23
|
count = 0
|
24
24
|
BasicInitializer.initializer(:count) { count += 1 }
|
25
25
|
basic = BasicInitializer.new
|
@@ -28,7 +28,7 @@ describe Machined::Initializable do
|
|
28
28
|
count.should == 1
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
31
|
+
it 'executes in the instance scope' do
|
32
32
|
BasicInitializer.initializer(:init_count) { @count = 0 }
|
33
33
|
BasicInitializer.initializer(:one) { @count += 1 }
|
34
34
|
BasicInitializer.initializer(:two) { @count += 1 }
|
@@ -37,14 +37,14 @@ describe Machined::Initializable do
|
|
37
37
|
basic.count.should == 2
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
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
|
-
it
|
47
|
+
it 'adds initializers after specific initializers' do
|
48
48
|
array = []
|
49
49
|
BasicInitializer.initializer(:one) { array << 1 }
|
50
50
|
BasicInitializer.initializer(:two) { array << 2 }
|
@@ -53,7 +53,7 @@ describe Machined::Initializable do
|
|
53
53
|
array.should == [ 1, 3, 2 ]
|
54
54
|
end
|
55
55
|
|
56
|
-
it
|
56
|
+
it 'adds initializers before specific initializers' do
|
57
57
|
array = []
|
58
58
|
BasicInitializer.initializer(:one) { array << 1 }
|
59
59
|
BasicInitializer.initializer(:two) { array << 2 }
|
@@ -65,10 +65,10 @@ describe Machined::Initializable do
|
|
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
|
-
}.to raise_error(
|
68
|
+
}.to raise_error('The specified initializer, :omg, does not exist')
|
69
69
|
|
70
70
|
expect {
|
71
71
|
BasicInitializer.initializer(:omg, :before => :wtf) { }
|
72
|
-
}.to raise_error(
|
72
|
+
}.to raise_error('The specified initializer, :wtf, does not exist')
|
73
73
|
end
|
74
74
|
end
|