flatrack 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -2
- data/README.md +14 -2
- data/{templates → error_pages}/404.html +0 -0
- data/{templates → error_pages}/500.html +0 -0
- data/flatrack.gemspec +4 -0
- data/{templates → lib/flatrack/cli/templates}/.gitignore +0 -0
- data/{templates → lib/flatrack/cli/templates}/.keep +0 -0
- data/{templates → lib/flatrack/cli/templates}/Gemfile.erb +0 -0
- data/{templates → lib/flatrack/cli/templates}/Rakefile +0 -0
- data/{templates → lib/flatrack/cli/templates}/boot.rb +0 -0
- data/{templates → lib/flatrack/cli/templates}/config.ru +0 -0
- data/{templates → lib/flatrack/cli/templates}/javascript.js.coffee +0 -0
- data/{templates → lib/flatrack/cli/templates}/layout.html.erb +0 -0
- data/{logo.png → lib/flatrack/cli/templates/logo.png} +0 -0
- data/{templates → lib/flatrack/cli/templates}/page.html.erb +0 -0
- data/{templates → lib/flatrack/cli/templates}/stylesheet.css.scss +0 -0
- data/lib/flatrack/cli.rb +10 -1
- data/lib/flatrack/request.rb +2 -2
- data/lib/flatrack/response.rb +6 -8
- data/lib/flatrack/site.rb +0 -2
- data/lib/flatrack/template/erubis/handler.rb +76 -0
- data/lib/flatrack/template/erubis.rb +20 -0
- data/lib/flatrack/template/html.rb +11 -0
- data/lib/flatrack/template/rb.rb +13 -0
- data/lib/flatrack/template.rb +35 -0
- data/lib/flatrack/version.rb +1 -1
- data/lib/flatrack/view/capture_helper.rb +30 -0
- data/lib/flatrack/view/link_helper.rb +28 -0
- data/lib/flatrack/view/output_buffer.rb +24 -0
- data/lib/flatrack/view/render_helper.rb +9 -0
- data/lib/flatrack/view/request_helper.rb +13 -0
- data/lib/flatrack/view/tag_helper.rb +102 -0
- data/lib/flatrack/view.rb +30 -0
- data/lib/flatrack.rb +3 -9
- data/lib/rake/asset_tasks.rb +31 -23
- data/spec/fixtures/assets/sample.css.scss +2 -0
- data/spec/fixtures/assets/{application.js.coffee → sample.js.coffee} +1 -1
- data/spec/fixtures/templates/html_tag.html +5 -0
- data/spec/fixtures/templates/html_tag.html.erb +9 -0
- data/spec/fixtures/templates/html_tag.html.rb +5 -0
- data/spec/fixtures/templates/image_tag.html +2 -0
- data/spec/fixtures/templates/image_tag.html.erb +2 -0
- data/spec/fixtures/templates/image_tag.html.rb +2 -0
- data/spec/fixtures/templates/javascript_tag.html +2 -0
- data/spec/fixtures/templates/javascript_tag.html.erb +2 -0
- data/spec/fixtures/templates/javascript_tag.html.rb +2 -0
- data/spec/fixtures/templates/link_to.html +9 -0
- data/spec/fixtures/templates/link_to.html.erb +11 -0
- data/spec/fixtures/templates/link_to.html.rb +7 -0
- data/spec/fixtures/templates/stylesheet_tag.html +2 -0
- data/spec/fixtures/templates/stylesheet_tag.html.erb +2 -0
- data/spec/fixtures/templates/stylesheet_tag.html.rb +2 -0
- data/spec/lib/flatrack/asset_extensions_spec.rb +2 -2
- data/spec/lib/flatrack/cli_spec.rb +8 -6
- data/spec/lib/flatrack/request_spec.rb +4 -4
- data/spec/lib/flatrack/response_spec.rb +4 -4
- data/spec/lib/flatrack/site_spec.rb +10 -5
- data/spec/lib/flatrack/view/link_helper_spec.rb +25 -0
- data/spec/lib/flatrack/view/tag_helper_spec.rb +81 -0
- data/spec/lib/flatrack/view_spec.rb +52 -0
- data/spec/lib/flatrack_spec.rb +1 -1
- data/spec/lib/rake/asset_tasks_spec.rb +8 -8
- data/spec/spec_helper.rb +3 -2
- data/spec/support/fixture_helper.rb +29 -0
- data/spec/support/site_helper.rb +43 -39
- metadata +126 -33
- data/lib/flatrack/renderer/base.rb +0 -19
- data/lib/flatrack/renderer.rb +0 -30
- data/lib/flatrack/response/view_context.rb +0 -67
- data/renderers/erb.rb +0 -9
- data/renderers/html.rb +0 -9
- data/renderers/rb.rb +0 -19
- data/spec/lib/flatrack/renderer/base_spec.rb +0 -4
- data/spec/lib/flatrack/response/view_context_spec.rb +0 -93
- data/spec/renderers/erb_spec.rb +0 -21
- data/spec/renderers/html_spec.rb +0 -21
- data/spec/renderers/rb_spec.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8edfe0f35ac6cc52afc3bedd60f818c74e7e1d52
|
4
|
+
data.tar.gz: 5b338685735c1feb6dece6a301b20d50d19cf5ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09b78371dbfe2ec291364dfa6ba660b53dc3ab2f5d0e80e4afeacfeaaee91b8e71a2cf0f4ab030b813df6dec4ddf4b74c4c4c2d4a3355c3854a2830ff87a1af6
|
7
|
+
data.tar.gz: 94b13b995d764115712e86573a76a5f7859d83ff5a290e9ac31ec9acc2d532b147dc96e9e135f08ef37b66b28d167c67feafae2ae5dca8cd56d39c7b94f96603
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
![Flatrack](https://raw.github.com/jwaldrip/flatrack/master/logo.png)
|
1
|
+
![Flatrack](https://raw.github.com/jwaldrip/flatrack/master/lib/flatrack/cli/templates/logo.png)
|
2
2
|
--
|
3
3
|
|
4
4
|
[![Version](http://allthebadges.io/jwaldrip/flatrack/badge_fury.png)](http://allthebadges.io/jwaldrip/flatrack/badge_fury)
|
5
5
|
[![Dependencies](http://allthebadges.io/jwaldrip/flatrack/gemnasium.png)](http://allthebadges.io/jwaldrip/flatrack/gemnasium)
|
6
6
|
[![Build Status](http://allthebadges.io/jwaldrip/flatrack/travis.png)](http://allthebadges.io/jwaldrip/flatrack/travis)
|
7
|
-
[![Coverage](
|
7
|
+
[![Coverage Status](https://coveralls.io/repos/jwaldrip/flatrack/badge.png?branch=master)](https://coveralls.io/r/jwaldrip/flatrack?branch=master)
|
8
8
|
[![Code Climate](http://allthebadges.io/jwaldrip/flatrack/code_climate.png)](http://allthebadges.io/jwaldrip/flatrack/code_climate)
|
9
9
|
|
10
10
|
## About
|
@@ -51,6 +51,18 @@ Anything in `/pages` maps to a URL at `/`, root of a directory will always map t
|
|
51
51
|
|
52
52
|
`GET /foo.html` would map to `/pages/foo.html.erb`, the erb (or any other format) is optional if you wish to render your pages dynamically.
|
53
53
|
|
54
|
+
## Templating Support
|
55
|
+
|
56
|
+
### Built in
|
57
|
+
|
58
|
+
* HTML
|
59
|
+
* ERB
|
60
|
+
* Ruby Evaluated Output
|
61
|
+
|
62
|
+
### Extensions
|
63
|
+
|
64
|
+
* [Haml](https://github.com/jwaldrip/haml-flatrack)
|
65
|
+
|
54
66
|
## Contributing
|
55
67
|
|
56
68
|
1. Fork it ( http://github.com/<my-github-username>/flat-rack/fork )
|
File without changes
|
File without changes
|
data/flatrack.gemspec
CHANGED
@@ -30,6 +30,8 @@ based routing.
|
|
30
30
|
|
31
31
|
# Dependencies
|
32
32
|
spec.add_runtime_dependency 'rack', '~> 1.4'
|
33
|
+
spec.add_runtime_dependency 'erubis', '~> 2.7'
|
34
|
+
spec.add_runtime_dependency 'tilt', '~> 1.1'
|
33
35
|
spec.add_runtime_dependency 'activesupport', ['> 3.2', '< 4.2']
|
34
36
|
spec.add_runtime_dependency 'sass', '~> 3.2'
|
35
37
|
spec.add_runtime_dependency 'sprockets-sass', '~> 1.0'
|
@@ -46,4 +48,6 @@ based routing.
|
|
46
48
|
spec.add_development_dependency 'pry', '~> 0.9'
|
47
49
|
spec.add_development_dependency 'coveralls', '~> 0.7'
|
48
50
|
spec.add_development_dependency 'simplecov', '~> 0.8'
|
51
|
+
spec.add_development_dependency 'rubocop', '~> 0.18'
|
52
|
+
spec.add_development_dependency 'inch', '~> 0.3'
|
49
53
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/flatrack/cli.rb
CHANGED
@@ -6,7 +6,8 @@ class Flatrack
|
|
6
6
|
include FileUtils
|
7
7
|
include Thor::Actions
|
8
8
|
|
9
|
-
|
9
|
+
SRC_ROOT = File.join Flatrack.gem_root, 'flatrack/cli/templates'
|
10
|
+
source_root SRC_ROOT
|
10
11
|
|
11
12
|
method_option :verbose, type: :boolean, default: true, aliases: :v
|
12
13
|
method_option :bundle, type: :boolean, default: true, aliases: :b
|
@@ -34,6 +35,10 @@ class Flatrack
|
|
34
35
|
'javascript.js.coffee' => 'assets/javascripts/main.js.coffee'
|
35
36
|
}
|
36
37
|
|
38
|
+
BIN_COPY_FILES = {
|
39
|
+
'logo.png' => 'assets/images/logo.png'
|
40
|
+
}
|
41
|
+
|
37
42
|
def new(path)
|
38
43
|
mkdir_p path
|
39
44
|
full_path = File.expand_path path
|
@@ -79,6 +84,10 @@ class Flatrack
|
|
79
84
|
FILES.each do |temp, dest|
|
80
85
|
template temp, dest, verbose: options[:verbose]
|
81
86
|
end
|
87
|
+
BIN_COPY_FILES.each do |src, dest|
|
88
|
+
src = File.join SRC_ROOT, src
|
89
|
+
copy_file src, dest, verbose: options[:verbose]
|
90
|
+
end
|
82
91
|
end
|
83
92
|
end
|
84
93
|
end
|
data/lib/flatrack/request.rb
CHANGED
@@ -23,7 +23,7 @@ class Flatrack
|
|
23
23
|
|
24
24
|
def response
|
25
25
|
Response.new(self).render
|
26
|
-
rescue
|
26
|
+
rescue TemplateNotFound
|
27
27
|
respond_with_error(500)
|
28
28
|
rescue FileNotFound
|
29
29
|
respond_with_error(404)
|
@@ -34,7 +34,7 @@ class Flatrack
|
|
34
34
|
def respond_with_error(code)
|
35
35
|
Response.new(self).render(file: "#{code}.html", status: code)
|
36
36
|
rescue FileNotFound
|
37
|
-
file = File.join Flatrack.gem_root, '../
|
37
|
+
file = File.join Flatrack.gem_root, '../error_pages', "#{code}.html"
|
38
38
|
Response.new(self).render(file: file, status: code)
|
39
39
|
end
|
40
40
|
end
|
data/lib/flatrack/response.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
class Flatrack
|
2
2
|
class Response
|
3
|
-
autoload :ViewContext, 'flatrack/response/view_context'
|
4
|
-
|
5
3
|
DEFAULT_FILE = 'index'
|
6
4
|
CONTENT_TYPES = {
|
7
5
|
html: 'text/html',
|
@@ -23,10 +21,10 @@ class Flatrack
|
|
23
21
|
end
|
24
22
|
|
25
23
|
def render(file: file_for(request.path), status: 200, layout: :layout)
|
26
|
-
page_content = proc { renderer_for_page(file).render(
|
24
|
+
page_content = proc { renderer_for_page(file).render(view) }
|
27
25
|
set_content_type
|
28
26
|
body << begin
|
29
|
-
renderer_for_layout(layout).render(
|
27
|
+
renderer_for_layout(layout).render(view, &page_content)
|
30
28
|
rescue Flatrack::FileNotFound
|
31
29
|
page_content.call
|
32
30
|
end
|
@@ -48,15 +46,15 @@ class Flatrack
|
|
48
46
|
end
|
49
47
|
|
50
48
|
def renderer_for_page(file)
|
51
|
-
|
49
|
+
Template.find :page, file
|
52
50
|
end
|
53
51
|
|
54
52
|
def renderer_for_layout(file)
|
55
|
-
|
53
|
+
Template.find :layout, File.join("#{file}.#{request.format}")
|
56
54
|
end
|
57
55
|
|
58
|
-
def
|
59
|
-
@
|
56
|
+
def view
|
57
|
+
@view ||= View.new(self)
|
60
58
|
end
|
61
59
|
end
|
62
60
|
end
|
data/lib/flatrack/site.rb
CHANGED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'erubis'
|
2
|
+
|
3
|
+
class Flatrack
|
4
|
+
module Template
|
5
|
+
class Erubis < Tilt::ErubisTemplate
|
6
|
+
class Handler < ::Erubis::Eruby
|
7
|
+
def add_preamble(src)
|
8
|
+
@newline_pending = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_text(src, text)
|
12
|
+
return if text.empty?
|
13
|
+
if text == "\n"
|
14
|
+
@newline_pending += 1
|
15
|
+
else
|
16
|
+
src << "@output_buffer.safe_append='"
|
17
|
+
src << "\n" * @newline_pending if @newline_pending > 0
|
18
|
+
src << escape_text(text)
|
19
|
+
src << "'.freeze;"
|
20
|
+
@newline_pending = 0
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Erubis toggles <%= and <%== behavior when escaping is enabled.
|
25
|
+
# We override to always treat <%== as escaped.
|
26
|
+
def add_expr(src, code, indicator)
|
27
|
+
case indicator
|
28
|
+
when '=='
|
29
|
+
add_expr_escaped(src, code)
|
30
|
+
else
|
31
|
+
super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
BLOCK_EXPR = /\s+(do|\{)(\s*\|[^|]*\|)?\s*\Z/
|
36
|
+
|
37
|
+
def add_expr_literal(src, code)
|
38
|
+
flush_newline_if_pending(src)
|
39
|
+
if code =~ BLOCK_EXPR
|
40
|
+
src << '@output_buffer.append= ' << code
|
41
|
+
else
|
42
|
+
src << '@output_buffer.append=(' << code << ');'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def add_expr_escaped(src, code)
|
47
|
+
flush_newline_if_pending(src)
|
48
|
+
if code =~ BLOCK_EXPR
|
49
|
+
src << '@output_buffer.safe_append= ' << code
|
50
|
+
else
|
51
|
+
src << '@output_buffer.safe_append=(' << code << ');'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_stmt(src, code)
|
56
|
+
flush_newline_if_pending(src)
|
57
|
+
super
|
58
|
+
end
|
59
|
+
|
60
|
+
def add_postamble(src)
|
61
|
+
flush_newline_if_pending(src)
|
62
|
+
src << 'output_buffer = @output_buffer.to_s'
|
63
|
+
end
|
64
|
+
|
65
|
+
def flush_newline_if_pending(src)
|
66
|
+
if @newline_pending > 0
|
67
|
+
src << begin
|
68
|
+
"@output_buffer.safe_append='#{"\n" * @newline_pending}'.freeze;"
|
69
|
+
end
|
70
|
+
@newline_pending = 0
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Flatrack
|
2
|
+
module Template
|
3
|
+
class Erubis < Tilt::ErubisTemplate
|
4
|
+
extend ActiveSupport::Autoload
|
5
|
+
autoload :Handler
|
6
|
+
|
7
|
+
def self.engine_initialized?
|
8
|
+
defined? Handler
|
9
|
+
end
|
10
|
+
|
11
|
+
def prepare
|
12
|
+
@outvar = :output_buffer
|
13
|
+
@options.merge!(trim: true)
|
14
|
+
@engine = Handler.new(data, options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Tilt.prefer Flatrack::Template::Erubis, 'erb'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'tilt'
|
2
|
+
require 'flatrack/template/erubis'
|
3
|
+
require 'flatrack/template/rb'
|
4
|
+
require 'flatrack/template/html'
|
5
|
+
|
6
|
+
class Flatrack
|
7
|
+
module Template
|
8
|
+
def find(type, file)
|
9
|
+
template = find_by_type type, file
|
10
|
+
fail FileNotFound, "could not find #{file}" unless template
|
11
|
+
Tilt.new template, options
|
12
|
+
rescue RuntimeError
|
13
|
+
raise(TemplateNotFound, "could not find a renderer for #{file}")
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def options
|
19
|
+
local_options = {}
|
20
|
+
super.merge local_options
|
21
|
+
rescue NoMethodError
|
22
|
+
local_options
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_by_type(type, file)
|
26
|
+
if File.exist?(file)
|
27
|
+
file
|
28
|
+
else
|
29
|
+
Dir[File.join type.to_s.pluralize, "#{file}*"].first
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module_function :find, :find_by_type, :options
|
34
|
+
end
|
35
|
+
end
|
data/lib/flatrack/version.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
class Flatrack
|
2
|
+
class View
|
3
|
+
module CaptureHelper
|
4
|
+
include ERB::Util
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def capture(*args)
|
9
|
+
value = nil
|
10
|
+
buffer = with_output_buffer { value = yield(*args) }
|
11
|
+
string = buffer.presence || value
|
12
|
+
html_escape string if string.is_a?(String)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Use an alternate output buffer for the duration of the block.
|
16
|
+
# Defaults to a new empty string.
|
17
|
+
def with_output_buffer(buf = nil) #:nodoc:
|
18
|
+
unless buf
|
19
|
+
buf = OutputBuffer.new
|
20
|
+
buf.force_encoding(output_buffer.encoding) if output_buffer
|
21
|
+
end
|
22
|
+
self.output_buffer, old_buffer = buf, output_buffer
|
23
|
+
yield
|
24
|
+
output_buffer
|
25
|
+
ensure
|
26
|
+
self.output_buffer = old_buffer
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Flatrack
|
2
|
+
class View
|
3
|
+
module LinkHelper
|
4
|
+
include TagHelper
|
5
|
+
|
6
|
+
def link_to(name = nil, options = nil, html_options = nil, &block)
|
7
|
+
if block_given?
|
8
|
+
href, options, block = name, options, block
|
9
|
+
elsif options.is_a?(Hash) || options.blank?
|
10
|
+
name, href, options, block = name, name, options, block
|
11
|
+
else
|
12
|
+
name, href, options, block = name, options, html_options, block
|
13
|
+
end
|
14
|
+
|
15
|
+
block ||= proc { name }
|
16
|
+
|
17
|
+
html_tag :a, link_to_options(href, options || {}), &block
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def link_to_options(link, opts = {})
|
23
|
+
link << '?' + opts.delete(:params).to_param if opts[:params].present?
|
24
|
+
{ href: link }.merge(opts)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Flatrack
|
2
|
+
class View
|
3
|
+
class OutputBuffer < ActiveSupport::SafeBuffer #:nodoc:
|
4
|
+
def initialize(*)
|
5
|
+
super
|
6
|
+
encode!
|
7
|
+
end
|
8
|
+
|
9
|
+
def <<(value)
|
10
|
+
return self if value.nil?
|
11
|
+
super(value.to_s)
|
12
|
+
end
|
13
|
+
|
14
|
+
alias_method :append=, :<<
|
15
|
+
|
16
|
+
def safe_concat(value)
|
17
|
+
return self if value.nil?
|
18
|
+
super(value.to_s)
|
19
|
+
end
|
20
|
+
|
21
|
+
alias_method :safe_append=, :safe_concat
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
class Flatrack
|
2
|
+
class View
|
3
|
+
module TagHelper
|
4
|
+
include CaptureHelper
|
5
|
+
include ERB::Util
|
6
|
+
|
7
|
+
PRE_CONTENT_STRINGS = {
|
8
|
+
textarea: "\n"
|
9
|
+
}
|
10
|
+
|
11
|
+
BOOLEAN_ATTRIBUTES = %w(disabled readonly multiple checked autobuffer
|
12
|
+
autoplay controls loop selected hidden scoped
|
13
|
+
async defer reversed ismap seamless muted
|
14
|
+
required autofocus novalidate formnovalidate open
|
15
|
+
pubdate itemscope allowfullscreen default inert
|
16
|
+
sortable truespeed typemustmatch).to_set
|
17
|
+
|
18
|
+
def html_tag(name, content_or_options_with_block = nil, options = nil,
|
19
|
+
escape = true, &block)
|
20
|
+
if block_given?
|
21
|
+
if content_or_options_with_block.is_a?(Hash)
|
22
|
+
options = content_or_options_with_block
|
23
|
+
end
|
24
|
+
html_tag_string(name, capture(&block), options, escape)
|
25
|
+
else
|
26
|
+
html_tag_string(name, content_or_options_with_block, options, escape)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def image_tag(uri, options = {})
|
31
|
+
uri = asset_path(uri) unless uri =~ %r{^(http)?(s)?:?\/\/}
|
32
|
+
options.merge! src: uri
|
33
|
+
html_tag(:img, nil, options)
|
34
|
+
end
|
35
|
+
|
36
|
+
def javascript_tag(uri)
|
37
|
+
uri = asset_path(uri) + '.js' if uri.is_a? Symbol
|
38
|
+
html_tag(:script, '', src: uri, type: 'application/javascript')
|
39
|
+
end
|
40
|
+
|
41
|
+
def stylesheet_tag(uri)
|
42
|
+
uri = asset_path(uri) + '.css' if uri.is_a? Symbol
|
43
|
+
html_tag(:link, nil, rel: 'stylesheet', type: 'text/css', href: uri)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def html_tag_string(name, content, options, escape = true)
|
49
|
+
tag_options = tag_options(options, escape) if options
|
50
|
+
content = h(content) if escape && !content.nil?
|
51
|
+
'<'.tap do |tag|
|
52
|
+
tag << name.to_s
|
53
|
+
tag << tag_options.to_s
|
54
|
+
content_with_ending = content.nil? ? '/>' : ">#{content}</#{name}>"
|
55
|
+
tag << content_with_ending
|
56
|
+
end.html_safe
|
57
|
+
end
|
58
|
+
|
59
|
+
def tag_options(options = {}, escape = true)
|
60
|
+
attrs = build_tag_options(options, escape)
|
61
|
+
" #{attrs * ' '}" unless attrs.blank?
|
62
|
+
end
|
63
|
+
|
64
|
+
def build_tag_options(options = {}, escape = true)
|
65
|
+
(options || {}).reduce([]) do |attrs, (key, value)|
|
66
|
+
if key.to_s == 'data' && value.is_a?(Hash)
|
67
|
+
attrs += data_tag_options(value, escape)
|
68
|
+
elsif BOOLEAN_ATTRIBUTES.include?(key.to_s)
|
69
|
+
attrs << boolean_tag_option(key, value)
|
70
|
+
elsif !value.nil?
|
71
|
+
attrs << tag_option(key, value, escape)
|
72
|
+
end
|
73
|
+
attrs
|
74
|
+
end.compact.sort
|
75
|
+
end
|
76
|
+
|
77
|
+
def data_tag_options(hash, escape = true)
|
78
|
+
hash.each_pair.map do |k, v|
|
79
|
+
data_tag_option(k, v, escape)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def data_tag_option(key, value, escape)
|
84
|
+
key = "data-#{key.to_s.dasherize}"
|
85
|
+
value = value.to_json unless value.is_a?(String) ||
|
86
|
+
value.is_a?(Symbol) ||
|
87
|
+
value.is_a?(BigDecimal)
|
88
|
+
tag_option(key, value, escape)
|
89
|
+
end
|
90
|
+
|
91
|
+
def boolean_tag_option(key, bool)
|
92
|
+
%(#{key}="#{key}") if bool
|
93
|
+
end
|
94
|
+
|
95
|
+
def tag_option(key, value, escape)
|
96
|
+
value = value.join(' ') if value.is_a?(Array)
|
97
|
+
value = h(value) if escape
|
98
|
+
%(#{key}="#{value}")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Flatrack
|
2
|
+
class View
|
3
|
+
extend ActiveSupport::Autoload
|
4
|
+
|
5
|
+
autoload :TagHelper
|
6
|
+
autoload :LinkHelper
|
7
|
+
autoload :RequestHelper
|
8
|
+
autoload :CaptureHelper
|
9
|
+
autoload :RenderHelper
|
10
|
+
autoload :OutputBuffer
|
11
|
+
|
12
|
+
include AssetExtensions
|
13
|
+
include TagHelper
|
14
|
+
include LinkHelper
|
15
|
+
include RequestHelper
|
16
|
+
include CaptureHelper
|
17
|
+
include RenderHelper
|
18
|
+
include ERB::Util
|
19
|
+
|
20
|
+
attr_accessor :output_buffer
|
21
|
+
|
22
|
+
def initialize(response)
|
23
|
+
@response = response
|
24
|
+
@output_buffer = OutputBuffer.new
|
25
|
+
super(response)
|
26
|
+
rescue ArgumentError
|
27
|
+
super()
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/flatrack.rb
CHANGED
@@ -9,14 +9,15 @@ require 'rack'
|
|
9
9
|
class Flatrack
|
10
10
|
extend ActiveSupport::Autoload
|
11
11
|
|
12
|
-
autoload :
|
12
|
+
autoload :View
|
13
|
+
autoload :Template
|
13
14
|
autoload :Request
|
14
15
|
autoload :Response
|
15
16
|
autoload :Site
|
16
17
|
autoload :AssetExtensions
|
17
18
|
autoload :CLI
|
18
19
|
|
19
|
-
|
20
|
+
TemplateNotFound = Class.new StandardError
|
20
21
|
FileNotFound = Class.new StandardError
|
21
22
|
|
22
23
|
FORMATS = {}
|
@@ -32,7 +33,6 @@ class Flatrack
|
|
32
33
|
end
|
33
34
|
|
34
35
|
class << self
|
35
|
-
|
36
36
|
def delegate_instance
|
37
37
|
@delegate_instance ||= new
|
38
38
|
end
|
@@ -46,7 +46,6 @@ class Flatrack
|
|
46
46
|
def method_missing(m, *args, &block)
|
47
47
|
delegate_instance.public_method(m).call(*args, &block)
|
48
48
|
end
|
49
|
-
|
50
49
|
end
|
51
50
|
|
52
51
|
def config(&block)
|
@@ -81,9 +80,4 @@ class Flatrack
|
|
81
80
|
|
82
81
|
# Fix Locales issue
|
83
82
|
I18n.enforce_available_locales = false
|
84
|
-
|
85
|
-
# Load all renderers
|
86
|
-
Dir.glob(File.join gem_root, '../renderers/**/*.rb').each do |f|
|
87
|
-
require f
|
88
|
-
end
|
89
83
|
end
|