frank 0.3.1 → 0.3.2
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/README.md +7 -3
- data/bin/frank +2 -0
- data/bin/frankout +6 -3
- data/bin/frankup +2 -0
- data/frank.gemspec +4 -2
- data/lib/frank.rb +0 -1
- data/lib/frank/base.rb +14 -18
- data/lib/frank/template_helpers.rb +4 -3
- data/spec/helper.rb +1 -4
- data/spec/output_spec.rb +27 -31
- data/spec/render_spec.rb +7 -2
- data/spec/template/dynamic/_partial_with_locals.haml +1 -0
- data/spec/template/dynamic/partial_locals_test.haml +3 -0
- data/spec/template/dynamic/partial_test.haml +1 -0
- metadata +5 -3
data/README.md
CHANGED
@@ -125,6 +125,10 @@ in my Haml views like this:
|
|
125
125
|
|
126
126
|
= render_partial 'footer'
|
127
127
|
|
128
|
+
You can also send local variables to partials like this:
|
129
|
+
|
130
|
+
= render_partial 'footer', :local_variable_name => 'some_value'
|
131
|
+
|
128
132
|
### Helpers
|
129
133
|
|
130
134
|
Helper methods are also easy. Just open up `helpers.rb` and add your methods
|
@@ -144,9 +148,9 @@ of building a project.
|
|
144
148
|
|
145
149
|
When it's time to `frankout`, Frank will leave out the JavasScript bits of the refresher.
|
146
150
|
|
147
|
-
### Current
|
151
|
+
### Current Path
|
148
152
|
|
149
|
-
Frank now has a `
|
153
|
+
Frank now has a `current_path` variable that you can use to set selected states on nav items.
|
150
154
|
It will return the path info from the template being processed. You also, have access to the variable from layouts and from the `frankout` command.
|
151
155
|
|
152
156
|
### Placeholder Text
|
@@ -219,4 +223,4 @@ Installation
|
|
219
223
|
[10]: http://lesscss.org/
|
220
224
|
[11]: http://en.wikipedia.org/wiki/Lorem_ipsum
|
221
225
|
[12]: http://www.imagemagick.org/script/binary-releases.php?ImageMagick=4pg9cdfr8e6gn7aru9mtelepr3
|
222
|
-
[13]: http://www.yaml.org/start.html
|
226
|
+
[13]: http://www.yaml.org/start.html
|
data/bin/frank
CHANGED
data/bin/frankout
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
3
|
+
|
2
4
|
require 'optparse'
|
3
5
|
require 'frank'
|
4
6
|
|
5
|
-
|
7
|
+
production = false
|
6
8
|
|
7
9
|
opts = OptionParser.new do |opts|
|
8
10
|
opts.banner = "Usage: frankout [OPTIONS] directory\n",
|
@@ -12,7 +14,7 @@ opts = OptionParser.new do |opts|
|
|
12
14
|
opts.separator 'Options:'
|
13
15
|
|
14
16
|
opts.on('--production', 'Production ready dump i.e. ([FOLDER]/index.html)') do |handler|
|
15
|
-
|
17
|
+
production = true
|
16
18
|
end
|
17
19
|
|
18
20
|
opts.on( '-h', '--help', 'Display this help' ) do
|
@@ -45,9 +47,10 @@ begin
|
|
45
47
|
settings.each do |name, value|
|
46
48
|
set name.to_s, value
|
47
49
|
end
|
50
|
+
set :environment, :output
|
48
51
|
set :output_folder, output_folder
|
49
52
|
set :proj_dir, proj_dir
|
50
|
-
end.dump(
|
53
|
+
end.dump(production)
|
51
54
|
|
52
55
|
rescue Errno::ENOENT
|
53
56
|
puts "Frank could not find settings.yml."
|
data/bin/frankup
CHANGED
data/frank.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{frank}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["blahed", "nwah"]
|
12
|
-
s.date = %q{2010-06
|
12
|
+
s.date = %q{2010-07-06}
|
13
13
|
s.description = %q{Rapidly develop static sites using any supported templating language}
|
14
14
|
s.email = %q{travis.dunn@thisismedium.com}
|
15
15
|
s.executables = ["frank", "frankout", "frankup"]
|
@@ -64,6 +64,7 @@ Gem::Specification.new do |s|
|
|
64
64
|
"spec/render_spec.rb",
|
65
65
|
"spec/template/dynamic/500.haml",
|
66
66
|
"spec/template/dynamic/_partial.haml",
|
67
|
+
"spec/template/dynamic/_partial_with_locals.haml",
|
67
68
|
"spec/template/dynamic/builder.builder",
|
68
69
|
"spec/template/dynamic/erb.erb",
|
69
70
|
"spec/template/dynamic/helper_test.haml",
|
@@ -77,6 +78,7 @@ Gem::Specification.new do |s|
|
|
77
78
|
"spec/template/dynamic/nested/child.haml",
|
78
79
|
"spec/template/dynamic/nested/deeper/deep.haml",
|
79
80
|
"spec/template/dynamic/no_layout.haml",
|
81
|
+
"spec/template/dynamic/partial_locals_test.haml",
|
80
82
|
"spec/template/dynamic/partial_test.haml",
|
81
83
|
"spec/template/dynamic/redcloth.textile",
|
82
84
|
"spec/template/dynamic/refresh.haml",
|
data/lib/frank.rb
CHANGED
data/lib/frank/base.rb
CHANGED
@@ -6,7 +6,7 @@ require 'frank/middleware/imager'
|
|
6
6
|
require 'frank/middleware/refresh'
|
7
7
|
|
8
8
|
module Frank
|
9
|
-
VERSION = '0.3.
|
9
|
+
VERSION = '0.3.2'
|
10
10
|
|
11
11
|
module Render; end
|
12
12
|
|
@@ -63,7 +63,7 @@ module Frank
|
|
63
63
|
end
|
64
64
|
|
65
65
|
# prints requests and errors to STDOUT
|
66
|
-
def log_request(status, excp=nil)
|
66
|
+
def log_request(status, excp = nil)
|
67
67
|
out = "\033[1m[#{Time.now.strftime('%Y-%m-%d %H:%M')}]\033[22m (#{@request.request_method}) http://#{@request.host}:#{@request.port}#{@request.fullpath} - #{status}"
|
68
68
|
out << "\n\n#{excp.message}\n\n#{excp.backtrace.join("\n")} " if excp
|
69
69
|
puts out
|
@@ -89,13 +89,15 @@ module Frank
|
|
89
89
|
LAYOUT_EXTS = %w[.haml .erb .rhtml .liquid .mustache]
|
90
90
|
|
91
91
|
# render request path or template path
|
92
|
-
def render(path)
|
92
|
+
def render(path, partial = false, local_vars = nil)
|
93
|
+
@current_path = path unless partial
|
94
|
+
|
93
95
|
# normalize the path
|
94
96
|
path.sub!(/^\/?(.*)$/, '/\1')
|
95
97
|
path.sub!(/\/$/, '/index.html')
|
96
98
|
path.sub!(/(\/[\w-]+)$/, '\1.html')
|
97
99
|
path = to_file_path(path) if defined? @request or path.match(/\/_[^\/]+$/)
|
98
|
-
|
100
|
+
|
99
101
|
# regex for kinds that don't support meta
|
100
102
|
# and define the meta delimiter
|
101
103
|
nometa, delimiter = /\/_|\.(sass|less)$/, /^META-{3,}\s*$|^-{3,}META\s*$/
|
@@ -111,8 +113,8 @@ module Frank
|
|
111
113
|
template = File.read(template_path) << "\n"
|
112
114
|
ext = File.extname(path)
|
113
115
|
template, meta = template.split(delimiter).reverse
|
114
|
-
locals = parse_meta_and_set_locals(meta,
|
115
|
-
|
116
|
+
locals = parse_meta_and_set_locals(meta, local_vars)
|
117
|
+
|
116
118
|
# use given layout if defined as a meta field
|
117
119
|
layout = locals[:layout] == 'nil' ? nil : locals[:layout] if locals.has_key?(:layout)
|
118
120
|
|
@@ -211,11 +213,8 @@ module Frank
|
|
211
213
|
private
|
212
214
|
|
213
215
|
# parse the given meta string with yaml
|
214
|
-
#
|
215
|
-
|
216
|
-
def parse_meta_and_set_locals(meta, path)
|
217
|
-
locals = {}
|
218
|
-
|
216
|
+
# set the current_path local
|
217
|
+
def parse_meta_and_set_locals(meta, locals = nil)
|
219
218
|
# parse yaml and symbolize keys
|
220
219
|
if meta.nil?
|
221
220
|
meta = {}
|
@@ -224,14 +223,11 @@ module Frank
|
|
224
223
|
options[(key.to_sym rescue key) || key] = value
|
225
224
|
options
|
226
225
|
end
|
227
|
-
end
|
228
|
-
|
229
|
-
|
230
|
-
# and add it to locals
|
231
|
-
current_path = path.sub(/\.[\w-]+$/, '').sub(/\/index/, '/')
|
232
|
-
locals[:current_path] = current_path
|
226
|
+
end
|
227
|
+
meta.merge!(locals) unless locals.nil?
|
228
|
+
meta[:current_path] = @current_path.sub(/\.[\w-]+$/, '').sub(/\/index/, '/')
|
233
229
|
|
234
|
-
meta
|
230
|
+
meta
|
235
231
|
end
|
236
232
|
|
237
233
|
end
|
@@ -4,10 +4,11 @@ module Frank
|
|
4
4
|
module TemplateHelpers
|
5
5
|
include FrankHelpers if defined? FrankHelpers
|
6
6
|
|
7
|
-
def render_partial(path)
|
7
|
+
def render_partial(path, *locals)
|
8
8
|
pieces = path.split('/')
|
9
9
|
partial = '_' + pieces.pop
|
10
|
-
|
10
|
+
locals = locals.empty? ? nil : locals[0]
|
11
|
+
render(File.join(pieces.join('/'), partial), partial = true, locals)
|
11
12
|
end
|
12
13
|
|
13
14
|
def lorem
|
@@ -15,7 +16,7 @@ module Frank
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def refresh
|
18
|
-
if @environment == :output
|
19
|
+
if @environment == :output
|
19
20
|
nil
|
20
21
|
else
|
21
22
|
<<-JS
|
data/spec/helper.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
testdir = File.dirname(__FILE__)
|
2
|
-
|
3
|
-
|
4
|
-
libdir = File.dirname(File.dirname(__FILE__)) + '/lib'
|
5
|
-
$LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
|
2
|
+
$:.unshift testdir unless $LOAD_PATH.include?(testdir)
|
6
3
|
|
7
4
|
require 'stringio'
|
8
5
|
require 'rubygems'
|
data/spec/output_spec.rb
CHANGED
@@ -4,19 +4,12 @@ describe Frank::Output do
|
|
4
4
|
include Rack::Test::Methods
|
5
5
|
|
6
6
|
context 'default output' do
|
7
|
-
before
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
settings.each do |name, value|
|
14
|
-
set name.to_s, value
|
15
|
-
end
|
16
|
-
set :environment, :output
|
17
|
-
set :proj_dir, proj_dir
|
18
|
-
set :output_folder, File.join(File.dirname(__FILE__), 'template/output')
|
19
|
-
end.dump
|
7
|
+
before :all do
|
8
|
+
bin_dir = File.join(File.dirname(File.dirname(__FILE__)), 'bin', 'frankout')
|
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"
|
20
13
|
end
|
21
14
|
end
|
22
15
|
|
@@ -29,9 +22,14 @@ describe Frank::Output do
|
|
29
22
|
File.read(output).should == "<div id='p'>/</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/</h2>\n</div>\n"
|
30
23
|
end
|
31
24
|
|
32
|
-
it
|
25
|
+
it 'creates partial_test.html' do
|
33
26
|
output = File.join(File.dirname(__FILE__), 'template/output/partial_test.html')
|
34
|
-
File.read(output).should == "<div id='p'>/partial_test</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <p>hello from partial</p>\n</div>\n"
|
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
|
29
|
+
|
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"
|
35
33
|
end
|
36
34
|
|
37
35
|
it 'creates child.html' do
|
@@ -111,19 +109,12 @@ describe Frank::Output do
|
|
111
109
|
end
|
112
110
|
|
113
111
|
context 'productions output' do
|
114
|
-
before
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
settings.each do |name, value|
|
121
|
-
set name.to_s, value
|
122
|
-
end
|
123
|
-
set :environment, :output
|
124
|
-
set :proj_dir, proj_dir
|
125
|
-
set :output_folder, File.join(File.dirname(__FILE__), 'template/output')
|
126
|
-
end.dump(production=true)
|
112
|
+
before :all do
|
113
|
+
bin_dir = File.join(File.dirname(File.dirname(__FILE__)), 'bin', 'frankout')
|
114
|
+
proj_dir = File.join(File.dirname(__FILE__), 'template')
|
115
|
+
output_dir = File.join(proj_dir, 'output')
|
116
|
+
Dir.chdir proj_dir do
|
117
|
+
system "#{bin_dir} #{output_dir} --production > /dev/null"
|
127
118
|
end
|
128
119
|
end
|
129
120
|
|
@@ -136,9 +127,14 @@ describe Frank::Output do
|
|
136
127
|
File.read(output).should == "<div id='p'>/</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/</h2>\n</div>\n"
|
137
128
|
end
|
138
129
|
|
139
|
-
it
|
130
|
+
it 'creates partial_test.html' do
|
140
131
|
output = File.join(File.dirname(__FILE__), 'template/output/partial_test/index.html')
|
141
|
-
File.read(output).should == "<div id='p'>/partial_test</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <p>hello from partial</p>\n</div>\n"
|
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"
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'creates partial_locals_test.html' do
|
136
|
+
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"
|
142
138
|
end
|
143
139
|
|
144
140
|
it 'creates child.html' do
|
@@ -217,4 +213,4 @@ describe Frank::Output do
|
|
217
213
|
|
218
214
|
end
|
219
215
|
|
220
|
-
end
|
216
|
+
end
|
data/spec/render_spec.rb
CHANGED
@@ -56,7 +56,12 @@ describe Frank::Render do
|
|
56
56
|
|
57
57
|
it 'renders haml template with a haml partial' do
|
58
58
|
template = @app.render('partial_test.haml')
|
59
|
-
template.should == "<div id='p'>/partial_test</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <p>hello from partial</p>\n</div>\n"
|
59
|
+
template.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"
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'renders a partial with locals' do
|
63
|
+
template = @app.render('partial_locals_test.haml')
|
64
|
+
template.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"
|
60
65
|
end
|
61
66
|
|
62
67
|
it 'renders sass template' do
|
@@ -98,4 +103,4 @@ describe Frank::Render do
|
|
98
103
|
lambda { @app.render('not_a.template') }.should raise_error(Frank::TemplateError)
|
99
104
|
end
|
100
105
|
|
101
|
-
end
|
106
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
%p="hello from #{local}"
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 2
|
9
|
+
version: 0.3.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- blahed
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06
|
18
|
+
date: 2010-07-06 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- spec/render_spec.rb
|
141
141
|
- spec/template/dynamic/500.haml
|
142
142
|
- spec/template/dynamic/_partial.haml
|
143
|
+
- spec/template/dynamic/_partial_with_locals.haml
|
143
144
|
- spec/template/dynamic/builder.builder
|
144
145
|
- spec/template/dynamic/erb.erb
|
145
146
|
- spec/template/dynamic/helper_test.haml
|
@@ -153,6 +154,7 @@ files:
|
|
153
154
|
- spec/template/dynamic/nested/child.haml
|
154
155
|
- spec/template/dynamic/nested/deeper/deep.haml
|
155
156
|
- spec/template/dynamic/no_layout.haml
|
157
|
+
- spec/template/dynamic/partial_locals_test.haml
|
156
158
|
- spec/template/dynamic/partial_test.haml
|
157
159
|
- spec/template/dynamic/redcloth.textile
|
158
160
|
- spec/template/dynamic/refresh.haml
|