frank 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +3 -25
- data/Gemfile.lock +30 -36
- data/README.md +16 -2
- data/Rakefile +1 -18
- data/frank.gemspec +33 -182
- data/lib/frank/base.rb +1 -2
- data/lib/frank/cli.rb +3 -4
- data/lib/frank/compile.rb +20 -0
- data/lib/frank/lorem.rb +2 -2
- data/lib/frank/publish.rb +7 -5
- data/lib/frank/settings.rb +2 -2
- data/lib/frank/template_helpers.rb +26 -0
- data/lib/frank/version.rb +3 -0
- data/lib/template/setup.rb +8 -1
- data/spec/base_spec.rb +1 -1
- data/spec/compile_spec.rb +117 -98
- data/spec/helper.rb +18 -0
- data/spec/publish_spec.rb +6 -6
- data/spec/render_spec.rb +16 -11
- data/spec/template/dynamic/content_for_erb.erb +3 -0
- data/spec/template/dynamic/content_for_haml.haml +2 -0
- data/spec/template/dynamic/lorem_test.haml +1 -1
- data/spec/template/dynamic/stylesheets/less.less +5 -0
- data/spec/template/layouts/default.haml +1 -0
- data/spec/template_helpers_spec.rb +18 -2
- metadata +138 -146
data/lib/frank/compile.rb
CHANGED
@@ -43,10 +43,30 @@ module Frank
|
|
43
43
|
static_folder = File.join(Frank.root, Frank.static_folder)
|
44
44
|
FileUtils.cp_r(File.join(static_folder, '/.'), Frank.export.path)
|
45
45
|
end
|
46
|
+
|
47
|
+
# ask the user if they want to overwrite the folder
|
48
|
+
# get the input and return it
|
49
|
+
def ask_nicely
|
50
|
+
print "\033[31mA folder named `#{Frank.export.path}' already exists, overwrite it?\033[0m [y/n] "
|
51
|
+
STDIN.gets.chomp.downcase
|
52
|
+
end
|
53
|
+
|
54
|
+
# verify that the user wants to overwrite the folder
|
55
|
+
# remove it if so, exit if not
|
56
|
+
def verify_overwriting
|
57
|
+
overwrite = ask_nicely
|
58
|
+
|
59
|
+
while overwrite.empty?
|
60
|
+
overwrite = ask_nicely
|
61
|
+
end
|
62
|
+
|
63
|
+
overwrite == 'y' ? FileUtils.rm_rf(Frank.export.path) : exit
|
64
|
+
end
|
46
65
|
|
47
66
|
# TODO verbose everywhere is lame
|
48
67
|
# create the dump dir, compile templates, copy over static assets
|
49
68
|
def export!
|
69
|
+
verify_overwriting if File.exist?(Frank.export.path)
|
50
70
|
FileUtils.mkdir(Frank.export.path)
|
51
71
|
|
52
72
|
unless Frank.silent_export?
|
data/lib/frank/lorem.rb
CHANGED
@@ -45,11 +45,11 @@ module Frank
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
def date(fmt = '%a %b %d, %Y', replacement = nil)
|
48
|
+
def date(fmt = '%a %b %d, %Y', range = 1950..2010, replacement = nil)
|
49
49
|
if Frank.exporting? && replacement
|
50
50
|
replacement
|
51
51
|
else
|
52
|
-
y = rand(
|
52
|
+
y = rand(range.last - range.first) + range.first
|
53
53
|
m = rand(12) + 1
|
54
54
|
d = rand(31) + 1
|
55
55
|
Time.local(y,m,d).strftime(fmt)
|
data/lib/frank/publish.rb
CHANGED
@@ -5,8 +5,10 @@ module Frank
|
|
5
5
|
def self.execute!
|
6
6
|
exit_unless_configured
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
unless Frank.silent_export?
|
9
|
+
puts "\nFrank is..."
|
10
|
+
puts " - \033[32mExporting templates\033[0m"
|
11
|
+
end
|
10
12
|
|
11
13
|
tmp_folder = "/tmp/frankexp-#{Frank.proj_name}"
|
12
14
|
|
@@ -18,7 +20,7 @@ module Frank
|
|
18
20
|
Frank.export.silent = true
|
19
21
|
Frank::Compile.export!
|
20
22
|
|
21
|
-
puts " - \033[32mPublishing to:\033[0m `#{Frank.publish.host}:#{Frank.publish.path}'"
|
23
|
+
puts " - \033[32mPublishing to:\033[0m `#{Frank.publish.host}:#{Frank.publish.path}'" unless Frank.silent_export?
|
22
24
|
|
23
25
|
ssh_options = {
|
24
26
|
:password => Frank.publish.password,
|
@@ -31,7 +33,7 @@ module Frank
|
|
31
33
|
Net::SSH.start(Frank.publish.host, Frank.publish.username, ssh_options) do |ssh|
|
32
34
|
ssh.scp.upload!("#{tmp_folder}/", Frank.publish.path, :recursive => true, :chunk_size => 2048) do |ch, name, sent, total|
|
33
35
|
|
34
|
-
puts " - #{name[tmp_folder.length..-1]}" unless name == current
|
36
|
+
puts " - #{name[tmp_folder.length..-1]}" unless name == current || Frank.silent_export?
|
35
37
|
|
36
38
|
current = name
|
37
39
|
end
|
@@ -40,7 +42,7 @@ module Frank
|
|
40
42
|
# cleanup by removing tmp folder
|
41
43
|
FileUtils.rm_rf(tmp_folder)
|
42
44
|
|
43
|
-
puts "\n\033[32mPublish complete!\033[0m"
|
45
|
+
puts "\n\033[32mPublish complete!\033[0m" unless Frank.silent_export?
|
44
46
|
end
|
45
47
|
|
46
48
|
def self.exit_unless_configured
|
data/lib/frank/settings.rb
CHANGED
@@ -14,6 +14,32 @@ module Frank
|
|
14
14
|
def lorem
|
15
15
|
Frank::Lorem.new
|
16
16
|
end
|
17
|
+
|
18
|
+
def content_for(name, &block)
|
19
|
+
@content_for ||= {}
|
20
|
+
|
21
|
+
if block_given?
|
22
|
+
@content_for[name.to_sym] = capture(&block)
|
23
|
+
else
|
24
|
+
@content_for[name.to_sym]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def content_for?(name)
|
29
|
+
!@content_for[name.to_sym].nil?
|
30
|
+
end
|
31
|
+
|
32
|
+
def capture(&block)
|
33
|
+
erbout = eval('_erbout', block.binding)
|
34
|
+
erbout_length = erbout.length
|
35
|
+
|
36
|
+
block.call
|
37
|
+
|
38
|
+
erbout_addition = erbout[erbout_length..-1]
|
39
|
+
erbout[erbout_length..-1] = ''
|
40
|
+
|
41
|
+
erbout_addition
|
42
|
+
end
|
17
43
|
|
18
44
|
def refresh
|
19
45
|
if Frank.exporting?
|
data/lib/template/setup.rb
CHANGED
@@ -42,6 +42,13 @@ Frank.dynamic_folder = "dynamic"
|
|
42
42
|
#
|
43
43
|
Frank.layouts_folder = "layouts"
|
44
44
|
|
45
|
+
# ----------------------
|
46
|
+
# Export settings:
|
47
|
+
#
|
48
|
+
# Projects will be exported to default to the following directory
|
49
|
+
#
|
50
|
+
Frank.export.path = "exported"
|
51
|
+
|
45
52
|
# ----------------------
|
46
53
|
# Publish settings:
|
47
54
|
#
|
@@ -67,4 +74,4 @@ Frank.layouts_folder = "layouts"
|
|
67
74
|
# Initializers:
|
68
75
|
#
|
69
76
|
# Add any other project setup code, or requires here
|
70
|
-
# ....
|
77
|
+
# ....
|
data/spec/base_spec.rb
CHANGED
data/spec/compile_spec.rb
CHANGED
@@ -2,139 +2,162 @@ require File.dirname(__FILE__) + '/helper'
|
|
2
2
|
|
3
3
|
describe Frank::Compile do
|
4
4
|
include Rack::Test::Methods
|
5
|
+
include Frank::Spec::Helpers
|
6
|
+
|
7
|
+
let(:proj_dir) { File.join(File.dirname(__FILE__), 'template') }
|
5
8
|
|
6
9
|
context 'default output' do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
Dir.chdir proj_dir do
|
12
|
-
system "#{bin_dir} #{output_dir} > /dev/null"
|
10
|
+
|
11
|
+
context 'without specifying an export dir' do
|
12
|
+
after do
|
13
|
+
FileUtils.rm_r File.join(proj_dir, Frank.export.path)
|
13
14
|
end
|
14
|
-
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
it 'creates the default export dir' do
|
17
|
+
Dir.chdir proj_dir do
|
18
|
+
frank 'export'
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
File.directory?(Frank.export.path).should be_true
|
21
|
+
end
|
22
|
+
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
File.read(output).should == "<div id='p'>/partial_test</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/partial_test</h2>\n <p>hello from partial</p>\n</div>\n"
|
28
|
-
end
|
25
|
+
context 'specifying an export dir' do
|
26
|
+
let(:output_dir) { File.join(proj_dir, 'output') }
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
before(:all) do
|
29
|
+
Dir.chdir proj_dir do
|
30
|
+
frank 'export', output_dir
|
31
|
+
end
|
32
|
+
end
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
34
|
+
after(:all) do
|
35
|
+
FileUtils.rm_r output_dir
|
36
|
+
end
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
38
|
+
it 'creates the output folder' do
|
39
|
+
File.exist?(File.join(File.dirname(__FILE__), 'template/output')).should be_true
|
40
|
+
end
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
42
|
+
it 'creates index.html' do
|
43
|
+
output = File.join(File.dirname(__FILE__), 'template/output/index.html')
|
44
|
+
File.read(output).should == "\n<div id='p'>/</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/</h2>\n</div>\n"
|
45
|
+
end
|
49
46
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
47
|
+
it 'creates partial_test.html' do
|
48
|
+
output = File.join(File.dirname(__FILE__), 'template/output/partial_test.html')
|
49
|
+
File.read(output).should == "\n<div id='p'>/partial_test</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/partial_test</h2>\n <p>hello from partial</p>\n</div>\n"
|
50
|
+
end
|
54
51
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
52
|
+
it 'creates partial_locals_test.html' do
|
53
|
+
output = File.join(File.dirname(__FILE__), 'template/output/partial_locals_test.html')
|
54
|
+
File.read(output).should == "\n<div id='p'>/partial_locals_test</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/partial_locals_test</h2>\n <p>hello from local</p>\n</div>\n"
|
55
|
+
end
|
59
56
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
57
|
+
it 'creates child.html' do
|
58
|
+
output = File.join(File.dirname(__FILE__), 'template/output/nested/child.html')
|
59
|
+
File.read(output).should == "<div id='nested_layout'>\n <h1>hello from child</h1>\n</div>\n"
|
60
|
+
end
|
64
61
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
62
|
+
it 'creates deep.html' do
|
63
|
+
output = File.join(File.dirname(__FILE__), 'template/output/nested/deeper/deep.html')
|
64
|
+
File.read(output).should == "<div id='nested_layout'>\n <h1>really deep</h1>\n</div>\n"
|
65
|
+
end
|
69
66
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
67
|
+
it 'creates no_layout.html' do
|
68
|
+
output = File.join(File.dirname(__FILE__), 'template/output/no_layout.html')
|
69
|
+
File.read(output).should == "<h1>i have no layout</h1>\n"
|
70
|
+
end
|
74
71
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
72
|
+
it 'creates coffee.js' do
|
73
|
+
output = File.join(File.dirname(__FILE__), 'template/output/coffee.js')
|
74
|
+
File.read(output).should == "(function() {\n ({\n greeting: \"Hello CoffeeScript\"\n });\n}).call(this);\n"
|
75
|
+
end
|
79
76
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
77
|
+
it 'creates erb.html' do
|
78
|
+
output = File.join(File.dirname(__FILE__), 'template/output/erb.html')
|
79
|
+
File.read(output).should == "\n<div id='p'>/erb</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
|
80
|
+
end
|
84
81
|
|
85
|
-
|
86
|
-
|
87
|
-
|
82
|
+
it 'creates redcloth.html' do
|
83
|
+
output = File.join(File.dirname(__FILE__), 'template/output/redcloth.html')
|
84
|
+
File.read(output).should == "\n<div id='p'>/redcloth</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
|
85
|
+
end
|
88
86
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
File.read(output).should include("<p class='paragraphs'>replace-this</p>")
|
94
|
-
File.read(output).should include("<p class='date'>replace-this</p>")
|
95
|
-
File.read(output).should include("<p class='name'>replace-this</p>")
|
96
|
-
File.read(output).should include("<p class='email'>replace-this</p>")
|
97
|
-
File.read(output).should include("<img src='replace-this' />")
|
98
|
-
end
|
87
|
+
it 'creates markdown.html' do
|
88
|
+
output = File.join(File.dirname(__FILE__), 'template/output/markdown.html')
|
89
|
+
File.read(output).should == "\n<div id='p'>/markdown</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
|
90
|
+
end
|
99
91
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
92
|
+
it 'creates liquid.html' do
|
93
|
+
output = File.join(File.dirname(__FILE__), 'template/output/liquid.html')
|
94
|
+
File.read(output).should == "\n<div id='p'>/liquid</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
|
95
|
+
end
|
104
96
|
|
105
|
-
|
106
|
-
|
97
|
+
it 'creates builder.html' do
|
98
|
+
output = File.join(File.dirname(__FILE__), 'template/output/builder.html')
|
99
|
+
File.read(output).should == "\n<div id='p'>/builder</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'copies static.html' do
|
103
|
+
output = File.join(File.dirname(__FILE__), 'template/output/files/static.html')
|
104
|
+
File.read(output).should == "hello from static"
|
105
|
+
end
|
106
|
+
|
107
|
+
it "doesn't create partials" do
|
108
|
+
File.exist?(File.join(File.dirname(__FILE__), 'template/output/_partial.html')).should be_false
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'handles lorem replacement fields' do
|
112
|
+
output = File.join(File.dirname(__FILE__), 'template/output/lorem_test.html')
|
113
|
+
File.read(output).should include("<p class='words'>replace-this</p>")
|
114
|
+
File.read(output).should include("<p class='sentences'>replace-this</p>")
|
115
|
+
File.read(output).should include("<p class='paragraphs'>replace-this</p>")
|
116
|
+
File.read(output).should include("<p class='date'>replace-this</p>")
|
117
|
+
File.read(output).should include("<p class='name'>replace-this</p>")
|
118
|
+
File.read(output).should include("<p class='email'>replace-this</p>")
|
119
|
+
File.read(output).should include("<img src='replace-this' />")
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should not render the refresh js' do
|
123
|
+
output = File.join(File.dirname(__FILE__), 'template/output/refresh.html')
|
124
|
+
File.read(output).should == "\n<div id='p'>/refresh</div>\n<div id='layout'>\n \n</div>\n"
|
125
|
+
end
|
107
126
|
end
|
108
127
|
|
109
128
|
end
|
110
129
|
|
111
130
|
context 'productions output' do
|
131
|
+
|
132
|
+
let(:output_dir) { File.join(proj_dir, 'output') }
|
133
|
+
|
112
134
|
before :all do
|
113
|
-
bin_dir = File.join(File.dirname(File.dirname(__FILE__)), 'bin', 'frank export')
|
114
|
-
proj_dir = File.join(File.dirname(__FILE__), 'template')
|
115
|
-
output_dir = File.join(proj_dir, 'output')
|
116
135
|
Dir.chdir proj_dir do
|
117
|
-
|
136
|
+
frank 'export', output_dir, '--production'
|
118
137
|
end
|
119
138
|
end
|
120
139
|
|
140
|
+
after(:all) do
|
141
|
+
FileUtils.rm_r output_dir
|
142
|
+
end
|
143
|
+
|
121
144
|
it 'creates the output folder' do
|
122
145
|
File.exist?(File.join(File.dirname(__FILE__), 'template/output')).should be_true
|
123
146
|
end
|
124
147
|
|
125
148
|
it 'creates index.html' do
|
126
149
|
output = File.join(File.dirname(__FILE__), 'template/output/index.html')
|
127
|
-
File.read(output).should == "<div id='p'>/</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/</h2>\n</div>\n"
|
150
|
+
File.read(output).should == "\n<div id='p'>/</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/</h2>\n</div>\n"
|
128
151
|
end
|
129
152
|
|
130
153
|
it 'creates partial_test.html' do
|
131
154
|
output = File.join(File.dirname(__FILE__), 'template/output/partial_test/index.html')
|
132
|
-
File.read(output).should == "<div id='p'>/partial_test</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/partial_test</h2>\n <p>hello from partial</p>\n</div>\n"
|
155
|
+
File.read(output).should == "\n<div id='p'>/partial_test</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/partial_test</h2>\n <p>hello from partial</p>\n</div>\n"
|
133
156
|
end
|
134
157
|
|
135
158
|
it 'creates partial_locals_test.html' do
|
136
159
|
output = File.join(File.dirname(__FILE__), 'template/output/partial_locals_test/index.html')
|
137
|
-
File.read(output).should == "<div id='p'>/partial_locals_test</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/partial_locals_test</h2>\n <p>hello from local</p>\n</div>\n"
|
160
|
+
File.read(output).should == "\n<div id='p'>/partial_locals_test</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/partial_locals_test</h2>\n <p>hello from local</p>\n</div>\n"
|
138
161
|
end
|
139
162
|
|
140
163
|
it 'creates child.html' do
|
@@ -154,32 +177,32 @@ describe Frank::Compile do
|
|
154
177
|
|
155
178
|
it 'creates coffee.js' do
|
156
179
|
output = File.join(File.dirname(__FILE__), 'template/output/coffee.js')
|
157
|
-
File.read(output).should == "(function(){\n
|
180
|
+
File.read(output).should == "(function() {\n ({\n greeting: \"Hello CoffeeScript\"\n });\n}).call(this);\n"
|
158
181
|
end
|
159
182
|
|
160
183
|
it 'creates erb.html' do
|
161
184
|
output = File.join(File.dirname(__FILE__), 'template/output/erb/index.html')
|
162
|
-
File.read(output).should == "<div id='p'>/erb</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
|
185
|
+
File.read(output).should == "\n<div id='p'>/erb</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
|
163
186
|
end
|
164
187
|
|
165
188
|
it 'creates redcloth.html' do
|
166
189
|
output = File.join(File.dirname(__FILE__), 'template/output/redcloth/index.html')
|
167
|
-
File.read(output).should == "<div id='p'>/redcloth</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
|
190
|
+
File.read(output).should == "\n<div id='p'>/redcloth</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
|
168
191
|
end
|
169
192
|
|
170
193
|
it 'creates markdown.html' do
|
171
194
|
output = File.join(File.dirname(__FILE__), 'template/output/markdown/index.html')
|
172
|
-
File.read(output).should == "<div id='p'>/markdown</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
|
195
|
+
File.read(output).should == "\n<div id='p'>/markdown</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
|
173
196
|
end
|
174
197
|
|
175
198
|
it 'creates liquid.html' do
|
176
199
|
output = File.join(File.dirname(__FILE__), 'template/output/liquid/index.html')
|
177
|
-
File.read(output).should == "<div id='p'>/liquid</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
|
200
|
+
File.read(output).should == "\n<div id='p'>/liquid</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
|
178
201
|
end
|
179
202
|
|
180
203
|
it 'creates builder.html' do
|
181
204
|
output = File.join(File.dirname(__FILE__), 'template/output/builder/index.html')
|
182
|
-
File.read(output).should == "<div id='p'>/builder</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
|
205
|
+
File.read(output).should == "\n<div id='p'>/builder</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
|
183
206
|
end
|
184
207
|
|
185
208
|
it 'copies static.html' do
|
@@ -204,11 +227,7 @@ describe Frank::Compile do
|
|
204
227
|
|
205
228
|
it 'should not render the refresh js' do
|
206
229
|
output = File.join(File.dirname(__FILE__), 'template/output/refresh/index.html')
|
207
|
-
File.read(output).should == "<div id='p'>/refresh</div>\n<div id='layout'>\n \n</div>\n"
|
208
|
-
end
|
209
|
-
|
210
|
-
after(:all) do
|
211
|
-
FileUtils.rm_r File.join(File.dirname(__FILE__), 'template/output')
|
230
|
+
File.read(output).should == "\n<div id='p'>/refresh</div>\n<div id='layout'>\n \n</div>\n"
|
212
231
|
end
|
213
232
|
|
214
233
|
end
|