frank 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -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?
@@ -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(20) + 1990
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)
@@ -5,8 +5,10 @@ module Frank
5
5
  def self.execute!
6
6
  exit_unless_configured
7
7
 
8
- puts "\nFrank is..."
9
- puts " - \033[32mExporting templates\033[0m"
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
@@ -34,7 +34,7 @@ module Frank
34
34
 
35
35
  # export settings
36
36
  @export = OpenStruct.new
37
- @export.path = nil
37
+ @export.path = "exported"
38
38
  @export.silent = false
39
39
 
40
40
  # publish options
@@ -101,4 +101,4 @@ module Frank
101
101
  end
102
102
 
103
103
  end
104
- end
104
+ end
@@ -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?
@@ -0,0 +1,3 @@
1
+ module Frank
2
+ VERSION = '1.0.9'
3
+ end
@@ -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
+ # ....
@@ -76,4 +76,4 @@ describe Frank::Base do
76
76
  FileUtils.rm_r File.join(Dir.pwd, 'stubbed')
77
77
  end
78
78
 
79
- end
79
+ end
@@ -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
- before :all do
8
- bin_dir = File.join(File.dirname(File.dirname(__FILE__)), 'bin', 'frank export')
9
- proj_dir = File.join(File.dirname(__FILE__), 'template')
10
- output_dir = File.join(proj_dir, 'output')
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
- it 'creates the output folder' do
17
- File.exist?(File.join(File.dirname(__FILE__), 'template/output')).should be_true
18
- end
16
+ it 'creates the default export dir' do
17
+ Dir.chdir proj_dir do
18
+ frank 'export'
19
19
 
20
- it 'creates index.html' do
21
- output = File.join(File.dirname(__FILE__), 'template/output/index.html')
22
- File.read(output).should == "<div id='p'>/</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/</h2>\n</div>\n"
20
+ File.directory?(Frank.export.path).should be_true
21
+ end
22
+ end
23
23
  end
24
24
 
25
- it 'creates partial_test.html' do
26
- output = File.join(File.dirname(__FILE__), 'template/output/partial_test.html')
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
- it 'creates partial_locals_test.html' do
31
- output = File.join(File.dirname(__FILE__), 'template/output/partial_locals_test.html')
32
- 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"
33
- end
28
+ before(:all) do
29
+ Dir.chdir proj_dir do
30
+ frank 'export', output_dir
31
+ end
32
+ end
34
33
 
35
- it 'creates child.html' do
36
- output = File.join(File.dirname(__FILE__), 'template/output/nested/child.html')
37
- File.read(output).should == "<div id='nested_layout'>\n <h1>hello from child</h1>\n</div>\n"
38
- end
34
+ after(:all) do
35
+ FileUtils.rm_r output_dir
36
+ end
39
37
 
40
- it 'creates deep.html' do
41
- output = File.join(File.dirname(__FILE__), 'template/output/nested/deeper/deep.html')
42
- File.read(output).should == "<div id='nested_layout'>\n <h1>really deep</h1>\n</div>\n"
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
- it 'creates no_layout.html' do
46
- output = File.join(File.dirname(__FILE__), 'template/output/no_layout.html')
47
- File.read(output).should == "<h1>i have no layout</h1>\n"
48
- end
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
- it 'creates coffee.js' do
51
- output = File.join(File.dirname(__FILE__), 'template/output/coffee.js')
52
- File.read(output).should == "(function(){\n var greeting;\n greeting = \"Hello CoffeeScript\";\n})();"
53
- end
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
- it 'creates erb.html' do
56
- output = File.join(File.dirname(__FILE__), 'template/output/erb.html')
57
- File.read(output).should == "<div id='p'>/erb</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
58
- end
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
- it 'creates redcloth.html' do
61
- output = File.join(File.dirname(__FILE__), 'template/output/redcloth.html')
62
- File.read(output).should == "<div id='p'>/redcloth</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
63
- end
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
- it 'creates markdown.html' do
66
- output = File.join(File.dirname(__FILE__), 'template/output/markdown.html')
67
- File.read(output).should == "<div id='p'>/markdown</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
68
- end
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
- it 'creates liquid.html' do
71
- output = File.join(File.dirname(__FILE__), 'template/output/liquid.html')
72
- File.read(output).should == "<div id='p'>/liquid</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
73
- end
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
- it 'creates builder.html' do
76
- output = File.join(File.dirname(__FILE__), 'template/output/builder.html')
77
- File.read(output).should == "<div id='p'>/builder</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
78
- end
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
- it 'copies static.html' do
81
- output = File.join(File.dirname(__FILE__), 'template/output/files/static.html')
82
- File.read(output).should == "hello from static"
83
- end
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
- it "doesn't create partials" do
86
- File.exist?(File.join(File.dirname(__FILE__), 'template/output/_partial.html')).should be_false
87
- end
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
- it 'handles lorem replacement fields' do
90
- output = File.join(File.dirname(__FILE__), 'template/output/lorem_test.html')
91
- File.read(output).should include("<p class='words'>replace-this</p>")
92
- File.read(output).should include("<p class='sentences'>replace-this</p>")
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
- it 'should not render the refresh js' do
101
- output = File.join(File.dirname(__FILE__), 'template/output/refresh.html')
102
- File.read(output).should == "<div id='p'>/refresh</div>\n<div id='layout'>\n \n</div>\n"
103
- end
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
- after(:all) do
106
- FileUtils.rm_r File.join(File.dirname(__FILE__), 'template/output')
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
- system "#{bin_dir} #{output_dir} --production > /dev/null"
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 var greeting;\n greeting = \"Hello CoffeeScript\";\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