frank 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +42 -1
- data/Rakefile +6 -3
- data/VERSION +1 -1
- data/bin/frank +3 -26
- data/bin/frankup +1 -0
- data/frank.gemspec +65 -12
- data/lib/frank.rb +10 -3
- data/lib/frank/base.rb +80 -55
- data/lib/frank/imager.rb +39 -0
- data/lib/frank/lorem.rb +54 -0
- data/lib/frank/output.rb +7 -8
- data/lib/frank/rescue.rb +6 -6
- data/lib/frank/statik.rb +23 -21
- data/lib/frank/template_helpers.rb +8 -2
- data/lib/frank/templates/404.haml +1 -1
- data/lib/frank/templates/imager/frank0.jpg +0 -0
- data/lib/frank/templates/imager/frank1.jpg +0 -0
- data/lib/frank/templates/imager/frank2.jpg +0 -0
- data/lib/frank/templates/imager/frank3.jpg +0 -0
- data/lib/frank/templates/imager/frank4.jpg +0 -0
- data/lib/frank/templates/imager/frank5.jpg +0 -0
- data/lib/frank/templates/imager/frank6.jpg +0 -0
- data/lib/frank/templates/imager/frank7.jpg +0 -0
- data/lib/frank/templates/imager/frank8.jpg +0 -0
- data/lib/frank/templates/imager/frank9.png +0 -0
- data/test/helper.rb +29 -0
- data/test/suite.rb +4 -0
- data/test/template/dynamic/_partial.haml +1 -0
- data/test/template/dynamic/builder.builder +1 -0
- data/test/template/dynamic/coffee.coffee +1 -0
- data/test/template/dynamic/erb.erb +1 -0
- data/test/template/dynamic/helper_test.haml +1 -0
- data/test/template/dynamic/index.haml +2 -0
- data/test/template/dynamic/layout.haml +2 -0
- data/test/template/dynamic/layout2.haml +2 -0
- data/test/template/dynamic/layout2_test.haml +1 -0
- data/test/template/dynamic/layout_test.haml +1 -0
- data/test/template/dynamic/liquid.liquid +1 -0
- data/test/template/dynamic/lorem_test.haml +4 -0
- data/test/template/dynamic/markdown.md +1 -0
- data/test/template/dynamic/mustache.mustache +1 -0
- data/test/template/dynamic/partial_test.haml +2 -0
- data/test/template/dynamic/redcloth.textile +1 -0
- data/test/template/dynamic/sass.sass +2 -0
- data/test/template/helpers.rb +5 -0
- data/test/template/settings.yml +67 -0
- data/test/template/static/static.html +1 -0
- data/test/test_base.rb +81 -0
- data/test/test_helpers.rb +53 -0
- data/test/test_output.rb +81 -0
- data/test/test_render.rb +89 -0
- metadata +71 -7
data/README.md
CHANGED
@@ -81,6 +81,43 @@ Helper methods are also easy. Just open up `helpers.rb` and add your methods
|
|
81
81
|
to the `FrankHelpers` module; that's it. Use them just like `render_partial`.
|
82
82
|
|
83
83
|
|
84
|
+
|
85
|
+
Built-in Helpers
|
86
|
+
----------------
|
87
|
+
|
88
|
+
Frank also comes with some handy helper methods for generating placeholder content.
|
89
|
+
|
90
|
+
### Placeholder Text
|
91
|
+
|
92
|
+
You can easily generate dummy text like so:
|
93
|
+
|
94
|
+
%p= lorem.sentences 3
|
95
|
+
|
96
|
+
This will return 3 sentences of standard [Lorem Ipsum][11]. `lorem` also has all of the following methods for generating dummy text:
|
97
|
+
|
98
|
+
lorem.sentence # returns a single sentence
|
99
|
+
lorem.words 5 # returns 5 individual words
|
100
|
+
lorem.word
|
101
|
+
lorem.paragraphs 10
|
102
|
+
lorem.paragraph
|
103
|
+
|
104
|
+
|
105
|
+
### Placeholder Images
|
106
|
+
|
107
|
+
Likewise, Frank can generate placeholder images for you, from a selection of 10 pre-made images. For example, to generate `<img />` tag with a random dummy image:
|
108
|
+
|
109
|
+
%img{:src=> lorem.image( 500, 400 ) }
|
110
|
+
|
111
|
+
The `lorem.image` helper returns a special Frank image URL. In this case, the returned image will be 500 pixels wide and 400 pixels tall. By default, Frank caches the images returned for each specific size. So every subsequent request for a `500x400` image will return the same thing. If you'd rather have a random image every time, just pass in `true` for the 3rd image:
|
112
|
+
|
113
|
+
lorem.image( 100, 100, true ) # returns a random 100x100 image every time it's called
|
114
|
+
|
115
|
+
( NOTE: Unfortunately, in order to use the placeholder images, you must have a working [ImageMagick][12], and have the `mini_magick` gem installed as well. )
|
116
|
+
|
117
|
+
If you would like to use the placeholder images in a context where the helper methods are unavailable (e.g. in static CSS or JavaScript), you can access the URL directly with `/_img/500x400.jpg`, or for random images `/_img/500x400.jpg?random`.
|
118
|
+
|
119
|
+
|
120
|
+
|
84
121
|
GET/POST params
|
85
122
|
---------------
|
86
123
|
|
@@ -92,6 +129,8 @@ For example, to use a person's name submitted through a form you might do:
|
|
92
129
|
|
93
130
|
%h1= "Hello, #{params.name}"
|
94
131
|
|
132
|
+
|
133
|
+
|
95
134
|
Configuration
|
96
135
|
-------------
|
97
136
|
|
@@ -124,4 +163,6 @@ Installation
|
|
124
163
|
[7]: http://jashkenas.github.com/coffee-script/
|
125
164
|
[8]: http://lesscss.org/
|
126
165
|
[9]: http://rack.rubyforge.org/
|
127
|
-
[10]: http://lesscss.org/
|
166
|
+
[10]: http://lesscss.org/
|
167
|
+
[11]: http://en.wikipedia.org/wiki/Lorem_ipsum
|
168
|
+
[12]: http://www.imagemagick.org/script/binary-releases.php?ImageMagick=4pg9cdfr8e6gn7aru9mtelepr3
|
data/Rakefile
CHANGED
@@ -7,9 +7,12 @@ begin
|
|
7
7
|
gemspec.email = "travis.dunn@thisismedium.com"
|
8
8
|
gemspec.homepage = "http://github.com/blahed/frank"
|
9
9
|
gemspec.authors = ["blahed", "nwah"]
|
10
|
-
gemspec.add_dependency 'rack'
|
11
|
-
gemspec.add_dependency 'mongrel'
|
12
|
-
gemspec.add_dependency 'haml'
|
10
|
+
gemspec.add_dependency 'rack', '>=1.0'
|
11
|
+
gemspec.add_dependency 'mongrel', '>=1.0'
|
12
|
+
gemspec.add_dependency 'haml', '>=2.0'
|
13
|
+
gemspec.add_development_dependency 'shoulda', '>=2.0'
|
14
|
+
gemspec.add_development_dependency 'rack-test', '>=0.5'
|
15
|
+
|
13
16
|
end
|
14
17
|
Jeweler::GemcutterTasks.new
|
15
18
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/frank
CHANGED
@@ -1,33 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require 'frank'
|
2
3
|
|
3
4
|
if ARGV.empty?
|
4
5
|
puts "Usage: frank [PROJECT_NAME]"
|
5
|
-
puts "Stubs out a template project
|
6
|
+
puts "Stubs out a template project"
|
6
7
|
exit
|
7
8
|
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
project = ARGV.first
|
12
|
-
libdir = File.join(File.dirname(File.expand_path(__FILE__)), '../lib')
|
13
|
-
dot_frank = File.join(ENV['HOME'], '.frank')
|
14
|
-
|
15
|
-
puts " - Creating '#{project}'"
|
16
|
-
begin
|
17
|
-
Dir.mkdir project
|
18
|
-
rescue Errno::EEXIST
|
19
|
-
puts " uh oh, #{project} already exists..."
|
20
|
-
exit
|
21
|
-
end
|
22
|
-
|
23
|
-
# If they have a .frank, copy contents to new project folder
|
24
|
-
if File.directory? dot_frank
|
25
|
-
puts " - Copying .frank template"
|
26
|
-
FileUtils.cp_r( File.join(dot_frank, '.'), project )
|
27
|
-
else # Otherwise just copy over the template project
|
28
|
-
puts " - Copying Frank template"
|
29
|
-
FileUtils.cp_r( Dir.glob(File.join(libdir, 'template/*')), project )
|
30
|
-
end
|
31
|
-
|
32
|
-
puts "\n Congratulations, '#{project}' is ready to go.\n\n"
|
33
|
-
|
10
|
+
Frank.stub(ARGV.first)
|
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.
|
8
|
+
s.version = "0.2.0"
|
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-02-
|
12
|
+
s.date = %q{2010-02-26}
|
13
13
|
s.description = %q{Create/Dump static builds using whatever templating/helper languages you wish}
|
14
14
|
s.email = %q{travis.dunn@thisismedium.com}
|
15
15
|
s.executables = ["frank", "frankout", "frankup"]
|
@@ -29,6 +29,8 @@ Gem::Specification.new do |s|
|
|
29
29
|
"frank.gemspec",
|
30
30
|
"lib/frank.rb",
|
31
31
|
"lib/frank/base.rb",
|
32
|
+
"lib/frank/imager.rb",
|
33
|
+
"lib/frank/lorem.rb",
|
32
34
|
"lib/frank/output.rb",
|
33
35
|
"lib/frank/rescue.rb",
|
34
36
|
"lib/frank/statik.rb",
|
@@ -37,6 +39,16 @@ Gem::Specification.new do |s|
|
|
37
39
|
"lib/frank/templates/500.haml",
|
38
40
|
"lib/frank/templates/frank-404.png",
|
39
41
|
"lib/frank/templates/frank-500.png",
|
42
|
+
"lib/frank/templates/imager/frank0.jpg",
|
43
|
+
"lib/frank/templates/imager/frank1.jpg",
|
44
|
+
"lib/frank/templates/imager/frank2.jpg",
|
45
|
+
"lib/frank/templates/imager/frank3.jpg",
|
46
|
+
"lib/frank/templates/imager/frank4.jpg",
|
47
|
+
"lib/frank/templates/imager/frank5.jpg",
|
48
|
+
"lib/frank/templates/imager/frank6.jpg",
|
49
|
+
"lib/frank/templates/imager/frank7.jpg",
|
50
|
+
"lib/frank/templates/imager/frank8.jpg",
|
51
|
+
"lib/frank/templates/imager/frank9.png",
|
40
52
|
"lib/frank/tilt.rb",
|
41
53
|
"lib/template/dynamic/css/frank.sass",
|
42
54
|
"lib/template/dynamic/index.haml",
|
@@ -44,31 +56,72 @@ Gem::Specification.new do |s|
|
|
44
56
|
"lib/template/helpers.rb",
|
45
57
|
"lib/template/settings.yml",
|
46
58
|
"lib/template/static/images/frank-med.png",
|
47
|
-
"lib/template/static/js/frank.js"
|
59
|
+
"lib/template/static/js/frank.js",
|
60
|
+
"test/helper.rb",
|
61
|
+
"test/suite.rb",
|
62
|
+
"test/template/dynamic/_partial.haml",
|
63
|
+
"test/template/dynamic/builder.builder",
|
64
|
+
"test/template/dynamic/coffee.coffee",
|
65
|
+
"test/template/dynamic/erb.erb",
|
66
|
+
"test/template/dynamic/helper_test.haml",
|
67
|
+
"test/template/dynamic/index.haml",
|
68
|
+
"test/template/dynamic/layout.haml",
|
69
|
+
"test/template/dynamic/layout2.haml",
|
70
|
+
"test/template/dynamic/layout2_test.haml",
|
71
|
+
"test/template/dynamic/layout_test.haml",
|
72
|
+
"test/template/dynamic/liquid.liquid",
|
73
|
+
"test/template/dynamic/lorem_test.haml",
|
74
|
+
"test/template/dynamic/markdown.md",
|
75
|
+
"test/template/dynamic/mustache.mustache",
|
76
|
+
"test/template/dynamic/partial_test.haml",
|
77
|
+
"test/template/dynamic/redcloth.textile",
|
78
|
+
"test/template/dynamic/sass.sass",
|
79
|
+
"test/template/helpers.rb",
|
80
|
+
"test/template/settings.yml",
|
81
|
+
"test/template/static/static.html",
|
82
|
+
"test/test_base.rb",
|
83
|
+
"test/test_helpers.rb",
|
84
|
+
"test/test_output.rb",
|
85
|
+
"test/test_render.rb"
|
48
86
|
]
|
49
87
|
s.homepage = %q{http://github.com/blahed/frank}
|
50
88
|
s.rdoc_options = ["--charset=UTF-8"]
|
51
89
|
s.require_paths = ["lib"]
|
52
90
|
s.rubygems_version = %q{1.3.5}
|
53
91
|
s.summary = %q{Stupidly Simple Static Slinger}
|
92
|
+
s.test_files = [
|
93
|
+
"test/helper.rb",
|
94
|
+
"test/suite.rb",
|
95
|
+
"test/template/helpers.rb",
|
96
|
+
"test/test_base.rb",
|
97
|
+
"test/test_helpers.rb",
|
98
|
+
"test/test_output.rb",
|
99
|
+
"test/test_render.rb"
|
100
|
+
]
|
54
101
|
|
55
102
|
if s.respond_to? :specification_version then
|
56
103
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
57
104
|
s.specification_version = 3
|
58
105
|
|
59
106
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
60
|
-
s.add_runtime_dependency(%q<rack>, [">= 0"])
|
61
|
-
s.add_runtime_dependency(%q<mongrel>, [">= 0"])
|
62
|
-
s.add_runtime_dependency(%q<haml>, [">= 0"])
|
107
|
+
s.add_runtime_dependency(%q<rack>, [">= 1.0"])
|
108
|
+
s.add_runtime_dependency(%q<mongrel>, [">= 1.0"])
|
109
|
+
s.add_runtime_dependency(%q<haml>, [">= 2.0"])
|
110
|
+
s.add_development_dependency(%q<shoulda>, [">= 2.0"])
|
111
|
+
s.add_development_dependency(%q<rack-test>, [">= 0.5"])
|
63
112
|
else
|
64
|
-
s.add_dependency(%q<rack>, [">= 0"])
|
65
|
-
s.add_dependency(%q<mongrel>, [">= 0"])
|
66
|
-
s.add_dependency(%q<haml>, [">= 0"])
|
113
|
+
s.add_dependency(%q<rack>, [">= 1.0"])
|
114
|
+
s.add_dependency(%q<mongrel>, [">= 1.0"])
|
115
|
+
s.add_dependency(%q<haml>, [">= 2.0"])
|
116
|
+
s.add_dependency(%q<shoulda>, [">= 2.0"])
|
117
|
+
s.add_dependency(%q<rack-test>, [">= 0.5"])
|
67
118
|
end
|
68
119
|
else
|
69
|
-
s.add_dependency(%q<rack>, [">= 0"])
|
70
|
-
s.add_dependency(%q<mongrel>, [">= 0"])
|
71
|
-
s.add_dependency(%q<haml>, [">= 0"])
|
120
|
+
s.add_dependency(%q<rack>, [">= 1.0"])
|
121
|
+
s.add_dependency(%q<mongrel>, [">= 1.0"])
|
122
|
+
s.add_dependency(%q<haml>, [">= 2.0"])
|
123
|
+
s.add_dependency(%q<shoulda>, [">= 2.0"])
|
124
|
+
s.add_dependency(%q<rack-test>, [">= 0.5"])
|
72
125
|
end
|
73
126
|
end
|
74
127
|
|
data/lib/frank.rb
CHANGED
@@ -1,7 +1,14 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift(
|
1
|
+
LIBDIR = File.dirname(__FILE__)
|
2
|
+
$LOAD_PATH.unshift(LIBDIR) unless $LOAD_PATH.include?(LIBDIR)
|
3
|
+
|
4
|
+
local_helpers = File.join(Dir.pwd, 'helpers.rb')
|
5
|
+
require local_helpers[0..-4] if File.exists? local_helpers
|
6
|
+
|
7
|
+
module Frank
|
8
|
+
class TemplateError < StandardError; end
|
9
|
+
class ConfigError < StandardError; end
|
10
|
+
end
|
3
11
|
|
4
|
-
require File.join(Dir.pwd, 'helpers')
|
5
12
|
require 'rubygems'
|
6
13
|
require 'frank/base'
|
7
14
|
require 'frank/output'
|
data/lib/frank/base.rb
CHANGED
@@ -3,23 +3,24 @@ require 'frank/tilt'
|
|
3
3
|
require 'frank/template_helpers'
|
4
4
|
require 'frank/rescue'
|
5
5
|
require 'frank/statik'
|
6
|
+
require 'frank/imager'
|
6
7
|
|
7
8
|
module Frank
|
8
9
|
|
9
10
|
module Render; end
|
10
|
-
|
11
|
+
|
11
12
|
class Base
|
12
13
|
include Rack::Utils
|
13
14
|
include Frank::Rescue
|
14
15
|
include Frank::TemplateHelpers
|
15
16
|
include Frank::Render
|
16
17
|
|
17
|
-
attr_accessor :server, :static_folder, :dynamic_folder, :templates
|
18
|
+
attr_accessor :environment, :proj_dir, :server, :static_folder, :dynamic_folder, :templates
|
18
19
|
|
19
20
|
def initialize(&block)
|
20
21
|
instance_eval &block
|
21
22
|
end
|
22
|
-
|
23
|
+
|
23
24
|
def call(env)
|
24
25
|
dup.call!(env)
|
25
26
|
end
|
@@ -36,7 +37,7 @@ module Frank
|
|
36
37
|
private
|
37
38
|
|
38
39
|
# setter for options
|
39
|
-
def set(option, value)
|
40
|
+
def set(option, value)
|
40
41
|
if respond_to?("#{option}=")
|
41
42
|
send "#{option}=", value
|
42
43
|
end
|
@@ -45,22 +46,20 @@ module Frank
|
|
45
46
|
# attempt to render with the request path,
|
46
47
|
# if it cannot be found, render error page
|
47
48
|
def process
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
render_500 e
|
56
|
-
end
|
49
|
+
ext = File.extname(@request.path.split('/').last || '')
|
50
|
+
@response['Content-Type'] = Rack::Mime.mime_type(ext, 'text/html')
|
51
|
+
@response.write render_path(@request.path)
|
52
|
+
rescue Frank::TemplateError
|
53
|
+
render_404
|
54
|
+
rescue Exception => e
|
55
|
+
render_500 e
|
57
56
|
end
|
58
57
|
|
59
58
|
# prints requests and errors to STDOUT
|
60
59
|
def log_request(status, excp=nil)
|
61
|
-
out = "[#{Time.now.strftime('%Y-%m-%d %H:%M')}] (#{@
|
60
|
+
out = "[#{Time.now.strftime('%Y-%m-%d %H:%M')}] (#{@request.request_method}) http://#{@request.host}:#{@request.port}#{@request.fullpath} - #{status}"
|
62
61
|
out += "\n\n**QUACK** #{excp.message}\n\n#{excp.backtrace.join("\n")} " if excp
|
63
|
-
STDOUT.puts out
|
62
|
+
STDOUT.puts out unless @environment == :test
|
64
63
|
end
|
65
64
|
|
66
65
|
end
|
@@ -71,25 +70,28 @@ module Frank
|
|
71
70
|
return path.split(/\.(?=[^.]+$)/)
|
72
71
|
end
|
73
72
|
|
73
|
+
# breaks down path and renders partials, js, css without layouts
|
74
74
|
def render_path(path)
|
75
75
|
path.sub!(/^\//,'')
|
76
76
|
template, ext = find_template_ext(path)
|
77
|
-
|
78
|
-
|
77
|
+
|
78
|
+
raise Frank::TemplateError, "Template not found #{path}" if template.nil?
|
79
79
|
if template.match(/^_/) or (ext||'').match(/^(js|css)$/)
|
80
80
|
render_template template
|
81
81
|
else
|
82
82
|
render_with_layout template
|
83
83
|
end
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
|
+
# renders a template
|
86
87
|
def render_template(tmpl, *args)
|
87
|
-
tilt_with_request(File.join(@dynamic_folder, tmpl), *args) {"CONTENT"}
|
88
|
+
tilt_with_request(File.join(@proj_dir, @dynamic_folder, tmpl), *args) {"CONTENT"}
|
88
89
|
end
|
89
|
-
|
90
|
+
|
91
|
+
# renders layout and template inside layout block
|
90
92
|
def render_with_layout(tmpl, *args)
|
91
93
|
if layout = get_layout_for(tmpl)
|
92
|
-
tilt_with_request(File.join(@dynamic_folder, layout), *args) do
|
94
|
+
tilt_with_request(File.join(@proj_dir, @dynamic_folder, layout), *args) do
|
93
95
|
render_template tmpl
|
94
96
|
end
|
95
97
|
else
|
@@ -97,7 +99,7 @@ module Frank
|
|
97
99
|
end
|
98
100
|
end
|
99
101
|
|
100
|
-
TMPL_EXTS = { :html => %w[haml erb rhtml builder liquid mustache],
|
102
|
+
TMPL_EXTS = { :html => %w[haml erb rhtml builder liquid mustache textile md mkd markdown],
|
101
103
|
:css => %w[sass less],
|
102
104
|
:js => %w[coffee] }
|
103
105
|
|
@@ -107,29 +109,36 @@ module Frank
|
|
107
109
|
end
|
108
110
|
nil
|
109
111
|
end
|
110
|
-
|
112
|
+
|
113
|
+
# finds template extension based on filename
|
114
|
+
# TODO: cleanup
|
111
115
|
def find_template_ext(filename)
|
112
|
-
name, kind = name_ext(filename)
|
113
|
-
kind = reverse_ext_lookup(kind) if kind && TMPL_EXTS[kind.intern].nil?
|
116
|
+
name, kind = name_ext(filename)
|
117
|
+
kind = reverse_ext_lookup(kind) if kind && TMPL_EXTS[kind.intern].nil?
|
114
118
|
|
115
|
-
|
116
|
-
tmpl = "#{(name||'')}.#{ext}"
|
117
|
-
return [tmpl, kind] if File.exists? File.join(@dynamic_folder, tmpl)
|
118
|
-
end
|
119
|
+
tmpl_ext = nil
|
119
120
|
|
120
121
|
TMPL_EXTS[ kind.nil? ? :html : kind.intern ].each do |ext|
|
122
|
+
tmpl = "#{(name||'')}.#{ext}"
|
121
123
|
default = File.join((name||''), "#{@templates['default']}.#{ext}")
|
122
|
-
|
124
|
+
|
125
|
+
if File.exists? File.join(@proj_dir, @dynamic_folder, tmpl)
|
126
|
+
tmpl_ext = [tmpl, ext]
|
127
|
+
elsif File.exists? File.join(@proj_dir, @dynamic_folder, default)
|
128
|
+
tmpl_ext = [default, ext]
|
129
|
+
end
|
123
130
|
end
|
124
|
-
|
125
|
-
|
126
|
-
nil
|
131
|
+
|
132
|
+
tmpl_ext
|
127
133
|
end
|
128
134
|
|
135
|
+
# determines layout using layouts setting
|
136
|
+
# in settings.yml
|
137
|
+
# TODO: cleanup
|
129
138
|
def get_layout_for(view)
|
130
139
|
view, ext = name_ext(view)
|
140
|
+
|
131
141
|
layouts = @templates['layouts'] || []
|
132
|
-
|
133
142
|
onlies = layouts.select {|l| l['only'] }
|
134
143
|
nots = layouts.select {|l| l['not'] }
|
135
144
|
blanks = layouts - onlies - nots
|
@@ -137,17 +146,17 @@ module Frank
|
|
137
146
|
layout = onlies.select {|l| l['only'].index(view) }.first
|
138
147
|
layout = nots.reject {|l| l['not'].index(view) }.first unless layout
|
139
148
|
layout = blanks.first unless layout
|
140
|
-
|
149
|
+
|
150
|
+
layout = nil if (TMPL_EXTS[:css] + TMPL_EXTS[:js]).include?(ext)
|
151
|
+
|
141
152
|
layout.nil? ? nil : layout['name'] + '.' + ext
|
142
153
|
end
|
143
154
|
|
144
|
-
|
145
|
-
|
146
|
-
end
|
147
|
-
|
148
|
-
def tilt_with_request(file, *args, &block)
|
155
|
+
# TODO: cleanup
|
156
|
+
def tilt_with_request(file, *args, &block)
|
149
157
|
locals = @request.nil? ? {} : { :request => @env, :params => @request.params }
|
150
158
|
obj = Object.new.extend(TemplateHelpers).extend(Render)
|
159
|
+
obj.instance_variable_set(:@proj_dir, @proj_dir)
|
151
160
|
obj.instance_variable_set(:@dynamic_folder, @dynamic_folder)
|
152
161
|
obj.instance_variable_set(:@templates, @templates)
|
153
162
|
Tilt.new(file, 1).render(obj, locals, &block)
|
@@ -159,29 +168,45 @@ module Frank
|
|
159
168
|
|
160
169
|
end
|
161
170
|
|
171
|
+
# starts the server
|
162
172
|
def self.new(&block)
|
163
173
|
base = Base.new(&block) if block_given?
|
164
|
-
server_settings = base.instance_variable_get(:@server)
|
165
174
|
|
166
175
|
builder = Rack::Builder.new do
|
167
|
-
use
|
176
|
+
use Frank::Statik, :root => base.static_folder
|
177
|
+
use Frank::Imager
|
168
178
|
run base
|
169
179
|
end
|
180
|
+
|
181
|
+
unless base.environment == :test
|
182
|
+
m = "got it under control \n got your back \n holdin' it down
|
183
|
+
takin' care of business \n workin' some magic".split("\n").sort_by{rand}.first.strip
|
184
|
+
puts "\n-----------------------\n" +
|
185
|
+
" Frank's #{ m }...\n" +
|
186
|
+
" #{base.server['hostname']}:#{base.server['port']} \n\n"
|
187
|
+
|
188
|
+
server = Rack::Handler.get(base.server['handler'])
|
189
|
+
server.run(builder, :Port => base.server['port'], :Host => base.server['hostname']) do
|
190
|
+
trap(:INT) { puts "\n\n-----------------------\n Show's over, fellas.\n\n"; exit }
|
191
|
+
end
|
192
|
+
end
|
170
193
|
|
171
|
-
|
172
|
-
takin' care of business \n workin' some magic".split("\n").sort_by{rand}.first.strip
|
173
|
-
puts "\n-----------------------\n" +
|
174
|
-
" Frank's #{ m }...\n" +
|
175
|
-
" #{server_settings['hostname']}:#{server_settings['port']} \n\n"
|
194
|
+
base
|
176
195
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
puts "
|
184
|
-
|
196
|
+
rescue Errno::EADDRINUSE
|
197
|
+
puts " Hold on a second... Frank works alone.\n \033[31mSomething's already using port #{base.server['port']}\033[0m\n\n"
|
198
|
+
end
|
199
|
+
|
200
|
+
# copies over the generic project template
|
201
|
+
def self.stub(project)
|
202
|
+
puts "\n-----------------------\n Frank:\n - Creating '#{project}'"
|
203
|
+
Dir.mkdir project
|
204
|
+
puts " - Copying Frank template"
|
205
|
+
FileUtils.cp_r( Dir.glob(File.join(LIBDIR, 'template/*')), project )
|
206
|
+
puts "\n Congratulations, '#{project}' is ready to go.\n\n"
|
207
|
+
rescue Errno::EEXIST
|
208
|
+
puts " uh oh, #{project} already exists..."
|
209
|
+
exit
|
185
210
|
end
|
186
211
|
|
187
212
|
end
|