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.
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
@@ -1,4 +0,0 @@
1
- tests = Dir["#{File.dirname(__FILE__)}/test_*.rb"]
2
- tests.each do |file|
3
- require file
4
- end
@@ -1,2 +0,0 @@
1
- %h1= 'hello worlds'
2
- = non_method if defined?(params) && params['brok']
@@ -1,2 +0,0 @@
1
- #layout
2
- = yield
@@ -1 +0,0 @@
1
- %h1 hi inside layout2
@@ -1 +0,0 @@
1
- %h1 hi inside layout
@@ -1,7 +0,0 @@
1
- %p.words= lorem.words 3
2
- %p.sentences= lorem.sentences 2
3
- %p.paragraphs= lorem.paragraphs 1
4
- %p.date= lorem.date('%Y-%m-%d')
5
- %p.name= lorem.name
6
- %p.email= lorem.email
7
- %img{:src => lorem.image(400, 300, true)}
@@ -1,2 +0,0 @@
1
- %h1 hello worlds
2
- = render_partial('partial')
@@ -1,62 +0,0 @@
1
- # -----------------------------------------------
2
- # Frank settings:
3
- #
4
- # These settings will apply to this project only.
5
- # If you would like to use this project as a
6
- # template for new projects, just copy this
7
- # project folder to `~/.frank` and it will be
8
- # duplicated for you every time you run the
9
- # `frank` command.
10
- #
11
- # Feel free to trash all these comments, too.
12
- #
13
-
14
- env: test
15
-
16
- # ----------------------
17
- # Server settings:
18
- #
19
- # Change the server host/port to bind rack to.
20
- # 'server' can be any Rack-supported server, e.g.
21
- # Mongrel, Thin, WEBrick
22
- #
23
- server:
24
- handler: mongrel
25
- hostname: localhost
26
- port: 3601
27
-
28
-
29
- # ----------------------
30
- # Static folder:
31
- #
32
- # All files in this folder will be served up
33
- # directly, without interpretation
34
- #
35
- static_folder: static
36
-
37
- # ----------------------
38
- # Dynamic folder:
39
- #
40
- # Frank will try to interpret any of the files
41
- # in this folder based on their extension
42
- #
43
- dynamic_folder: dynamic
44
-
45
- # ----------------------
46
- # Templates:
47
- #
48
- # 'layouts' is a list of layouts to use, where
49
- # 'name' is the filename (without extension).
50
- # You can also use multiple layouts, and limit
51
- # their scopes like so:
52
- # - name: blog_layout
53
- # only: [blog]
54
- # - name: normal
55
- # not: [blog, ajax]
56
- templates:
57
- layouts:
58
- - name: layout
59
- not: [builder, erb, liquid, markdown, mustache, redcloth]
60
- - name: layout2
61
- only: [layout2_test]
62
-
@@ -1,81 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestBase < Test::Unit::TestCase
4
-
5
- def app
6
- proj_dir = File.join(File.dirname(__FILE__), 'template')
7
- settings = YAML.load_file(File.join(proj_dir, 'settings.yml'))
8
- Frank.new do
9
- settings.each do |name, value|
10
- set name.to_s, value
11
- end
12
- set :environment, :test
13
- set :proj_dir, proj_dir
14
- end
15
- end
16
-
17
- context 'Frank::Base' do
18
-
19
- should 'have all required settings set' do
20
- assert_not_nil app.proj_dir
21
- assert_not_nil app.server
22
- assert_not_nil app.static_folder
23
- assert_not_nil app.dynamic_folder
24
- assert_not_nil app.templates
25
- end
26
-
27
- should 'render a dynamic template given a request' do
28
- get '/'
29
-
30
- assert last_response.ok?
31
- assert_equal "<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n", last_response.body
32
- end
33
-
34
- should 'render a dynamic css without a layout' do
35
- get '/sass.css'
36
-
37
- assert last_response.ok?
38
- assert_equal "#hello-worlds {\n background: red; }\n", last_response.body
39
- end
40
-
41
- should 'render a dynamic javascript without a layout' do
42
- get '/coffee.js'
43
-
44
- assert last_response.ok?
45
- assert_equal "(function(){\n var greeting;\n greeting = \"Hello CoffeeScript\";\n})();", last_response.body
46
- end
47
-
48
- should 'render 404 page if template not found' do
49
- get '/not_here.css'
50
-
51
- assert !last_response.ok?
52
- assert_equal 'text/html', last_response.content_type
53
- assert_match 'Not Found', last_response.body
54
- end
55
-
56
- should 'render 500 page for error' do
57
- get '/?brok=en'
58
-
59
- assert !last_response.ok?
60
- assert_equal 'text/html', last_response.content_type
61
- assert_match "undefined local variable or method `non_method'", last_response.body
62
- end
63
-
64
- end
65
-
66
- context 'Frank.stub' do
67
-
68
- should 'stub out a project' do
69
- out = capture_stdout { Frank.stub('stubbed') }
70
- assert_equal Dir.entries('stubbed'), Dir.entries(File.join(LIBDIR, 'template'))
71
- putss = "\nFrank is...\n - \e[32mCreating\e[0m your project 'stubbed'\n - \e[32mCopying\e[0m Frank template\n\n \e[32mCongratulations, 'stubbed' is ready to go!\e[0m\n"
72
- assert_equal putss, out.string
73
- end
74
-
75
- teardown do
76
- FileUtils.rm_r File.join(Dir.pwd, 'stubbed')
77
- end
78
-
79
- end
80
-
81
- end
@@ -1,71 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestBase < Test::Unit::TestCase
4
-
5
- context 'Frank::TemplateHelpers' do
6
-
7
- setup do
8
- proj_dir = File.join(File.dirname(__FILE__), 'template')
9
- settings = YAML.load_file(File.join(proj_dir, 'settings.yml'))
10
- require File.join(proj_dir, 'helpers')
11
- @frank = Frank.new do
12
- settings.each do |name, value|
13
- set name.to_s, value
14
- end
15
- set :environment, :test
16
- set :proj_dir, proj_dir
17
- end
18
- end
19
-
20
- should 'render haml and use hello_helper' do
21
- template = @frank.render_path('helper_test.haml')
22
- assert_equal "<div id='layout'>\n <h1>hello from helper</h1>\n</div>\n", template
23
- end
24
-
25
- context 'Lorem' do
26
- should 'render haml with 3 random lorem words' do
27
- template = @frank.render_path('lorem_test.haml')
28
- reg = /<p class='words'>(?:\w+\s?){3}<\/p>/
29
- assert_match reg, template
30
- end
31
-
32
- should 'render haml with 2 random lorem sentences' do
33
- template = @frank.render_path('lorem_test.haml')
34
- reg = /<p class='sentences'>(?:[^.]+.){2}<\/p>/
35
- assert_match reg, template
36
- end
37
-
38
- should 'render haml with 1 random lorem paragraph' do
39
- template = @frank.render_path('lorem_test.haml')
40
- reg = /<p class='paragraphs'>(?:[^\n]+(?:\n\n)?){1}<\/p>/m
41
- assert_match reg, template
42
- end
43
-
44
- should 'render haml with lorem name' do
45
- template = @frank.render_path('lorem_test.haml')
46
- reg = /<p class='name'>\w+\s\w+<\/p>/m
47
- assert_match reg, template
48
- end
49
-
50
- should 'render haml with lorem email' do
51
- template = @frank.render_path('lorem_test.haml')
52
- reg = /<p class='email'>[\w-]+@\w+\.\w+<\/p>/m
53
- assert_match reg, template
54
- end
55
-
56
- should 'render haml with lorem date' do
57
- template = @frank.render_path('lorem_test.haml')
58
- reg = /<p class='date'>\d{4}-\d{2}-\d{2}<\/p>/m
59
- assert_match reg, template
60
- end
61
-
62
- should 'render image url using imager' do
63
- template = @frank.render_path('lorem_test.haml')
64
- reg = /<img src='\/_img\/400x300.jpg\?random\d{5}' \/>/
65
- assert_match reg, template
66
- end
67
- end
68
-
69
- end
70
-
71
- end
@@ -1,160 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestBase < Test::Unit::TestCase
4
-
5
- context 'Frank::Output' do
6
-
7
- setup do
8
- proj_dir = File.join(File.dirname(__FILE__), 'template')
9
- settings = YAML.load_file(File.join(proj_dir, 'settings.yml'))
10
- require File.join(proj_dir, 'helpers')
11
- capture_stdout do
12
- @frank = Frank::Output.new do
13
- settings.each do |name, value|
14
- set name.to_s, value
15
- end
16
- set :environment, :test
17
- set :proj_dir, proj_dir
18
- set :output_folder, File.join(File.dirname(__FILE__), 'template/output')
19
- end.dump
20
- end
21
- end
22
-
23
- should 'create the output folder' do
24
- assert File.exist? File.join(File.dirname(__FILE__), 'template/output')
25
- end
26
-
27
- should 'create index.html' do
28
- output = File.join(File.dirname(__FILE__), 'template/output/index.html')
29
- assert_equal "<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n", IO.read(output)
30
- end
31
-
32
- should 'create partial_test.html' do
33
- output = File.join(File.dirname(__FILE__), 'template/output/partial_test.html')
34
- assert_equal "<div id='layout'>\n <h1>hello worlds</h1>\n <p>hello from partial</p>\n</div>\n", IO.read(output)
35
- end
36
-
37
- should 'create erb.html' do
38
- output = File.join(File.dirname(__FILE__), 'template/output/erb.html')
39
- assert_equal "<h1>hello worlds</h1>\n", IO.read(output)
40
- end
41
-
42
- should 'create redcloth.html' do
43
- output = File.join(File.dirname(__FILE__), 'template/output/redcloth.html')
44
- assert_equal "<h1>hello worlds</h1>", IO.read(output)
45
- end
46
-
47
- should 'create markdown.html' do
48
- output = File.join(File.dirname(__FILE__), 'template/output/markdown.html')
49
- assert_equal "<h1>hello worlds</h1>\n", IO.read(output)
50
- end
51
-
52
- should 'create mustache.html' do
53
- output = File.join(File.dirname(__FILE__), 'template/output/mustache.html')
54
- assert_equal "<h1>hello worlds</h1>\n", IO.read(output)
55
- end
56
-
57
- should 'create liquid.html' do
58
- output = File.join(File.dirname(__FILE__), 'template/output/liquid.html')
59
- assert_equal "<h1>hello worlds</h1>", IO.read(output)
60
- end
61
-
62
- should 'create builder.html' do
63
- output = File.join(File.dirname(__FILE__), 'template/output/builder.html')
64
- assert_equal "<h1>hello worlds</h1>\n", IO.read(output)
65
- end
66
-
67
- should 'copy static.html' do
68
- output = File.join(File.dirname(__FILE__), 'template/output/static.html')
69
- assert_equal "hello from static", IO.read(output)
70
- end
71
-
72
- should 'not create partials' do
73
- assert !File.exist?(File.join(File.dirname(__FILE__), 'template/output/_partial.html'))
74
- end
75
-
76
- teardown do
77
- FileUtils.rm_r File.join(File.dirname(__FILE__), 'template/output')
78
- end
79
- end
80
-
81
- context 'Frank::Output Production' do
82
-
83
- setup do
84
- proj_dir = File.join(File.dirname(__FILE__), 'template')
85
- settings = YAML.load_file(File.join(proj_dir, 'settings.yml'))
86
- require File.join(proj_dir, 'helpers')
87
-
88
- capture_stdout do
89
- @frank = Frank::Output.new do
90
- settings.each do |name, value|
91
- set name.to_s, value
92
- end
93
- set :environment, :test
94
- set :proj_dir, proj_dir
95
- set :output_folder, File.join(File.dirname(__FILE__), 'template/output')
96
- end.dump({:production => true})
97
- end
98
- end
99
-
100
- should 'create the output folder' do
101
- assert File.exist? File.join(File.dirname(__FILE__), 'template/output')
102
- end
103
-
104
- should 'create index.html' do
105
- output = File.join(File.dirname(__FILE__), 'template/output/index.html')
106
- assert_equal "<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n", IO.read(output)
107
- end
108
-
109
- should 'create partial_test.html' do
110
- output = File.join(File.dirname(__FILE__), 'template/output/partial_test/index.html')
111
- assert_equal "<div id='layout'>\n <h1>hello worlds</h1>\n <p>hello from partial</p>\n</div>\n", IO.read(output)
112
- end
113
-
114
- should 'create erb.html' do
115
- output = File.join(File.dirname(__FILE__), 'template/output/erb/index.html')
116
- assert_equal "<h1>hello worlds</h1>\n", IO.read(output)
117
- end
118
-
119
- should 'create redcloth.html' do
120
- output = File.join(File.dirname(__FILE__), 'template/output/redcloth/index.html')
121
- assert_equal "<h1>hello worlds</h1>", IO.read(output)
122
- end
123
-
124
- should 'create markdown.html' do
125
- output = File.join(File.dirname(__FILE__), 'template/output/markdown/index.html')
126
- assert_equal "<h1>hello worlds</h1>\n", IO.read(output)
127
- end
128
-
129
- should 'create mustache.html' do
130
- output = File.join(File.dirname(__FILE__), 'template/output/mustache/index.html')
131
- assert_equal "<h1>hello worlds</h1>\n", IO.read(output)
132
- end
133
-
134
- should 'create liquid.html' do
135
- output = File.join(File.dirname(__FILE__), 'template/output/liquid/index.html')
136
- assert_equal "<h1>hello worlds</h1>", IO.read(output)
137
- end
138
-
139
- should 'create builder.html' do
140
- output = File.join(File.dirname(__FILE__), 'template/output/builder/index.html')
141
- assert_equal "<h1>hello worlds</h1>\n", IO.read(output)
142
- end
143
-
144
- should 'copy static.html' do
145
- output = File.join(File.dirname(__FILE__), 'template/output/static.html')
146
- assert_equal "hello from static", IO.read(output)
147
- end
148
-
149
- should 'not create partials' do
150
- assert !File.exist?(File.join(File.dirname(__FILE__), 'template/output/_partial/index.html'))
151
- end
152
-
153
- teardown do
154
- FileUtils.rm_r File.join(File.dirname(__FILE__), 'template/output')
155
- end
156
-
157
-
158
- end
159
-
160
- end
@@ -1,89 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestBase < Test::Unit::TestCase
4
-
5
- context 'Frank::Base' do
6
-
7
- setup do
8
- proj_dir = File.join(File.dirname(__FILE__), 'template')
9
- settings = YAML.load_file(File.join(proj_dir, 'settings.yml'))
10
- @frank = 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
- context 'layouts' do
20
-
21
- should 'render template using layout' do
22
- template = @frank.render_path('layout_test.haml')
23
- assert_equal "<div id='layout'>\n <h1>hi inside layout</h1>\n</div>\n", template
24
- end
25
-
26
- should 'render template using layout2' do
27
- template = @frank.render_path('layout2_test.haml')
28
- assert_equal "<div id='layout2'>\n <h1>hi inside layout2</h1>\n</div>\n", template
29
- end
30
-
31
- end
32
-
33
- should 'render haml template' do
34
- template = @frank.render_path('index.haml')
35
- assert_equal "<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n", template
36
- end
37
-
38
- should 'render haml template with a haml partial' do
39
- template = @frank.render_path('partial_test.haml')
40
- assert_equal "<div id='layout'>\n <h1>hello worlds</h1>\n <p>hello from partial</p>\n</div>\n", template
41
- end
42
-
43
- should 'render sass template' do
44
- template = @frank.render_path('sass.sass')
45
- assert_equal "#hello-worlds {\n background: red; }\n", template
46
- end
47
-
48
- should 'render coffee template' do
49
- template = @frank.render_path('coffee.coffee')
50
- assert_equal "(function(){\n var greeting;\n greeting = \"Hello CoffeeScript\";\n})();", template
51
- end
52
-
53
- should 'render erb template' do
54
- template = @frank.render_path('erb.erb')
55
- assert_equal "<h1>hello worlds</h1>\n", template
56
- end
57
-
58
- should 'render redcloth template' do
59
- template = @frank.render_path('redcloth.textile')
60
- assert_equal "<h1>hello worlds</h1>", template
61
- end
62
-
63
- should 'render rdiscount template' do
64
- template = @frank.render_path('markdown.md')
65
- assert_equal "<h1>hello worlds</h1>\n", template
66
- end
67
-
68
- should 'render mustache template' do
69
- template = @frank.render_path('mustache.mustache')
70
- assert_equal "<h1>hello worlds</h1>\n", template
71
- end
72
-
73
- should 'render liquid template' do
74
- template = @frank.render_path('liquid.liquid')
75
- assert_equal "<h1>hello worlds</h1>", template
76
- end
77
-
78
- should 'render builder template' do
79
- template = @frank.render_path('builder.builder')
80
- assert_equal "<h1>hello worlds</h1>\n", template
81
- end
82
-
83
- should 'raise template error' do
84
- assert_raise(Frank::TemplateError) { @frank.render_path('not_a.template') }
85
- end
86
-
87
- end
88
-
89
- end