frank 0.2.6 → 0.3.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/Featurelist +6 -0
- data/README.md +44 -32
- data/Rakefile +3 -3
- data/frank.gemspec +51 -45
- data/lib/frank.rb +1 -0
- data/lib/frank/base.rb +144 -94
- data/lib/frank/lorem.rb +77 -36
- data/lib/frank/middleware/imager.rb +43 -0
- data/lib/frank/middleware/refresh.rb +42 -0
- data/lib/frank/middleware/statik.rb +41 -0
- data/lib/frank/output.rb +25 -37
- data/lib/frank/rescue.rb +13 -6
- data/lib/frank/template_helpers.rb +34 -3
- data/lib/frank/templates/404.haml +1 -0
- data/lib/frank/templates/500.haml +2 -0
- data/lib/frank/tilt.rb +389 -141
- data/lib/template/{dynamic/layout.haml → layouts/default.haml} +0 -0
- data/lib/template/settings.yml +15 -28
- data/spec/base_spec.rb +88 -0
- data/{test → spec}/helper.rb +0 -7
- data/spec/output_spec.rb +220 -0
- data/spec/render_spec.rb +106 -0
- data/spec/template/dynamic/500.haml +1 -0
- data/{test → spec}/template/dynamic/_partial.haml +0 -0
- data/{test → spec}/template/dynamic/builder.builder +0 -0
- data/{test → spec}/template/dynamic/coffee.coffee +0 -0
- data/{test → spec}/template/dynamic/erb.erb +0 -0
- data/{test → spec}/template/dynamic/helper_test.haml +0 -0
- data/spec/template/dynamic/index.haml +5 -0
- data/spec/template/dynamic/layout2_test.haml +4 -0
- data/{test → spec}/template/dynamic/liquid.liquid +0 -0
- data/spec/template/dynamic/lorem_test.haml +7 -0
- data/{test → spec}/template/dynamic/markdown.md +0 -0
- data/spec/template/dynamic/markdown_in_haml.md +4 -0
- data/{test → spec}/template/dynamic/mustache.mustache +0 -0
- data/spec/template/dynamic/nested/child.haml +1 -0
- data/spec/template/dynamic/nested/deeper/deep.haml +1 -0
- data/spec/template/dynamic/no_layout.haml +4 -0
- data/spec/template/dynamic/partial_test.haml +2 -0
- data/{test → spec}/template/dynamic/redcloth.textile +0 -0
- data/spec/template/dynamic/refresh.haml +1 -0
- data/{test → spec}/template/dynamic/sass.sass +0 -0
- data/{test → spec}/template/helpers.rb +0 -0
- data/spec/template/layouts/default.haml +3 -0
- data/{test/template/dynamic → spec/template/layouts/explicit}/layout2.haml +0 -0
- data/spec/template/layouts/nested/default.haml +2 -0
- data/spec/template/settings.yml +45 -0
- data/{test/template/static → spec/template/static/files}/static.html +0 -0
- data/spec/template_helpers_spec.rb +78 -0
- metadata +57 -49
- data/lib/frank/imager.rb +0 -39
- data/lib/frank/statik.rb +0 -39
- data/test/suite.rb +0 -4
- data/test/template/dynamic/index.haml +0 -2
- data/test/template/dynamic/layout.haml +0 -2
- data/test/template/dynamic/layout2_test.haml +0 -1
- data/test/template/dynamic/layout_test.haml +0 -1
- data/test/template/dynamic/lorem_test.haml +0 -7
- data/test/template/dynamic/partial_test.haml +0 -2
- data/test/template/settings.yml +0 -62
- data/test/test_base.rb +0 -81
- data/test/test_helpers.rb +0 -71
- data/test/test_output.rb +0 -160
- data/test/test_render.rb +0 -89
data/lib/frank/lorem.rb
CHANGED
@@ -2,81 +2,122 @@ module Frank
|
|
2
2
|
class Lorem
|
3
3
|
WORDS = %w(alias consequatur aut perferendis sit voluptatem accusantium doloremque aperiam eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo aspernatur aut odit aut fugit sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt neque dolorem ipsum quia dolor sit amet consectetur adipisci velit sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem ut enim ad minima veniam quis nostrum exercitationem ullam corporis nemo enim ipsam voluptatem quia voluptas sit suscipit laboriosam nisi ut aliquid ex ea commodi consequatur quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae et iusto odio dignissimos ducimus qui blanditiis praesentium laudantium totam rem voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident sed ut perspiciatis unde omnis iste natus error similique sunt in culpa qui officia deserunt mollitia animi id est laborum et dolorum fuga et harum quidem rerum facilis est et expedita distinctio nam libero tempore cum soluta nobis est eligendi optio cumque nihil impedit quo porro quisquam est qui minus id quod maxime placeat facere possimus omnis voluptas assumenda est omnis dolor repellendus temporibus autem quibusdam et aut consequatur vel illum qui dolorem eum fugiat quo voluptas nulla pariatur at vero eos et accusamus officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae itaque earum rerum hic tenetur a sapiente delectus ut aut reiciendis voluptatibus maiores doloribus asperiores repellat)
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
def initialize(environment)
|
6
|
+
@environment = environment
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
def word(replacement = nil)
|
11
|
+
words 1, replacement
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'ruby-debug'
|
10
15
|
|
11
|
-
|
16
|
+
def words(total, replacement = nil)
|
17
|
+
if @environment == :output && replacement
|
18
|
+
replacement
|
19
|
+
else
|
12
20
|
(1..total).map do
|
13
21
|
randm(WORDS)
|
14
22
|
end.join(' ')
|
15
23
|
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
24
|
+
end
|
25
|
+
|
26
|
+
def sentence(replacement = nil)
|
27
|
+
sentences 1, replacement
|
28
|
+
end
|
20
29
|
|
21
|
-
|
30
|
+
def sentences(total, replacement = nil)
|
31
|
+
# TODO: Don't capitalize replacement field
|
32
|
+
if @environment == :output && replacement
|
33
|
+
replacement
|
34
|
+
else
|
22
35
|
(1..total).map do
|
23
36
|
words(randm(4..15)).capitalize
|
24
37
|
end.join('. ')
|
25
38
|
end
|
26
|
-
|
27
|
-
def paragraph
|
28
|
-
paragraphs 1
|
29
|
-
end
|
39
|
+
end
|
30
40
|
|
31
|
-
|
41
|
+
def paragraph(replacement = nil)
|
42
|
+
paragraphs 1, replacement
|
43
|
+
end
|
44
|
+
|
45
|
+
def paragraphs(total, replacement = nil)
|
46
|
+
if @environment == :output && replacement
|
47
|
+
replacement
|
48
|
+
else
|
32
49
|
(1..total).map do
|
33
|
-
sentences(randm(3..7)).capitalize
|
50
|
+
sentences(randm(3..7), replacement).capitalize
|
34
51
|
end.join("\n\n")
|
35
52
|
end
|
36
|
-
|
37
|
-
|
53
|
+
end
|
54
|
+
|
55
|
+
def date(fmt = '%a %b %d, %Y', replacement = nil)
|
56
|
+
if @environment == :output && replacement
|
57
|
+
replacement
|
58
|
+
else
|
38
59
|
y = rand(20) + 1990
|
39
60
|
m = rand(12) + 1
|
40
61
|
d = rand(31) + 1
|
41
62
|
Time.local(y,m,d).strftime(fmt)
|
42
63
|
end
|
43
|
-
|
44
|
-
|
64
|
+
end
|
65
|
+
|
66
|
+
def name(replacement = nil)
|
67
|
+
if @environment == :output && replacement
|
68
|
+
replacement
|
69
|
+
else
|
45
70
|
"#{first_name} #{last_name}"
|
46
71
|
end
|
47
|
-
|
48
|
-
|
72
|
+
end
|
73
|
+
|
74
|
+
def first_name(replacement = nil)
|
75
|
+
if @environment == :output && replacement
|
76
|
+
replacement
|
77
|
+
else
|
49
78
|
names = %w(Judith Angelo Margarita Kerry Elaine Lorenzo Justice Doris Raul Liliana Kerry Elise Ciaran Johnny Moses Davion Penny Mohammed Harvey Sheryl Hudson Brendan Brooklynn Denis Sadie Trisha Jacquelyn Virgil Cindy Alexa Marianne Giselle Casey Alondra Angela Katherine Skyler Kyleigh Carly Abel Adrianna Luis Dominick Eoin Noel Ciara Roberto Skylar Brock Earl Dwayne Jackie Hamish Sienna Nolan Daren Jean Shirley Connor Geraldine Niall Kristi Monty Yvonne Tammie Zachariah Fatima Ruby Nadia Anahi Calum Peggy Alfredo Marybeth Bonnie Gordon Cara John Staci Samuel Carmen Rylee Yehudi Colm Beth Dulce Darius inley Javon Jason Perla Wayne Laila Kaleigh Maggie Don Quinn Collin Aniya Zoe Isabel Clint Leland Esmeralda Emma Madeline Byron Courtney Vanessa Terry Antoinette George Constance Preston Rolando Caleb Kenneth Lynette Carley Francesca Johnnie Jordyn Arturo Camila Skye Guy Ana Kaylin Nia Colton Bart Brendon Alvin Daryl Dirk Mya Pete Joann Uriel Alonzo Agnes Chris Alyson Paola Dora Elias Allen Jackie Eric Bonita Kelvin Emiliano Ashton Kyra Kailey Sonja Alberto Ty Summer Brayden Lori Kelly Tomas Joey Billie Katie Stephanie Danielle Alexis Jamal Kieran Lucinda Eliza Allyson Melinda Alma Piper Deana Harriet Bryce Eli Jadyn Rogelio Orlaith Janet Randal Toby Carla Lorie Caitlyn Annika Isabelle inn Ewan Maisie Michelle Grady Ida Reid Emely Tricia Beau Reese Vance Dalton Lexi Rafael Makenzie Mitzi Clinton Xena Angelina Kendrick Leslie Teddy Jerald Noelle Neil Marsha Gayle Omar Abigail Alexandra Phil Andre Billy Brenden Bianca Jared Gretchen Patrick Antonio Josephine Kyla Manuel Freya Kellie Tonia Jamie Sydney Andres Ruben Harrison Hector Clyde Wendell Kaden Ian Tracy Cathleen Shawn)
|
50
79
|
names[rand(names.size)]
|
51
80
|
end
|
52
|
-
|
53
|
-
|
81
|
+
end
|
82
|
+
|
83
|
+
def last_name(replacement = nil)
|
84
|
+
if @environment == :output && replacement
|
85
|
+
replacement
|
86
|
+
else
|
54
87
|
names = %w(Chung Chen Melton Hill Puckett Song Hamilton Bender Wagner McLaughlin McNamara Raynor Moon Woodard Desai Wallace Lawrence Griffin Dougherty Powers May Steele Teague Vick Gallagher Solomon Walsh Monroe Connolly Hawkins Middleton Goldstein Watts Johnston Weeks Wilkerson Barton Walton Hall Ross Chung Bender Woods Mangum Joseph Rosenthal Bowden Barton Underwood Jones Baker Merritt Cross Cooper Holmes Sharpe Morgan Hoyle Allen Rich Rich Grant Proctor Diaz Graham Watkins Hinton Marsh Hewitt Branch Walton O'Brien Case Watts Christensen Parks Hardin Lucas Eason Davidson Whitehead Rose Sparks Moore Pearson Rodgers Graves Scarborough Sutton Sinclair Bowman Olsen Love McLean Christian Lamb James Chandler Stout Cowan Golden Bowling Beasley Clapp Abrams Tilley Morse Boykin Sumner Cassidy Davidson Heath Blanchard McAllister McKenzie Byrne Schroeder Griffin Gross Perkins Robertson Palmer Brady Rowe Zhang Hodge Li Bowling Justice Glass Willis Hester Floyd Graves Fischer Norman Chan Hunt Byrd Lane Kaplan Heller May Jennings Hanna Locklear Holloway Jones Glover Vick O'Donnell Goldman McKenna Starr Stone McClure Watson Monroe Abbott Singer Hall Farrell Lucas Norman Atkins Monroe Robertson Sykes Reid Chandler Finch Hobbs Adkins Kinney Whitaker Alexander Conner Waters Becker Rollins Love Adkins Black Fox Hatcher Wu Lloyd Joyce Welch Matthews Chappell MacDonald Kane Butler Pickett Bowman Barton Kennedy Branch Thornton McNeill Weinstein Middleton Moss Lucas Rich Carlton Brady Schultz Nichols Harvey Stevenson Houston Dunn West O'Brien Barr Snyder Cain Heath Boswell Olsen Pittman Weiner Petersen Davis Coleman Terrell Norman Burch Weiner Parrott Henry Gray Chang McLean Eason Weeks Siegel Puckett Heath Hoyle Garrett Neal Baker Goldman Shaffer Choi Carver)
|
55
88
|
names[rand(names.size)]
|
56
89
|
end
|
90
|
+
end
|
57
91
|
|
58
|
-
|
92
|
+
def email(replacement = nil)
|
93
|
+
if @environment == :output && replacement
|
94
|
+
replacement
|
95
|
+
else
|
59
96
|
delimiters = ['_','-','']
|
60
97
|
domains = %w(gmail.com yahoo.com hotmail.com email.com live.com me.com mac.com aol.com fastmail.com mail.com)
|
61
98
|
username = name.gsub(/[^\w]/, delimiters[rand(delimiters.size)])
|
62
99
|
"#{username}@#{domains[rand(domains.size)]}".downcase
|
63
100
|
end
|
64
|
-
|
65
|
-
|
101
|
+
end
|
102
|
+
|
103
|
+
def image(width, height, random=false, replacement=nil)
|
104
|
+
if @environment == :output && replacement
|
105
|
+
replacement
|
106
|
+
else
|
66
107
|
if defined? MiniMagick
|
67
108
|
"/_img/#{width.to_s}x#{height.to_s}.jpg#{'?random' + (10000 + rand(10000)).to_s if random}"
|
68
109
|
else
|
69
110
|
raise Frank::ConfigError, 'mini_magick is required for lorem.image, please install it with `gem install mini_magick`'
|
70
111
|
end
|
71
112
|
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
def randm(range)
|
76
|
-
a = range.to_a
|
77
|
-
a[rand(a.length)]
|
78
|
-
end
|
79
|
-
|
80
113
|
end
|
114
|
+
|
115
|
+
private
|
116
|
+
|
117
|
+
def randm(range)
|
118
|
+
a = range.to_a
|
119
|
+
a[rand(a.length)]
|
120
|
+
end
|
121
|
+
|
81
122
|
end
|
82
123
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Frank
|
2
|
+
module Middleware
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'mini_magick'
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
|
9
|
+
class Imager
|
10
|
+
|
11
|
+
def initialize(app, options={})
|
12
|
+
@app = app
|
13
|
+
end
|
14
|
+
|
15
|
+
# choose a random image if random is in the query
|
16
|
+
def image_filename(dims, query)
|
17
|
+
if query.include?('random')
|
18
|
+
"frank#{rand(10)}.jpg"
|
19
|
+
else
|
20
|
+
"frank#{dims.hash.to_s[-1..-1]}.jpg"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# catch a request for _img/0x0, get an image, resize it to given dims
|
25
|
+
def call(env)
|
26
|
+
path = env['PATH_INFO']
|
27
|
+
image_path = File.expand_path(File.dirname(__FILE__)) + '/templates/imager/'
|
28
|
+
|
29
|
+
if defined?(MiniMagick) && path.include?('_img')
|
30
|
+
dims = '!' + path.split('/').last.match(/\d+x\d+/i).to_s
|
31
|
+
filename = image_filename(dims, env['QUERY_STRING'])
|
32
|
+
|
33
|
+
image = MiniMagick::Image.from_file(image_path + filename)
|
34
|
+
image.resize dims
|
35
|
+
return [ 200, { 'Content-Type' => 'image/jpg' }, image.to_blob ]
|
36
|
+
end
|
37
|
+
@app.call(env)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Frank
|
2
|
+
module Middleware
|
3
|
+
class Refresh
|
4
|
+
|
5
|
+
def initialize(app, options={})
|
6
|
+
@app = app
|
7
|
+
@folders = options[:watch]
|
8
|
+
end
|
9
|
+
|
10
|
+
# catch __refrank__ path and
|
11
|
+
# return the most recent timestamp
|
12
|
+
def call(env)
|
13
|
+
request = Rack::Request.new(env)
|
14
|
+
if request.path_info.match /^\/__refresh__$/
|
15
|
+
[ 200, { 'Content-Type' => 'application/json' }, "[#{get_mtime}]" ]
|
16
|
+
else
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# build list of mtimes for watched files
|
25
|
+
# return the most recent
|
26
|
+
def get_mtime
|
27
|
+
pwd = Dir.pwd
|
28
|
+
timestamps = []
|
29
|
+
helpers = File.join(pwd, 'helpers.rb')
|
30
|
+
|
31
|
+
timestamps << File.mtime(helpers).to_i if File.exist? helpers
|
32
|
+
@folders.each do |folder|
|
33
|
+
Dir[File.join(pwd, folder, '**/*.*')].each do |found|
|
34
|
+
timestamps << File.mtime(found).to_i unless File.directory?(found)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
timestamps.sort.last
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Frank
|
2
|
+
module Middleware
|
3
|
+
class Statik
|
4
|
+
|
5
|
+
def initialize(app, options={})
|
6
|
+
@app = app
|
7
|
+
frank_root = File.expand_path(File.dirname(File.dirname(__FILE__))) + '/templates'
|
8
|
+
root = options[:root] || Dir.pwd
|
9
|
+
@frank_server = Rack::File.new(frank_root)
|
10
|
+
@static_server = Rack::File.new(root)
|
11
|
+
end
|
12
|
+
|
13
|
+
# handles serving from __frank__
|
14
|
+
# looks for static access, if not found,
|
15
|
+
# passes request to frank
|
16
|
+
def call(env)
|
17
|
+
path = env['PATH_INFO'].dup
|
18
|
+
|
19
|
+
if path.include? '__frank__'
|
20
|
+
env['PATH_INFO'].gsub!('/__frank__', '')
|
21
|
+
result = @frank_server.call(env)
|
22
|
+
else
|
23
|
+
env['PATH_INFO'] << '/' unless path.match(/(\.\w+|\/)$/)
|
24
|
+
env['PATH_INFO'] << 'index.html' if path[-1..-1] == '/'
|
25
|
+
result = @static_server.call(env)
|
26
|
+
end
|
27
|
+
|
28
|
+
# return if static assets found
|
29
|
+
# else reset the path and pass to frank
|
30
|
+
if result[0] == 200
|
31
|
+
result
|
32
|
+
else
|
33
|
+
env['PATH_INFO'] = path
|
34
|
+
@app.call(env)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/frank/output.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'find'
|
2
|
-
|
3
1
|
module Frank
|
4
2
|
class Output < Frank::Base
|
5
3
|
include Frank::Render
|
@@ -10,46 +8,36 @@ module Frank
|
|
10
8
|
instance_eval &block
|
11
9
|
end
|
12
10
|
|
13
|
-
#
|
14
|
-
|
11
|
+
# compile the templates
|
12
|
+
# if production and template isn't index and is html
|
13
|
+
# name a folder based on the template and compile to index.html
|
14
|
+
# otherwise compile as is
|
15
|
+
def compile_templates(production)
|
15
16
|
dir = File.join(@proj_dir, @dynamic_folder)
|
16
|
-
layouts = templates['layouts'].map { |l| l['name'] }
|
17
17
|
|
18
|
-
|
19
|
-
if
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
name
|
24
|
-
|
25
|
-
new_ext
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
# if template isn't index or template doesn't compile to html
|
30
|
-
# then compile it as is, otherwise name a folder based on the template
|
31
|
-
# and compile to index.html
|
32
|
-
if "#{name}.#{new_ext}" == 'index.html' || new_ext != 'html'
|
33
|
-
new_file = File.join(@output_folder, "#{name}.#{new_ext}")
|
34
|
-
else
|
35
|
-
new_file = File.join(@output_folder, name, "index.#{new_ext}")
|
36
|
-
name = "#{name}/index"
|
37
|
-
end
|
38
|
-
create_dir(new_file)
|
39
|
-
File.open(new_file, 'w') {|f| f.write render_path(path) }
|
40
|
-
elsif options[:production] == false
|
41
|
-
new_file = File.join(@output_folder, "#{name}.#{new_ext}")
|
42
|
-
create_dir(new_file)
|
43
|
-
File.open(new_file, 'w') {|f| f.write render_path(path) }
|
18
|
+
Dir[File.join(dir, '**/*')].each do |path|
|
19
|
+
if File.file?(path) && !File.basename(path).match(/^(\.|_)/)
|
20
|
+
path = path[ (dir.size + 1)..-1 ]
|
21
|
+
ext = File.extname(path)
|
22
|
+
new_ext = ext_from_handler(ext)
|
23
|
+
name = File.basename(path, ext)
|
24
|
+
|
25
|
+
if production == true && "#{name}.#{new_ext}" != 'index.html' && new_ext == 'html'
|
26
|
+
new_file = File.join(@output_folder, path.sub(/(\/?[\w-]+)\.[\w-]+$/, "\\1/index.#{new_ext}"))
|
27
|
+
else
|
28
|
+
new_file = File.join(@output_folder, path.sub(/\.[\w-]+$/, ".#{new_ext}"))
|
44
29
|
end
|
45
|
-
|
30
|
+
|
31
|
+
create_dirs(new_file)
|
32
|
+
File.open(new_file, 'w') {|f| f.write render(path) }
|
33
|
+
puts " - \033[32mCreating\033[0m '#{new_file}'"
|
46
34
|
end
|
47
35
|
end
|
48
36
|
end
|
49
37
|
|
50
38
|
# use path to determine folder name and
|
51
|
-
# create the required
|
52
|
-
def
|
39
|
+
# create the required folders if they don't exist
|
40
|
+
def create_dirs(path)
|
53
41
|
FileUtils.makedirs path.split('/').reverse[1..-1].reverse.join('/')
|
54
42
|
end
|
55
43
|
|
@@ -61,15 +49,15 @@ module Frank
|
|
61
49
|
end
|
62
50
|
|
63
51
|
# create the dump dir, compile templates, copy over static assets
|
64
|
-
def dump(
|
52
|
+
def dump(production = false)
|
65
53
|
FileUtils.mkdir(@output_folder)
|
66
54
|
puts "\nFrank is..."
|
67
55
|
puts " - \033[32mCreating\033[0m '#{@output_folder}'"
|
68
56
|
|
69
|
-
compile_templates(
|
57
|
+
compile_templates(production)
|
70
58
|
copy_static
|
71
59
|
puts "\n \033[32mCongratulations, project dumped to '#{@output_folder}' successfully!\033[0m"
|
72
60
|
end
|
73
61
|
end
|
74
62
|
|
75
|
-
end
|
63
|
+
end
|
data/lib/frank/rescue.rb
CHANGED
@@ -9,19 +9,26 @@ module Frank
|
|
9
9
|
:environment => @environment }
|
10
10
|
|
11
11
|
@response['Content-Type'] = 'text/html'
|
12
|
-
@response.status
|
13
|
-
|
12
|
+
@response.status = 404
|
13
|
+
obj = Object.new.extend(TemplateHelpers)
|
14
|
+
@response.body = Tilt::HamlTemplate.new(template).render(obj, locals = locals)
|
15
|
+
|
14
16
|
log_request('404')
|
15
17
|
end
|
16
18
|
|
17
19
|
def render_500(excp)
|
18
20
|
template = File.expand_path(File.dirname(__FILE__)) + '/templates/500.haml'
|
19
|
-
locals
|
21
|
+
locals = { :request => @env,
|
22
|
+
:params => @request.params,
|
23
|
+
:exception => excp }
|
20
24
|
|
21
25
|
@response['Content-Type'] = 'text/html'
|
22
|
-
@response.status
|
23
|
-
|
26
|
+
@response.status = 500
|
27
|
+
obj = Object.new.extend(TemplateHelpers)
|
28
|
+
@response.body = Tilt::HamlTemplate.new(template).render(obj, locals = locals)
|
29
|
+
|
24
30
|
log_request('500', excp)
|
25
31
|
end
|
32
|
+
|
26
33
|
end
|
27
|
-
end
|
34
|
+
end
|
@@ -7,12 +7,43 @@ module Frank
|
|
7
7
|
def render_partial(path)
|
8
8
|
pieces = path.split('/')
|
9
9
|
partial = '_' + pieces.pop
|
10
|
-
|
10
|
+
render(File.join(pieces.join('/'), partial))
|
11
11
|
end
|
12
12
|
|
13
13
|
def lorem
|
14
|
-
Frank::Lorem
|
14
|
+
Frank::Lorem.new(@environment)
|
15
|
+
end
|
16
|
+
|
17
|
+
def refresh
|
18
|
+
if @environment == :output || @environment == :production
|
19
|
+
nil
|
20
|
+
else
|
21
|
+
<<-JS
|
22
|
+
<script type="text/javascript">
|
23
|
+
(function(){
|
24
|
+
var when = #{Time.now.to_i};
|
25
|
+
|
26
|
+
function process( raw ){
|
27
|
+
if( eval(raw)[0] > when )
|
28
|
+
window.location.reload();
|
29
|
+
}
|
30
|
+
|
31
|
+
(function poll(){
|
32
|
+
var req = new XMLHttpRequest();
|
33
|
+
req.open('GET', '/__refresh__', true);
|
34
|
+
req.onreadystatechange = function (aEvt) {
|
35
|
+
if ( req.readyState == 4 && req.status == 200 )
|
36
|
+
process(req.responseText);
|
37
|
+
};
|
38
|
+
req.send(null);
|
39
|
+
setTimeout( poll, 1000 );
|
40
|
+
})();
|
41
|
+
|
42
|
+
})();
|
43
|
+
</script>
|
44
|
+
JS
|
45
|
+
end
|
15
46
|
end
|
16
47
|
|
17
48
|
end
|
18
|
-
end
|
49
|
+
end
|