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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0aec0d226a3b1fbf6614fdd772325b2d393a58a
4
- data.tar.gz: c066f48a3047e11b32a7df82e5ad544bf8d7390f
3
+ metadata.gz: aeb92ed8375597715f099798076360100171fd3d
4
+ data.tar.gz: e4eb7e564ee857784c67e0952001821cc3abaadb
5
5
  SHA512:
6
- metadata.gz: 57a09c2d7aae4bfab7c95450a5a5a41b4ed1f34abf5a345d90a8f444d4e301b0e7fdb81c2de6c9e9cc3d26a9fa7b86f772cbefde2eb500755a3b277f0f21e603
7
- data.tar.gz: 61804f644c5f4c5bfece7bf8974ebbdca4707a06c8196ae32b214cc18d758b0c5ea5dbdadd66b5b4fca6806a687665fceaf215f1ae257d884b551dcc2b0009bb
6
+ metadata.gz: 350ed50f84bcc2d115b9223e2ce5bff5a41d36d679ff7002b358fc0dd8e59178bac1e180cc713ee04dcd450c2066e7fa54f755d57bfcaeea4369cd08b19196ef
7
+ data.tar.gz: d5c093b73c97259debe0941bb544948dcae572d62148598f7fdc620462a6d045b3f82c5f02bd9b522f3bfe7ddf83a75dc60d5b6a440cf6dc5120386b525caf27
data/.rubocop.yml CHANGED
@@ -1,3 +1,4 @@
1
1
  AllCops:
2
2
  Excludes:
3
3
  - vendor/bundle/**
4
+ - spec/**
data/.travis.yml CHANGED
@@ -2,4 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
4
  - 2.1.1
5
- cache: bundler
5
+ cache: bundler
6
+ after_success:
7
+ - bundle exec inch
8
+ - bundle exec rubocop
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
  [![Version](http://allthebadges.io/jwaldrip/flatrack/badge_fury.png)](http://allthebadges.io/jwaldrip/flatrack/badge_fury)
5
- [![Dependencies](http://allthebadges.io/jwaldrip/flatrack/gemnasium.png)](http://allthebadges.io/jwaldrip/flatrack/gemnasium)
6
5
  [![Build Status](http://allthebadges.io/jwaldrip/flatrack/travis.png)](http://allthebadges.io/jwaldrip/flatrack/travis)
7
6
  [![Coverage Status](https://coveralls.io/repos/jwaldrip/flatrack/badge.png?branch=master)](https://coveralls.io/r/jwaldrip/flatrack?branch=master)
8
7
  [![Code Climate](http://allthebadges.io/jwaldrip/flatrack/code_climate.png)](http://allthebadges.io/jwaldrip/flatrack/code_climate)
8
+ [![Inline docs](http://inch-pages.github.io/github/jwaldrip/flatrack.png)](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 3 directories:
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
- - javascripte
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
- * [Haml](https://github.com/jwaldrip/haml-flatrack)
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/<my-github-username>/flat-rack/fork )
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
- puts 'Flatrack ' + Flatrack::VERSION and return if options[:version]
78
+ if options[:version]
79
+ puts 'Flatrack ' + Flatrack::VERSION
80
+ return
81
+ end
79
82
  end
80
83
 
81
84
  default_task :__default__
@@ -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
- (ext = File.extname path).empty? ? DEFAULT_FORMAT : ext.sub(/\./, '')
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
@@ -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
- page_content = proc { renderer_for_page(file).render(view) }
23
- set_content_type
24
+ @file, @status, @layout = file, status, layout
25
+ page_content = pre_render_page
24
26
  body << begin
25
- renderer_for_layout(layout).render(view, &page_content)
27
+ renderer_for_layout(@layout).render view, &proc { page_content }
26
28
  rescue Flatrack::FileNotFound
27
- page_content.call
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, File.join("#{file}.#{request.format}")
72
+ Template.find :layout, format, file
60
73
  end
61
74
 
62
75
  def view
@@ -6,34 +6,40 @@ require 'flatrack/template/html'
6
6
  class Flatrack
7
7
  # The default template parser/finder
8
8
  class Template
9
- attr_reader :type, :file
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).find
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
- @type, @file = type, file
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
- # Finds a given template
26
- # @return [Tilt::Template]
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(TemplateNotFound, "could not find a renderer for #{file}")
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
- Dir[File.join type.to_s.pluralize, "#{file}*"].first
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
@@ -1,5 +1,5 @@
1
1
  # Version
2
2
  class Flatrack
3
3
  # @private
4
- VERSION = '1.2.1'
4
+ VERSION = '1.3.0'
5
5
  end
@@ -6,7 +6,7 @@ class Flatrack
6
6
  # @param file [Symbol, String]
7
7
  # @return [String]
8
8
  def render(file)
9
- Template.find(:partial, file.to_s).render(self)
9
+ Template.find(:partial, nil, file.to_s).render(self)
10
10
  end
11
11
  end
12
12
  end
data/lib/flatrack/view.rb CHANGED
@@ -19,6 +19,7 @@ class Flatrack
19
19
  include ERB::Util
20
20
 
21
21
  attr_accessor :output_buffer
22
+ delegate :use_layout, to: :@response
22
23
 
23
24
  # initializes a flatrack view
24
25
  # @param response [Flatrack::Response]
@@ -1,36 +1,38 @@
1
1
  # Rake Extensions
2
2
  module Rake
3
- # Asset class for sprockets pre-compilation
4
- class AssetTasks::Asset
5
- # Returns a sprockets asset
6
- # @param env [Sprockets::Environment]
7
- # @param file [String]
8
- def initialize(env, file)
9
- @env = env
10
- @file = file
11
- end
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
- # Returns the path of an asset
14
- # @return [String]
15
- def path
16
- File.expand_path(file).sub(/(#{@env.paths.join('|')})\//, '')
17
- end
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
- private
20
+ private
20
21
 
21
- def basename
22
- File.basename @file
23
- end
22
+ def basename
23
+ File.basename @file
24
+ end
24
25
 
25
- def parts
26
- basename.split('.').size
27
- end
26
+ def parts
27
+ basename.split('.').size
28
+ end
28
29
 
29
- def file
30
- if parts > 2
31
- @file.split('.').tap(&:pop).join('.')
32
- else
33
- @file
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,3 @@
1
+ <div class="layout-content">
2
+ <%= yield %>
3
+ </div>
@@ -0,0 +1,3 @@
1
+ <div class="layout-content">
2
+ hello world
3
+ </div>
@@ -0,0 +1,5 @@
1
+ <%
2
+ path = File.expand_path File.join File.dirname(__FILE__), 'alt_layout.html.erb'
3
+ use_layout path
4
+ %>
5
+ hello world
@@ -0,0 +1,3 @@
1
+ path = File.expand_path File.join File.dirname(__FILE__), 'alt_layout.html.erb'
2
+ use_layout path
3
+ 'hello world'
@@ -57,4 +57,11 @@ describe Flatrack::CLI do
57
57
  end
58
58
  end
59
59
 
60
+ describe '--version' do
61
+ it 'should display the flatrack version' do
62
+ expect(STDOUT).to receive(:puts).with 'Flatrack ' + Flatrack::VERSION
63
+ Flatrack::CLI.start(%w(--version))
64
+ end
65
+ end
66
+
60
67
  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.2.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-26 00:00:00.000000000 Z
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