frank 0.2.6 → 0.3.0.beta

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.
Files changed (64) hide show
  1. data/Featurelist +6 -0
  2. data/README.md +44 -32
  3. data/Rakefile +3 -3
  4. data/frank.gemspec +51 -45
  5. data/lib/frank.rb +1 -0
  6. data/lib/frank/base.rb +144 -94
  7. data/lib/frank/lorem.rb +77 -36
  8. data/lib/frank/middleware/imager.rb +43 -0
  9. data/lib/frank/middleware/refresh.rb +42 -0
  10. data/lib/frank/middleware/statik.rb +41 -0
  11. data/lib/frank/output.rb +25 -37
  12. data/lib/frank/rescue.rb +13 -6
  13. data/lib/frank/template_helpers.rb +34 -3
  14. data/lib/frank/templates/404.haml +1 -0
  15. data/lib/frank/templates/500.haml +2 -0
  16. data/lib/frank/tilt.rb +389 -141
  17. data/lib/template/{dynamic/layout.haml → layouts/default.haml} +0 -0
  18. data/lib/template/settings.yml +15 -28
  19. data/spec/base_spec.rb +88 -0
  20. data/{test → spec}/helper.rb +0 -7
  21. data/spec/output_spec.rb +220 -0
  22. data/spec/render_spec.rb +106 -0
  23. data/spec/template/dynamic/500.haml +1 -0
  24. data/{test → spec}/template/dynamic/_partial.haml +0 -0
  25. data/{test → spec}/template/dynamic/builder.builder +0 -0
  26. data/{test → spec}/template/dynamic/coffee.coffee +0 -0
  27. data/{test → spec}/template/dynamic/erb.erb +0 -0
  28. data/{test → spec}/template/dynamic/helper_test.haml +0 -0
  29. data/spec/template/dynamic/index.haml +5 -0
  30. data/spec/template/dynamic/layout2_test.haml +4 -0
  31. data/{test → spec}/template/dynamic/liquid.liquid +0 -0
  32. data/spec/template/dynamic/lorem_test.haml +7 -0
  33. data/{test → spec}/template/dynamic/markdown.md +0 -0
  34. data/spec/template/dynamic/markdown_in_haml.md +4 -0
  35. data/{test → spec}/template/dynamic/mustache.mustache +0 -0
  36. data/spec/template/dynamic/nested/child.haml +1 -0
  37. data/spec/template/dynamic/nested/deeper/deep.haml +1 -0
  38. data/spec/template/dynamic/no_layout.haml +4 -0
  39. data/spec/template/dynamic/partial_test.haml +2 -0
  40. data/{test → spec}/template/dynamic/redcloth.textile +0 -0
  41. data/spec/template/dynamic/refresh.haml +1 -0
  42. data/{test → spec}/template/dynamic/sass.sass +0 -0
  43. data/{test → spec}/template/helpers.rb +0 -0
  44. data/spec/template/layouts/default.haml +3 -0
  45. data/{test/template/dynamic → spec/template/layouts/explicit}/layout2.haml +0 -0
  46. data/spec/template/layouts/nested/default.haml +2 -0
  47. data/spec/template/settings.yml +45 -0
  48. data/{test/template/static → spec/template/static/files}/static.html +0 -0
  49. data/spec/template_helpers_spec.rb +78 -0
  50. metadata +57 -49
  51. data/lib/frank/imager.rb +0 -39
  52. data/lib/frank/statik.rb +0 -39
  53. data/test/suite.rb +0 -4
  54. data/test/template/dynamic/index.haml +0 -2
  55. data/test/template/dynamic/layout.haml +0 -2
  56. data/test/template/dynamic/layout2_test.haml +0 -1
  57. data/test/template/dynamic/layout_test.haml +0 -1
  58. data/test/template/dynamic/lorem_test.haml +0 -7
  59. data/test/template/dynamic/partial_test.haml +0 -2
  60. data/test/template/settings.yml +0 -62
  61. data/test/test_base.rb +0 -81
  62. data/test/test_helpers.rb +0 -71
  63. data/test/test_output.rb +0 -160
  64. data/test/test_render.rb +0 -89
@@ -0,0 +1 @@
1
+ = non_method if @environment == :test
File without changes
@@ -0,0 +1,5 @@
1
+ title: hello worlds
2
+ META---------------------------------
3
+
4
+ %h1= title
5
+ %h2= current_path
@@ -0,0 +1,4 @@
1
+ layout: explicit/layout2.haml
2
+ META--------------------
3
+
4
+ %h1 hi inside layout2
@@ -0,0 +1,7 @@
1
+ %p.words= lorem.words 3, 'replace-this'
2
+ %p.sentences= lorem.sentences 2, 'replace-this'
3
+ %p.paragraphs= lorem.paragraphs 1, 'replace-this'
4
+ %p.date= lorem.date '%Y-%m-%d', 'replace-this'
5
+ %p.name= lorem.name 'replace-this'
6
+ %p.email= lorem.email 'replace-this'
7
+ %img{:src => lorem.image(400, 300, true, 'replace-this')}
@@ -0,0 +1,4 @@
1
+ layout: default.haml
2
+ META--------------------
3
+
4
+ # hi inside layout
@@ -0,0 +1 @@
1
+ %h1 hello from child
@@ -0,0 +1 @@
1
+ %h1 really deep
@@ -0,0 +1,4 @@
1
+ layout: nil
2
+ META-------------------
3
+
4
+ %h1 i have no layout
@@ -0,0 +1,2 @@
1
+ %h1 hello worlds
2
+ = render_partial('partial.haml')
@@ -0,0 +1 @@
1
+ =refresh
File without changes
@@ -0,0 +1,3 @@
1
+ #p= current_path
2
+ #layout
3
+ = yield
@@ -0,0 +1,2 @@
1
+ #nested_layout
2
+ = yield
@@ -0,0 +1,45 @@
1
+ env: test
2
+ # ----------------------
3
+ # Server settings:
4
+ #
5
+ # Change the server host/port to bind rack to.
6
+ # 'server' can be any Rack-supported server, e.g.
7
+ # Mongrel, Thin, WEBrick
8
+ #
9
+ server:
10
+ handler: mongrel
11
+ hostname: 0.0.0.0
12
+ port: 3601
13
+
14
+ # ----------------------
15
+ # Static folder:
16
+ #
17
+ # All files in this folder will be served up
18
+ # directly, without interpretation
19
+ #
20
+ static_folder: static
21
+
22
+ # ----------------------
23
+ # Dynamic folder:
24
+ #
25
+ # Frank will try to interpret any of the files
26
+ # in this folder based on their extension
27
+ #
28
+ dynamic_folder: dynamic
29
+
30
+ # ----------------------
31
+ # Layouts folder:
32
+ #
33
+ # Frank will look for layouts in this folder
34
+ # the default layout is `default'
35
+ # it respects nested layouts that correspond to nested
36
+ # folders in the `dynamic_folder'
37
+ # for example: a template: `dynamic_folder/blog/a-blog-post.haml'
38
+ # would look for a layout: `layouts/blog/default.haml'
39
+ # and if not found use the default: `layouts/default.haml'
40
+ #
41
+ # Frank also supports defining layouts on an
42
+ # individual template basis using meta data
43
+ # you can do this by defining a meta field `layout: my_layout.haml'
44
+ #
45
+ layouts_folder: layouts
@@ -0,0 +1,78 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ describe Frank::TemplateHelpers do
4
+ include Rack::Test::Methods
5
+
6
+ def app
7
+ proj_dir = File.join(File.dirname(__FILE__), 'template')
8
+ settings = YAML.load_file(File.join(proj_dir, 'settings.yml'))
9
+ require File.join(proj_dir, 'helpers')
10
+ Frank.new do
11
+ settings.each do |name, value|
12
+ set name.to_s, value
13
+ end
14
+ set :environment, :test
15
+ set :proj_dir, proj_dir
16
+ end
17
+ end
18
+
19
+ before(:all) do
20
+ @app = app
21
+ end
22
+
23
+ it 'render haml and use hello_helper' do
24
+ template = @app.render('helper_test.haml')
25
+ template.should == "<div id='p'>/helper_test</div>\n<div id='layout'>\n <h1>hello from helper</h1>\n</div>\n"
26
+ end
27
+
28
+ it 'should render the refresh javascript' do
29
+ template = @app.render('refresh.haml')
30
+ template.should include("<script type=\"text/javascript\">\n (function(){")
31
+ end
32
+
33
+ context 'Lorem' do
34
+ it 'render haml with 3 random lorem words' do
35
+ template = @app.render('lorem_test.haml')
36
+ reg = /<p class='words'>(?:\w+\s?){3}<\/p>/
37
+ template.should =~ reg
38
+ end
39
+
40
+ it 'render haml with 2 random lorem sentences' do
41
+ template = @app.render('lorem_test.haml')
42
+ reg = /<p class='sentences'>(?:[^.]+.){2}<\/p>/
43
+ template.should =~ reg
44
+ end
45
+
46
+ it 'render haml with 1 random lorem paragraph' do
47
+ template = @app.render('lorem_test.haml')
48
+ reg = /<p class='paragraphs'>(?:[^\n]+(?:\n\n)?){1}<\/p>/m
49
+ template.should =~ reg
50
+ end
51
+
52
+ it 'render haml with lorem name' do
53
+ template = @app.render('lorem_test.haml')
54
+ reg = /<p class='name'>[\w']+\s[\w']+<\/p>/m
55
+ template.should =~ reg
56
+ end
57
+
58
+ it 'render haml with lorem email' do
59
+ template = @app.render('lorem_test.haml')
60
+ reg = /<p class='email'>[\w-]+@\w+\.\w+<\/p>/m
61
+ template.should =~ reg
62
+ end
63
+
64
+ it 'render haml with lorem date' do
65
+ template = @app.render('lorem_test.haml')
66
+ reg = /<p class='date'>\d{4}-\d{2}-\d{2}<\/p>/m
67
+ template.should =~ reg
68
+ end
69
+
70
+ it 'render image url using imager' do
71
+ template = @app.render('lorem_test.haml')
72
+ reg = /<img src='\/_img\/400x300.jpg\?random\d{5}' \/>/
73
+ template.should =~ reg
74
+ end
75
+ end
76
+
77
+ end
78
+
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frank
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ prerelease: true
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 6
9
- version: 0.2.6
7
+ - 3
8
+ - 0
9
+ - beta
10
+ version: 0.3.0.beta
10
11
  platform: ruby
11
12
  authors:
12
13
  - blahed
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-04-14 00:00:00 -04:00
19
+ date: 2010-06-12 00:00:00 -04:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
@@ -58,16 +59,15 @@ dependencies:
58
59
  type: :runtime
59
60
  version_requirements: *id003
60
61
  - !ruby/object:Gem::Dependency
61
- name: shoulda
62
+ name: rspec
62
63
  prerelease: false
63
64
  requirement: &id004 !ruby/object:Gem::Requirement
64
65
  requirements:
65
66
  - - ">="
66
67
  - !ruby/object:Gem::Version
67
68
  segments:
68
- - 2
69
69
  - 0
70
- version: "2.0"
70
+ version: "0"
71
71
  type: :development
72
72
  version_requirements: *id004
73
73
  - !ruby/object:Gem::Dependency
@@ -83,7 +83,7 @@ dependencies:
83
83
  version: "0.5"
84
84
  type: :development
85
85
  version_requirements: *id005
86
- description: Create/Dump static builds using whatever templating/helper languages you wish
86
+ description: Rapidly develop static sites using any supported templating language
87
87
  email: travis.dunn@thisismedium.com
88
88
  executables:
89
89
  - frank
@@ -96,6 +96,7 @@ extra_rdoc_files:
96
96
  - README.md
97
97
  files:
98
98
  - .gitignore
99
+ - Featurelist
99
100
  - LICENSE
100
101
  - README.md
101
102
  - Rakefile
@@ -105,11 +106,12 @@ files:
105
106
  - frank.gemspec
106
107
  - lib/frank.rb
107
108
  - lib/frank/base.rb
108
- - lib/frank/imager.rb
109
109
  - lib/frank/lorem.rb
110
+ - lib/frank/middleware/imager.rb
111
+ - lib/frank/middleware/refresh.rb
112
+ - lib/frank/middleware/statik.rb
110
113
  - lib/frank/output.rb
111
114
  - lib/frank/rescue.rb
112
- - lib/frank/statik.rb
113
115
  - lib/frank/template_helpers.rb
114
116
  - lib/frank/templates/404.haml
115
117
  - lib/frank/templates/500.haml
@@ -128,37 +130,42 @@ files:
128
130
  - lib/frank/tilt.rb
129
131
  - lib/template/dynamic/css/frank.sass
130
132
  - lib/template/dynamic/index.haml
131
- - lib/template/dynamic/layout.haml
132
133
  - lib/template/helpers.rb
134
+ - lib/template/layouts/default.haml
133
135
  - lib/template/settings.yml
134
136
  - lib/template/static/images/frank-med.png
135
137
  - lib/template/static/js/frank.js
136
- - test/helper.rb
137
- - test/suite.rb
138
- - test/template/dynamic/_partial.haml
139
- - test/template/dynamic/builder.builder
140
- - test/template/dynamic/coffee.coffee
141
- - test/template/dynamic/erb.erb
142
- - test/template/dynamic/helper_test.haml
143
- - test/template/dynamic/index.haml
144
- - test/template/dynamic/layout.haml
145
- - test/template/dynamic/layout2.haml
146
- - test/template/dynamic/layout2_test.haml
147
- - test/template/dynamic/layout_test.haml
148
- - test/template/dynamic/liquid.liquid
149
- - test/template/dynamic/lorem_test.haml
150
- - test/template/dynamic/markdown.md
151
- - test/template/dynamic/mustache.mustache
152
- - test/template/dynamic/partial_test.haml
153
- - test/template/dynamic/redcloth.textile
154
- - test/template/dynamic/sass.sass
155
- - test/template/helpers.rb
156
- - test/template/settings.yml
157
- - test/template/static/static.html
158
- - test/test_base.rb
159
- - test/test_helpers.rb
160
- - test/test_output.rb
161
- - test/test_render.rb
138
+ - spec/base_spec.rb
139
+ - spec/helper.rb
140
+ - spec/output_spec.rb
141
+ - spec/render_spec.rb
142
+ - spec/template/dynamic/500.haml
143
+ - spec/template/dynamic/_partial.haml
144
+ - spec/template/dynamic/builder.builder
145
+ - spec/template/dynamic/coffee.coffee
146
+ - spec/template/dynamic/erb.erb
147
+ - spec/template/dynamic/helper_test.haml
148
+ - spec/template/dynamic/index.haml
149
+ - spec/template/dynamic/layout2_test.haml
150
+ - spec/template/dynamic/liquid.liquid
151
+ - spec/template/dynamic/lorem_test.haml
152
+ - spec/template/dynamic/markdown.md
153
+ - spec/template/dynamic/markdown_in_haml.md
154
+ - spec/template/dynamic/mustache.mustache
155
+ - spec/template/dynamic/nested/child.haml
156
+ - spec/template/dynamic/nested/deeper/deep.haml
157
+ - spec/template/dynamic/no_layout.haml
158
+ - spec/template/dynamic/partial_test.haml
159
+ - spec/template/dynamic/redcloth.textile
160
+ - spec/template/dynamic/refresh.haml
161
+ - spec/template/dynamic/sass.sass
162
+ - spec/template/helpers.rb
163
+ - spec/template/layouts/default.haml
164
+ - spec/template/layouts/explicit/layout2.haml
165
+ - spec/template/layouts/nested/default.haml
166
+ - spec/template/settings.yml
167
+ - spec/template/static/files/static.html
168
+ - spec/template_helpers_spec.rb
162
169
  has_rdoc: true
163
170
  homepage: http://github.com/blahed/frank
164
171
  licenses: []
@@ -177,23 +184,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
184
  version: "0"
178
185
  required_rubygems_version: !ruby/object:Gem::Requirement
179
186
  requirements:
180
- - - ">="
187
+ - - ">"
181
188
  - !ruby/object:Gem::Version
182
189
  segments:
183
- - 0
184
- version: "0"
190
+ - 1
191
+ - 3
192
+ - 1
193
+ version: 1.3.1
185
194
  requirements: []
186
195
 
187
196
  rubyforge_project:
188
197
  rubygems_version: 1.3.6
189
198
  signing_key:
190
199
  specification_version: 3
191
- summary: Stupidly Simple Static Slinger
200
+ summary: Static Site Non-Framework
192
201
  test_files:
193
- - test/helper.rb
194
- - test/suite.rb
195
- - test/template/helpers.rb
196
- - test/test_base.rb
197
- - test/test_helpers.rb
198
- - test/test_output.rb
199
- - test/test_render.rb
202
+ - spec/base_spec.rb
203
+ - spec/helper.rb
204
+ - spec/output_spec.rb
205
+ - spec/render_spec.rb
206
+ - spec/template/helpers.rb
207
+ - spec/template_helpers_spec.rb
@@ -1,39 +0,0 @@
1
- module Frank
2
- begin
3
- require 'mini_magick'
4
- rescue LoadError
5
- end
6
-
7
- class Imager
8
-
9
- def initialize(app, options={})
10
- @app = app
11
- end
12
-
13
- # choose a random image if random is in the query
14
- def image_filename(dims, query)
15
- if query.include?('random')
16
- "frank#{rand(10)}.jpg"
17
- else
18
- "frank#{dims.hash.to_s[-1..-1]}.jpg"
19
- end
20
- end
21
-
22
- # catch a request for _img/0x0, get an image, resize it to given dims
23
- def call(env)
24
- path = env['PATH_INFO']
25
- image_path = File.expand_path(File.dirname(__FILE__)) + '/templates/imager/'
26
-
27
- if defined?(MiniMagick) && path.include?('_img')
28
- dims = '!' + path.split('/').last.match(/\d+x\d+/i).to_s
29
- filename = image_filename(dims, env['QUERY_STRING'])
30
-
31
- image = MiniMagick::Image.from_file(image_path + filename)
32
- image.resize dims
33
- return [ 200, { 'Content-Type' => 'image/jpg' }, image.to_blob ]
34
- end
35
- @app.call(env)
36
- end
37
-
38
- end
39
- end
@@ -1,39 +0,0 @@
1
- module Frank
2
- class Statik
3
-
4
- def initialize(app, options={})
5
- @app = app
6
- frank_root = File.expand_path(File.dirname(__FILE__)) + '/templates'
7
- root = options[:root] || Dir.pwd
8
- @frank_server = Rack::File.new(frank_root)
9
- @static_server = Rack::File.new(root)
10
- end
11
-
12
- # handles serving from __frank__
13
- # looks for static access, if not found,
14
- # passes request to frank
15
- def call(env)
16
- path = env['PATH_INFO'].dup
17
-
18
- if path.include? '__frank__'
19
- env['PATH_INFO'].gsub!('/__frank__', '')
20
- result = @frank_server.call(env)
21
- else
22
- env['PATH_INFO'] << '/' unless path.match(/(\.\w+|\/)$/)
23
- env['PATH_INFO'] << 'index.html' if path[-1..-1] == '/'
24
- result = @static_server.call(env)
25
- end
26
-
27
- # return if static assets found
28
- # else reset the path and pass to frank
29
- if result[0] == 200
30
- result
31
- else
32
- env['PATH_INFO'] = path
33
- @app.call(env)
34
- end
35
-
36
- end
37
-
38
- end
39
- end