flatrack 1.2.1 → 1.3.0
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.travis.yml +4 -1
- data/CHANGELOG.md +16 -0
- data/README.md +15 -5
- data/lib/flatrack/cli.rb +4 -1
- data/lib/flatrack/request.rb +5 -4
- data/lib/flatrack/response.rb +23 -10
- data/lib/flatrack/template.rb +18 -11
- data/lib/flatrack/version.rb +1 -1
- data/lib/flatrack/view/render_helper.rb +1 -1
- data/lib/flatrack/view.rb +1 -0
- data/lib/rake/asset_tasks/asset.rb +28 -26
- data/spec/fixtures/templates/alt_layout.html.erb +3 -0
- data/spec/fixtures/templates/set_layout.html +3 -0
- data/spec/fixtures/templates/set_layout.html.erb +5 -0
- data/spec/fixtures/templates/set_layout.html.rb +3 -0
- data/spec/lib/flatrack/cli_spec.rb +7 -0
- data/spec/lib/flatrack/view/set_layout_spec.rb +31 -0
- data/spec/lib/flatrack/view_spec.rb +1 -1
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aeb92ed8375597715f099798076360100171fd3d
|
4
|
+
data.tar.gz: e4eb7e564ee857784c67e0952001821cc3abaadb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 350ed50f84bcc2d115b9223e2ce5bff5a41d36d679ff7002b358fc0dd8e59178bac1e180cc713ee04dcd450c2066e7fa54f755d57bfcaeea4369cd08b19196ef
|
7
|
+
data.tar.gz: d5c093b73c97259debe0941bb544948dcae572d62148598f7fdc620462a6d045b3f82c5f02bd9b522f3bfe7ddf83a75dc60d5b6a440cf6dc5120386b525caf27
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
# Flatrack 1.2.1 (March 25, 2014)
|
2
|
+
|
3
|
+
* Fully Documented Flatrack.
|
4
|
+
|
5
|
+
*Jason Waldrip*
|
6
|
+
|
7
|
+
* Added --version to CLI.
|
8
|
+
|
9
|
+
*Jason Waldrip*
|
10
|
+
|
11
|
+
# Flatrack 1.2.0 (March 24, 2014)
|
12
|
+
|
13
|
+
* Moved away from custom templating engine in favor or tilt.
|
14
|
+
|
15
|
+
*Jason Waldrip*
|
16
|
+
|
1
17
|
# Flatrack 1.1.1 (March 06, 2014)
|
2
18
|
|
3
19
|
* Fix gem build errors, and update dependencies.
|
data/README.md
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
--
|
3
3
|
|
4
4
|
[](http://allthebadges.io/jwaldrip/flatrack/badge_fury)
|
5
|
-
[](http://allthebadges.io/jwaldrip/flatrack/gemnasium)
|
6
5
|
[](http://allthebadges.io/jwaldrip/flatrack/travis)
|
7
6
|
[](https://coveralls.io/r/jwaldrip/flatrack?branch=master)
|
8
7
|
[](http://allthebadges.io/jwaldrip/flatrack/code_climate)
|
8
|
+
[](http://inch-pages.github.io/github/jwaldrip/flatrack)
|
9
9
|
|
10
10
|
## About
|
11
11
|
A simple rack web layer for delivering rendered static files.
|
@@ -20,17 +20,18 @@ A simple rack web layer for delivering rendered static files.
|
|
20
20
|
|
21
21
|
### Structure
|
22
22
|
|
23
|
-
You should have
|
23
|
+
You should have 4 directories:
|
24
24
|
|
25
25
|
- assets
|
26
26
|
- layouts
|
27
27
|
- pages
|
28
|
+
- partials
|
28
29
|
|
29
30
|
#### Assets
|
30
31
|
Location of sprockets assets, flatrack comes with Sass and Coffeescript out of the box.
|
31
32
|
|
32
33
|
- images
|
33
|
-
-
|
34
|
+
- javascripts
|
34
35
|
- stylesheets
|
35
36
|
|
36
37
|
#### Pages
|
@@ -61,11 +62,20 @@ Anything in `/pages` maps to a URL at `/`, root of a directory will always map t
|
|
61
62
|
|
62
63
|
### Extensions
|
63
64
|
|
64
|
-
* [
|
65
|
+
* HAML ([haml-flatrack](https://github.com/jwaldrip/haml-flatrack))
|
66
|
+
* Markdown ([redcarpet](https://github.com/vmg/redcarpet), [bluecloth](https://github.com/mislav/bluecloth/))
|
67
|
+
* Textile (Redcloth)
|
68
|
+
* _and more!_ (see [Tilt](https://github.com/rtomayko/tilt) for more details.)
|
69
|
+
|
70
|
+
### Sites using flatrack
|
71
|
+
___Pull Request to add yours!___
|
72
|
+
|
73
|
+
* [jasonwaldrip.com](http://jasonwaldrip.com)
|
74
|
+
* [carlypaige.com](http://carlypaige.com)
|
65
75
|
|
66
76
|
## Contributing
|
67
77
|
|
68
|
-
1. Fork it ( http://github.com
|
78
|
+
1. Fork it ( http://github.com/jwaldrip/flat-rack/fork )
|
69
79
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
70
80
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
71
81
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/flatrack/cli.rb
CHANGED
@@ -75,7 +75,10 @@ class Flatrack
|
|
75
75
|
desc '--version', 'flatrack version'
|
76
76
|
# Info about flatrack
|
77
77
|
def __default__
|
78
|
-
|
78
|
+
if options[:version]
|
79
|
+
puts 'Flatrack ' + Flatrack::VERSION
|
80
|
+
return
|
81
|
+
end
|
79
82
|
end
|
80
83
|
|
81
84
|
default_task :__default__
|
data/lib/flatrack/request.rb
CHANGED
@@ -2,9 +2,6 @@ class Flatrack
|
|
2
2
|
# parses an incoming flatrack request and provides a method to render a
|
3
3
|
# response
|
4
4
|
class Request
|
5
|
-
# @private
|
6
|
-
DEFAULT_FORMAT = 'html'
|
7
|
-
|
8
5
|
attr_reader :env, :rack_request
|
9
6
|
|
10
7
|
# Initializes a response
|
@@ -26,7 +23,11 @@ class Flatrack
|
|
26
23
|
|
27
24
|
# the format on the incoming request
|
28
25
|
def format
|
29
|
-
|
26
|
+
ext = File.extname path
|
27
|
+
unless ext.empty?
|
28
|
+
path.sub!(/#{ext}/, '')
|
29
|
+
ext.split('.').last
|
30
|
+
end
|
30
31
|
end
|
31
32
|
|
32
33
|
# the processed response for an inbound request
|
data/lib/flatrack/response.rb
CHANGED
@@ -4,7 +4,9 @@ class Flatrack
|
|
4
4
|
# @private
|
5
5
|
DEFAULT_FILE = 'index'
|
6
6
|
|
7
|
+
attr_accessor :layout
|
7
8
|
attr_reader :request
|
9
|
+
delegate :format, to: :request
|
8
10
|
|
9
11
|
# Initializes a response
|
10
12
|
# @param request [Flatrack::Request]
|
@@ -19,18 +21,33 @@ class Flatrack
|
|
19
21
|
# @option opts [Symbol] :layout
|
20
22
|
# @return [Array] the rack response
|
21
23
|
def render(file: file_for(request.path), status: 200, layout: :layout)
|
22
|
-
|
23
|
-
|
24
|
+
@file, @status, @layout = file, status, layout
|
25
|
+
page_content = pre_render_page
|
24
26
|
body << begin
|
25
|
-
renderer_for_layout(layout).render
|
27
|
+
renderer_for_layout(@layout).render view, &proc { page_content }
|
26
28
|
rescue Flatrack::FileNotFound
|
27
|
-
page_content
|
29
|
+
page_content
|
28
30
|
end
|
29
31
|
[status, headers, body]
|
30
32
|
end
|
31
33
|
|
34
|
+
# Set the layout
|
35
|
+
# @param layout [String]
|
36
|
+
# @return [String]
|
37
|
+
def use_layout(layout)
|
38
|
+
@layout = layout.to_s
|
39
|
+
end
|
40
|
+
|
32
41
|
private
|
33
42
|
|
43
|
+
def pre_render_page
|
44
|
+
renderer = renderer_for_page(@file)
|
45
|
+
content = renderer.render(view)
|
46
|
+
@view = nil
|
47
|
+
headers['Content-Type'] = FORMATS[renderer.format.to_sym]
|
48
|
+
content
|
49
|
+
end
|
50
|
+
|
34
51
|
def body
|
35
52
|
@body ||= []
|
36
53
|
end
|
@@ -39,10 +56,6 @@ class Flatrack
|
|
39
56
|
@headers ||= {}
|
40
57
|
end
|
41
58
|
|
42
|
-
def set_content_type
|
43
|
-
headers['Content-Type'] = FORMATS[request.format.to_sym]
|
44
|
-
end
|
45
|
-
|
46
59
|
def file_for(path)
|
47
60
|
if File.directory?(File.join 'pages', path)
|
48
61
|
File.join(path, DEFAULT_FILE)
|
@@ -52,11 +65,11 @@ class Flatrack
|
|
52
65
|
end
|
53
66
|
|
54
67
|
def renderer_for_page(file)
|
55
|
-
Template.find :page, file
|
68
|
+
Template.find :page, format, file
|
56
69
|
end
|
57
70
|
|
58
71
|
def renderer_for_layout(file)
|
59
|
-
Template.find :layout,
|
72
|
+
Template.find :layout, format, file
|
60
73
|
end
|
61
74
|
|
62
75
|
def view
|
data/lib/flatrack/template.rb
CHANGED
@@ -6,34 +6,40 @@ require 'flatrack/template/html'
|
|
6
6
|
class Flatrack
|
7
7
|
# The default template parser/finder
|
8
8
|
class Template
|
9
|
-
|
9
|
+
# @private
|
10
|
+
DEFAULT_FORMAT = 'html'
|
11
|
+
|
12
|
+
attr_reader :type, :file, :format
|
13
|
+
delegate :render, to: :@renderer
|
10
14
|
|
11
15
|
# Creates a new template instance and invokes find
|
12
16
|
# @param type [Symbol] the type of template
|
17
|
+
# @param format [String] the format e.g. html
|
13
18
|
# @param file [String] the location of the file
|
14
|
-
def self.find(type, file)
|
15
|
-
new(type, file)
|
19
|
+
def self.find(type, format, file)
|
20
|
+
new(type, format, file)
|
16
21
|
end
|
17
22
|
|
18
23
|
# Creates a new template instance
|
19
24
|
# @param type [Symbol] the type of template
|
25
|
+
# @param format [String] the format e.g. html
|
20
26
|
# @param file [String] the location of the file
|
21
|
-
def initialize(type, file)
|
22
|
-
@
|
27
|
+
def initialize(type, format, file)
|
28
|
+
@format = format || DEFAULT_FORMAT
|
29
|
+
@type, @file = type, file.to_s
|
30
|
+
@renderer = find
|
23
31
|
end
|
24
32
|
|
25
|
-
|
26
|
-
|
33
|
+
private
|
34
|
+
|
27
35
|
def find
|
28
36
|
template = find_by_type
|
29
37
|
fail FileNotFound, "could not find #{file}" unless template
|
30
38
|
Tilt.new template, options
|
31
39
|
rescue RuntimeError
|
32
|
-
raise
|
40
|
+
raise TemplateNotFound, "could not find a renderer for #{file}"
|
33
41
|
end
|
34
42
|
|
35
|
-
private
|
36
|
-
|
37
43
|
def options
|
38
44
|
local_options = {}
|
39
45
|
super.merge local_options
|
@@ -45,7 +51,8 @@ class Flatrack
|
|
45
51
|
if File.exist?(file)
|
46
52
|
file
|
47
53
|
else
|
48
|
-
|
54
|
+
file_with_format = [file, format].compact.join('.')
|
55
|
+
Dir[File.join type.to_s.pluralize, "#{file_with_format}*"].first
|
49
56
|
end
|
50
57
|
end
|
51
58
|
end
|
data/lib/flatrack/version.rb
CHANGED
data/lib/flatrack/view.rb
CHANGED
@@ -1,36 +1,38 @@
|
|
1
1
|
# Rake Extensions
|
2
2
|
module Rake
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
class AssetTasks
|
4
|
+
# Asset class for sprockets pre-compilation
|
5
|
+
class Asset
|
6
|
+
# Returns a sprockets asset
|
7
|
+
# @param env [Sprockets::Environment]
|
8
|
+
# @param file [String]
|
9
|
+
def initialize(env, file)
|
10
|
+
@env = env
|
11
|
+
@file = file
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
# Returns the path of an asset
|
15
|
+
# @return [String]
|
16
|
+
def path
|
17
|
+
File.expand_path(file).sub(/(#{@env.paths.join('|')})\//, '')
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
+
private
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
def basename
|
23
|
+
File.basename @file
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
def parts
|
27
|
+
basename.split('.').size
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
def file
|
31
|
+
if parts > 2
|
32
|
+
@file.split('.').tap(&:pop).join('.')
|
33
|
+
else
|
34
|
+
@file
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Flatrack::View do
|
4
|
+
def render_template(fixture)
|
5
|
+
path = File.join Flatrack.gem_root, '../spec/fixtures/templates', fixture
|
6
|
+
env = Rack::MockRequest.env_for 'http://example.com'
|
7
|
+
req = Flatrack::Request.new env
|
8
|
+
_, _, body = Flatrack::Response.new(req).render(file: path)
|
9
|
+
body.first.lines.map(&:strip).join
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#link_to' do
|
13
|
+
|
14
|
+
context 'using erb' do
|
15
|
+
it 'should properly render' do
|
16
|
+
template_content = render_template 'set_layout.html.erb'
|
17
|
+
expected_content = render_template 'set_layout.html'
|
18
|
+
expect(template_content).to eq expected_content
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'using rb' do
|
23
|
+
it 'should properly render' do
|
24
|
+
template_content = render_template 'set_layout.html.rb'
|
25
|
+
expected_content = render_template 'set_layout.html'
|
26
|
+
expect(template_content).to eq expected_content
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -42,7 +42,7 @@ describe Flatrack::View do
|
|
42
42
|
|
43
43
|
it 'should properly render a partial' do
|
44
44
|
site do
|
45
|
-
write(:partial, 'sample.erb', template)
|
45
|
+
write(:partial, 'sample.html.erb', template)
|
46
46
|
result = view.render(:sample)
|
47
47
|
expect(result).to include 'Hello World'.reverse
|
48
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flatrack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Waldrip
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -364,6 +364,7 @@ files:
|
|
364
364
|
- public/assets/manifest-6d7e78baa6d2c0670a82be957315fcbc.json
|
365
365
|
- spec/fixtures/assets/sample.css.scss
|
366
366
|
- spec/fixtures/assets/sample.js.coffee
|
367
|
+
- spec/fixtures/templates/alt_layout.html.erb
|
367
368
|
- spec/fixtures/templates/html_tag.html
|
368
369
|
- spec/fixtures/templates/html_tag.html.erb
|
369
370
|
- spec/fixtures/templates/html_tag.html.rb
|
@@ -376,6 +377,9 @@ files:
|
|
376
377
|
- spec/fixtures/templates/link_to.html
|
377
378
|
- spec/fixtures/templates/link_to.html.erb
|
378
379
|
- spec/fixtures/templates/link_to.html.rb
|
380
|
+
- spec/fixtures/templates/set_layout.html
|
381
|
+
- spec/fixtures/templates/set_layout.html.erb
|
382
|
+
- spec/fixtures/templates/set_layout.html.rb
|
379
383
|
- spec/fixtures/templates/stylesheet_tag.html
|
380
384
|
- spec/fixtures/templates/stylesheet_tag.html.erb
|
381
385
|
- spec/fixtures/templates/stylesheet_tag.html.rb
|
@@ -385,6 +389,7 @@ files:
|
|
385
389
|
- spec/lib/flatrack/response_spec.rb
|
386
390
|
- spec/lib/flatrack/site_spec.rb
|
387
391
|
- spec/lib/flatrack/view/link_helper_spec.rb
|
392
|
+
- spec/lib/flatrack/view/set_layout_spec.rb
|
388
393
|
- spec/lib/flatrack/view/tag_helper_spec.rb
|
389
394
|
- spec/lib/flatrack/view_spec.rb
|
390
395
|
- spec/lib/flatrack_spec.rb
|
@@ -419,6 +424,7 @@ summary: Deliver static files with style.
|
|
419
424
|
test_files:
|
420
425
|
- spec/fixtures/assets/sample.css.scss
|
421
426
|
- spec/fixtures/assets/sample.js.coffee
|
427
|
+
- spec/fixtures/templates/alt_layout.html.erb
|
422
428
|
- spec/fixtures/templates/html_tag.html
|
423
429
|
- spec/fixtures/templates/html_tag.html.erb
|
424
430
|
- spec/fixtures/templates/html_tag.html.rb
|
@@ -431,6 +437,9 @@ test_files:
|
|
431
437
|
- spec/fixtures/templates/link_to.html
|
432
438
|
- spec/fixtures/templates/link_to.html.erb
|
433
439
|
- spec/fixtures/templates/link_to.html.rb
|
440
|
+
- spec/fixtures/templates/set_layout.html
|
441
|
+
- spec/fixtures/templates/set_layout.html.erb
|
442
|
+
- spec/fixtures/templates/set_layout.html.rb
|
434
443
|
- spec/fixtures/templates/stylesheet_tag.html
|
435
444
|
- spec/fixtures/templates/stylesheet_tag.html.erb
|
436
445
|
- spec/fixtures/templates/stylesheet_tag.html.rb
|
@@ -440,6 +449,7 @@ test_files:
|
|
440
449
|
- spec/lib/flatrack/response_spec.rb
|
441
450
|
- spec/lib/flatrack/site_spec.rb
|
442
451
|
- spec/lib/flatrack/view/link_helper_spec.rb
|
452
|
+
- spec/lib/flatrack/view/set_layout_spec.rb
|
443
453
|
- spec/lib/flatrack/view/tag_helper_spec.rb
|
444
454
|
- spec/lib/flatrack/view_spec.rb
|
445
455
|
- spec/lib/flatrack_spec.rb
|