locomotivecms_steam 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +19 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +188 -0
- data/LICENSE +20 -0
- data/README.md +36 -0
- data/Rakefile +17 -0
- data/bin/publish +28 -0
- data/config/locales/de.yml +157 -0
- data/config/locales/en.yml +189 -0
- data/config/locales/es.yml +133 -0
- data/config/locales/et.yml +154 -0
- data/config/locales/fr.yml +148 -0
- data/config/locales/it.yml +155 -0
- data/config/locales/nb.yml +191 -0
- data/config/locales/nl.yml +160 -0
- data/config/locales/pl.yml +203 -0
- data/config/locales/pt-BR.yml +139 -0
- data/config/locales/ru.yml +224 -0
- data/lib/locomotive/steam/core_ext.rb +5 -0
- data/lib/locomotive/steam/core_ext/array.rb +3 -0
- data/lib/locomotive/steam/core_ext/boolean/false.rb +3 -0
- data/lib/locomotive/steam/core_ext/boolean/true.rb +3 -0
- data/lib/locomotive/steam/core_ext/hash.rb +27 -0
- data/lib/locomotive/steam/core_ext/string.rb +8 -0
- data/lib/locomotive/steam/exceptions.rb +62 -0
- data/lib/locomotive/steam/initializers.rb +5 -0
- data/lib/locomotive/steam/initializers/i18n.rb +3 -0
- data/lib/locomotive/steam/initializers/markdown.rb +27 -0
- data/lib/locomotive/steam/initializers/will_paginate.rb +16 -0
- data/lib/locomotive/steam/liquid.rb +22 -0
- data/lib/locomotive/steam/liquid/drops/base.rb +46 -0
- data/lib/locomotive/steam/liquid/drops/content_entry.rb +48 -0
- data/lib/locomotive/steam/liquid/drops/content_types.rb +117 -0
- data/lib/locomotive/steam/liquid/drops/page.rb +28 -0
- data/lib/locomotive/steam/liquid/drops/session_proxy.rb +18 -0
- data/lib/locomotive/steam/liquid/drops/site.rb +26 -0
- data/lib/locomotive/steam/liquid/errors.rb +17 -0
- data/lib/locomotive/steam/liquid/filters/date.rb +136 -0
- data/lib/locomotive/steam/liquid/filters/html.rb +188 -0
- data/lib/locomotive/steam/liquid/filters/misc.rb +49 -0
- data/lib/locomotive/steam/liquid/filters/resize.rb +18 -0
- data/lib/locomotive/steam/liquid/filters/text.rb +55 -0
- data/lib/locomotive/steam/liquid/filters/translate.rb +28 -0
- data/lib/locomotive/steam/liquid/patches.rb +47 -0
- data/lib/locomotive/steam/liquid/scopeable.rb +149 -0
- data/lib/locomotive/steam/liquid/tags/consume.rb +97 -0
- data/lib/locomotive/steam/liquid/tags/csrf.rb +34 -0
- data/lib/locomotive/steam/liquid/tags/editable.rb +6 -0
- data/lib/locomotive/steam/liquid/tags/editable/base.rb +50 -0
- data/lib/locomotive/steam/liquid/tags/editable/control.rb +19 -0
- data/lib/locomotive/steam/liquid/tags/editable/file.rb +15 -0
- data/lib/locomotive/steam/liquid/tags/editable/long_text.rb +15 -0
- data/lib/locomotive/steam/liquid/tags/editable/short_text.rb +20 -0
- data/lib/locomotive/steam/liquid/tags/editable/text.rb +15 -0
- data/lib/locomotive/steam/liquid/tags/extends.rb +25 -0
- data/lib/locomotive/steam/liquid/tags/google_analytics.rb +28 -0
- data/lib/locomotive/steam/liquid/tags/hybrid.rb +27 -0
- data/lib/locomotive/steam/liquid/tags/inline_editor.rb +16 -0
- data/lib/locomotive/steam/liquid/tags/link_to.rb +56 -0
- data/lib/locomotive/steam/liquid/tags/locale_switcher.rb +106 -0
- data/lib/locomotive/steam/liquid/tags/nav.rb +287 -0
- data/lib/locomotive/steam/liquid/tags/paginate.rb +105 -0
- data/lib/locomotive/steam/liquid/tags/path_helper.rb +98 -0
- data/lib/locomotive/steam/liquid/tags/path_to.rb +36 -0
- data/lib/locomotive/steam/liquid/tags/seo.rb +74 -0
- data/lib/locomotive/steam/liquid/tags/session_assign.rb +41 -0
- data/lib/locomotive/steam/liquid/tags/snippet.rb +63 -0
- data/lib/locomotive/steam/liquid/tags/with_scope.rb +44 -0
- data/lib/locomotive/steam/listen.rb +64 -0
- data/lib/locomotive/steam/logger.rb +54 -0
- data/lib/locomotive/steam/monkey_patches.rb +5 -0
- data/lib/locomotive/steam/monkey_patches/better_errors.rb +70 -0
- data/lib/locomotive/steam/monkey_patches/dragonfly.rb +79 -0
- data/lib/locomotive/steam/monkey_patches/haml.rb +15 -0
- data/lib/locomotive/steam/monkey_patches/httparty.rb +46 -0
- data/lib/locomotive/steam/monkey_patches/mounter.rb +32 -0
- data/lib/locomotive/steam/server.rb +81 -0
- data/lib/locomotive/steam/server/dynamic_assets.rb +33 -0
- data/lib/locomotive/steam/server/entry_submission.rb +120 -0
- data/lib/locomotive/steam/server/favicon.rb +18 -0
- data/lib/locomotive/steam/server/locale.rb +42 -0
- data/lib/locomotive/steam/server/logging.rb +32 -0
- data/lib/locomotive/steam/server/middleware.rb +61 -0
- data/lib/locomotive/steam/server/page.rb +69 -0
- data/lib/locomotive/steam/server/path.rb +34 -0
- data/lib/locomotive/steam/server/renderer.rb +118 -0
- data/lib/locomotive/steam/server/templatized_page.rb +32 -0
- data/lib/locomotive/steam/server/timezone.rb +18 -0
- data/lib/locomotive/steam/standalone_server.rb +33 -0
- data/lib/locomotive/steam/version.rb +5 -0
- data/lib/steam.rb +4 -0
- data/locomotivecms_steam.gemspec +42 -0
- data/spec/fixtures/default/README +0 -0
- data/spec/fixtures/default/app/content_types/bands.yml +19 -0
- data/spec/fixtures/default/app/content_types/events.yml +25 -0
- data/spec/fixtures/default/app/content_types/messages.yml +17 -0
- data/spec/fixtures/default/app/content_types/songs.yml +25 -0
- data/spec/fixtures/default/app/content_types/updates.yml +33 -0
- data/spec/fixtures/default/app/views/pages/404.liquid.haml +10 -0
- data/spec/fixtures/default/app/views/pages/about_us.fr.liquid.haml +7 -0
- data/spec/fixtures/default/app/views/pages/about_us.liquid.haml +21 -0
- data/spec/fixtures/default/app/views/pages/about_us.nb.liquid.haml +4 -0
- data/spec/fixtures/default/app/views/pages/about_us/jane_doe.liquid.haml +4 -0
- data/spec/fixtures/default/app/views/pages/about_us/john_doe.fr.liquid.haml +5 -0
- data/spec/fixtures/default/app/views/pages/about_us/john_doe.liquid.haml +6 -0
- data/spec/fixtures/default/app/views/pages/all.liquid.haml +13 -0
- data/spec/fixtures/default/app/views/pages/archives/news.liquid.haml +10 -0
- data/spec/fixtures/default/app/views/pages/contact.liquid.haml +54 -0
- data/spec/fixtures/default/app/views/pages/contest.liquid.haml +18 -0
- data/spec/fixtures/default/app/views/pages/events.liquid.haml +42 -0
- data/spec/fixtures/default/app/views/pages/filtered.liquid.haml +10 -0
- data/spec/fixtures/default/app/views/pages/grunge_bands.liquid.haml +8 -0
- data/spec/fixtures/default/app/views/pages/index.fr.liquid.haml +3 -0
- data/spec/fixtures/default/app/views/pages/index.liquid.haml +100 -0
- data/spec/fixtures/default/app/views/pages/music.fr.liquid.haml +4 -0
- data/spec/fixtures/default/app/views/pages/music.liquid.haml +42 -0
- data/spec/fixtures/default/app/views/pages/songs/template.fr.liquid.haml +16 -0
- data/spec/fixtures/default/app/views/pages/songs/template.liquid.haml +18 -0
- data/spec/fixtures/default/app/views/pages/songs/template/band.liquid.haml +16 -0
- data/spec/fixtures/default/app/views/pages/store.fr.liquid.haml +5 -0
- data/spec/fixtures/default/app/views/pages/store.liquid +5 -0
- data/spec/fixtures/default/app/views/pages/tags/nav.liquid.haml +6 -0
- data/spec/fixtures/default/app/views/pages/tags/nav_in_deep.liquid.haml +6 -0
- data/spec/fixtures/default/app/views/pages/unlisted_pages.liquid.haml +9 -0
- data/spec/fixtures/default/app/views/snippets/A_Complicated-one.liquid.haml +1 -0
- data/spec/fixtures/default/app/views/snippets/footer.liquid.haml +6 -0
- data/spec/fixtures/default/app/views/snippets/header.liquid.haml +1 -0
- data/spec/fixtures/default/app/views/snippets/song.fr.liquid.haml +8 -0
- data/spec/fixtures/default/app/views/snippets/song.liquid +12 -0
- data/spec/fixtures/default/config/deploy.yml +12 -0
- data/spec/fixtures/default/config/deploy_example.yml +12 -0
- data/spec/fixtures/default/config/site.yml +15 -0
- data/spec/fixtures/default/config/translations.yml +3 -0
- data/spec/fixtures/default/data/bands.yml +10 -0
- data/spec/fixtures/default/data/events.yml +53 -0
- data/spec/fixtures/default/data/songs.yml +46 -0
- data/spec/fixtures/default/data/updates.yml +48 -0
- data/spec/fixtures/default/public/fonts/chunkfive-webfont.eot +0 -0
- data/spec/fixtures/default/public/fonts/chunkfive-webfont.svg +213 -0
- data/spec/fixtures/default/public/fonts/chunkfive-webfont.ttf +0 -0
- data/spec/fixtures/default/public/fonts/chunkfive-webfont.woff +0 -0
- data/spec/fixtures/default/public/fonts/chunkfive.css +8 -0
- data/spec/fixtures/default/public/fonts/chunkfive.otf +0 -0
- data/spec/fixtures/default/public/images/nav_on.png +0 -0
- data/spec/fixtures/default/public/images/photo_frame.png +0 -0
- data/spec/fixtures/default/public/images/sep.png +0 -0
- data/spec/fixtures/default/public/images/top.jpg +0 -0
- data/spec/fixtures/default/public/javascripts/application.js.coffee +2 -0
- data/spec/fixtures/default/public/javascripts/common.js +1 -0
- data/spec/fixtures/default/public/samples/asset_collections/cover.jpg +0 -0
- data/spec/fixtures/default/public/samples/photo.jpg +0 -0
- data/spec/fixtures/default/public/samples/photo_2.jpg +0 -0
- data/spec/fixtures/default/public/stylesheets/application.css +64 -0
- data/spec/fixtures/default/public/stylesheets/other/extra.css.less +8 -0
- data/spec/fixtures/default/public/stylesheets/other/style.css.scss +13 -0
- data/spec/fixtures/default/public/stylesheets/reboot.css +82 -0
- data/spec/integration/integration_helper.rb +15 -0
- data/spec/integration/server/basic_spec.rb +170 -0
- data/spec/integration/server/contact_form_spec.rb +111 -0
- data/spec/integration/server/liquid_spec.rb +91 -0
- data/spec/integration/server/with_scope_spec.rb +20 -0
- data/spec/locales/locales_spec.rb +22 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support.rb +4 -0
- data/spec/support/examples/locale_file.rb +14 -0
- data/spec/support/examples/matching_locale.rb +8 -0
- data/spec/support/helpers.rb +22 -0
- data/spec/support/matchers/hash.rb +5 -0
- metadata +564 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
module Locomotive
|
2
|
+
module Steam
|
3
|
+
module Liquid
|
4
|
+
module Tags
|
5
|
+
|
6
|
+
class PathTo < ::Liquid::Tag
|
7
|
+
|
8
|
+
include PathHelper
|
9
|
+
|
10
|
+
Syntax = /(#{::Liquid::Expression}+)(#{::Liquid::TagAttributes}?)/
|
11
|
+
|
12
|
+
def initialize(tag_name, markup, tokens, context)
|
13
|
+
if markup =~ Syntax
|
14
|
+
@handle = $1
|
15
|
+
@_options = {}
|
16
|
+
markup.scan(::Liquid::TagAttributes) do |key, value|
|
17
|
+
@_options[key] = value
|
18
|
+
end
|
19
|
+
else
|
20
|
+
raise SyntaxError.new("Syntax Error in 'path_to' - Valid syntax: path_to <page|page_handle|content_entry>(, locale: [fr|de|...], with: <page_handle>")
|
21
|
+
end
|
22
|
+
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
def render(context)
|
27
|
+
render_path(context)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
::Liquid::Template.register_tag('path_to', PathTo)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Locomotive
|
2
|
+
module Steam
|
3
|
+
module Liquid
|
4
|
+
module Tags
|
5
|
+
module SEO
|
6
|
+
|
7
|
+
class Base < ::Liquid::Tag
|
8
|
+
|
9
|
+
def render(context)
|
10
|
+
%{
|
11
|
+
#{self.render_title(context)}
|
12
|
+
#{self.render_metadata(context)}
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def render_title(context)
|
19
|
+
title = self.value_for(:seo_title, context)
|
20
|
+
title = context.registers[:site].name if title.blank?
|
21
|
+
|
22
|
+
%{
|
23
|
+
<title>#{title}</title>
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def render_metadata(context)
|
28
|
+
%{
|
29
|
+
<meta name="description" content="#{self.value_for(:meta_description, context)}" />
|
30
|
+
<meta name="keywords" content="#{self.value_for(:meta_keywords, context)}" />
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
# Removes whitespace and quote characters from the input
|
35
|
+
def sanitized_string(string)
|
36
|
+
string ? string.strip.gsub(/"/, '') : ''
|
37
|
+
end
|
38
|
+
|
39
|
+
def value_for(attribute, context)
|
40
|
+
object = self.metadata_object(context)
|
41
|
+
value = object.try(attribute.to_sym).blank? ? context.registers[:site].send(attribute.to_sym) : object.send(attribute.to_sym)
|
42
|
+
self.sanitized_string(value)
|
43
|
+
end
|
44
|
+
|
45
|
+
def metadata_object(context)
|
46
|
+
context['content_instance'] || context['page']
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Title < Base
|
51
|
+
|
52
|
+
def render(context)
|
53
|
+
self.render_title(context)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
class Metadata < Base
|
59
|
+
|
60
|
+
def render(context)
|
61
|
+
self.render_metadata(context)
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
::Liquid::Template.register_tag('seo', SEO::Base)
|
69
|
+
::Liquid::Template.register_tag('seo_title', SEO::Title)
|
70
|
+
::Liquid::Template.register_tag('seo_metadata', SEO::Metadata)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Locomotive
|
2
|
+
module Steam
|
3
|
+
module Liquid
|
4
|
+
module Tags
|
5
|
+
|
6
|
+
# Assign sets a variable in your session.
|
7
|
+
#
|
8
|
+
# {% session_assign foo = 'monkey' %}
|
9
|
+
#
|
10
|
+
# You can then use the variable later in the page.
|
11
|
+
#
|
12
|
+
# {{ session.foo }}
|
13
|
+
#
|
14
|
+
class SessionAssign < ::Liquid::Tag
|
15
|
+
Syntax = /(#{::Liquid::VariableSignature}+)\s*=\s*(#{::Liquid::QuotedFragment}+)/
|
16
|
+
|
17
|
+
def initialize(tag_name, markup, tokens, options)
|
18
|
+
if markup =~ Syntax
|
19
|
+
@to = $1
|
20
|
+
@from = $2
|
21
|
+
else
|
22
|
+
raise ::Liquid::SyntaxError.new(options[:locale].t("errors.syntax.session_assign"), options[:line])
|
23
|
+
end
|
24
|
+
|
25
|
+
super
|
26
|
+
end
|
27
|
+
|
28
|
+
def render(context)
|
29
|
+
request = context.registers[:request]
|
30
|
+
|
31
|
+
request.session[@to.to_sym] = context[@from]
|
32
|
+
''
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
::Liquid::Template.register_tag('session_assign', SessionAssign)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Locomotive
|
2
|
+
module Steam
|
3
|
+
module Liquid
|
4
|
+
module Tags
|
5
|
+
|
6
|
+
class Snippet < ::Liquid::Include
|
7
|
+
|
8
|
+
def render(context)
|
9
|
+
name = @template_name.gsub(/[\"\']/, '')
|
10
|
+
snippet = context.registers[:mounting_point].snippets[name]
|
11
|
+
|
12
|
+
raise ::Liquid::StandardError.new("Unknown snippet \"#{name}\"") if snippet.nil?
|
13
|
+
|
14
|
+
partial = self.parse_template(snippet)
|
15
|
+
|
16
|
+
variable = context[@variable_name || @template_name[1..-2]]
|
17
|
+
|
18
|
+
context.stack do
|
19
|
+
@attributes.each do |key, value|
|
20
|
+
context[key] = context[value]
|
21
|
+
end
|
22
|
+
|
23
|
+
output = (if variable.is_a?(Array)
|
24
|
+
variable.collect do |variable|
|
25
|
+
context[@template_name[1..-2]] = variable
|
26
|
+
partial.render(context)
|
27
|
+
end
|
28
|
+
else
|
29
|
+
context[@template_name[1..-2]] = variable
|
30
|
+
partial.render(context)
|
31
|
+
end)
|
32
|
+
|
33
|
+
Locomotive::Steam::Logger.info " Steamed snippet #{name}"
|
34
|
+
|
35
|
+
output
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
def parse_template(snippet)
|
42
|
+
begin
|
43
|
+
::Liquid::Template.parse(snippet.source)
|
44
|
+
rescue ::Liquid::Error => e
|
45
|
+
# do it again on the raw source instead so that the error line matches
|
46
|
+
# the source file.
|
47
|
+
begin
|
48
|
+
::Liquid::Template.parse(snippet.template.raw_source)
|
49
|
+
rescue ::Liquid::Error => e
|
50
|
+
e.backtrace.unshift "#{snippet.template.filepath}:#{e.line + 1}:in `#{snippet.name}'"
|
51
|
+
e.line = self.line - 1
|
52
|
+
raise e
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
::Liquid::Template.register_tag('include', Snippet)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Locomotive
|
2
|
+
module Steam
|
3
|
+
module Liquid
|
4
|
+
module Tags
|
5
|
+
class WithScope < ::Liquid::Block
|
6
|
+
|
7
|
+
SlashedString = /\/[^\/]*\//
|
8
|
+
TagAttributes = /(\w+|\w+\.\w+)\s*\:\s*(#{SlashedString}|#{::Liquid::QuotedFragment})/
|
9
|
+
|
10
|
+
def initialize(tag_name, markup, tokens, options)
|
11
|
+
@tag_options = HashWithIndifferentAccess.new
|
12
|
+
markup.scan(TagAttributes) do |key, value|
|
13
|
+
@tag_options[key] = value
|
14
|
+
end
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def render(context)
|
19
|
+
context.stack do
|
20
|
+
context['with_scope'] = decode(@tag_options, context)
|
21
|
+
render_all(@nodelist, context)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def decode(attributes, context)
|
28
|
+
attributes.each_pair do |key, value|
|
29
|
+
attributes[key] = (case value
|
30
|
+
when /^true|false$/i then value == 'true'
|
31
|
+
when /^\/[^\/]*\/$/ then Regexp.new(value[1..-2])
|
32
|
+
when /^["|'](.+)["|']$/ then $1.gsub(/^["|']/, '').gsub(/["|']$/, '')
|
33
|
+
else
|
34
|
+
context[value] || value
|
35
|
+
end)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
::Liquid::Template.register_tag('with_scope', WithScope)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'listen'
|
2
|
+
|
3
|
+
module Locomotive::Steam
|
4
|
+
class Listen
|
5
|
+
|
6
|
+
attr_accessor :reader
|
7
|
+
|
8
|
+
def self.instance
|
9
|
+
@@instance = new
|
10
|
+
end
|
11
|
+
|
12
|
+
def start(reader)
|
13
|
+
# if $parent_pid && $parent_pid == Process.pid
|
14
|
+
# puts "bypassing Listen in the parent process"
|
15
|
+
# return false
|
16
|
+
# end
|
17
|
+
|
18
|
+
puts "Listening here: #{Process.pid}"
|
19
|
+
|
20
|
+
self.reader = reader
|
21
|
+
|
22
|
+
self.definitions.each do |definition|
|
23
|
+
self.apply(definition)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def definitions
|
28
|
+
[
|
29
|
+
['config', /\.yml/, [:site, :content_types, :pages, :snippets, :content_entries, :translations]],
|
30
|
+
['app/views', /\.liquid/, [:pages, :snippets]],
|
31
|
+
['app/content_types', /\.yml/, [:content_types, :content_entries]],
|
32
|
+
['data', /\.yml/, :content_entries]
|
33
|
+
]
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
38
|
+
def apply(definition)
|
39
|
+
reloader = Proc.new do |modified, added, removed|
|
40
|
+
resources = [*definition.last]
|
41
|
+
names = resources.map { |n| "\"#{n}\"" }.join(', ')
|
42
|
+
|
43
|
+
Locomotive::Steam::Logger.info "* Reloaded #{names} at #{Time.now}"
|
44
|
+
|
45
|
+
begin
|
46
|
+
reader.reload(resources)
|
47
|
+
rescue Exception => e
|
48
|
+
Locomotive::Steam::MounterException.new('Unable to reload', e)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
filter = definition[1]
|
53
|
+
path = File.join(self.reader.mounting_point.path, definition.first)
|
54
|
+
path = File.expand_path(path)
|
55
|
+
|
56
|
+
listener = ::Listen.to(path, only: filter, &reloader)
|
57
|
+
|
58
|
+
# non blocking listener
|
59
|
+
listener.start #(false)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Locomotive
|
2
|
+
module Steam
|
3
|
+
|
4
|
+
class Logger
|
5
|
+
|
6
|
+
attr_accessor :logger, :logfile_path, :stdout
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
self.logger = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
# Setup the single instance of the ruby logger.
|
13
|
+
#
|
14
|
+
# @param [ String ] path The path to the log file (default: log/steam.log)
|
15
|
+
# @param [ Boolean ] stdout Instead of having a file, log to the standard output
|
16
|
+
#
|
17
|
+
def setup(path, stdout = false)
|
18
|
+
require 'logger'
|
19
|
+
|
20
|
+
self.stdout = stdout
|
21
|
+
|
22
|
+
self.logfile_path = File.expand_path(File.join(path, 'log', 'steam.log'))
|
23
|
+
FileUtils.mkdir_p(File.dirname(logfile_path))
|
24
|
+
|
25
|
+
out = self.stdout ? STDOUT : self.logfile_path
|
26
|
+
|
27
|
+
self.logger = ::Logger.new(out).tap do |log|
|
28
|
+
log.level = ::Logger::DEBUG
|
29
|
+
log.formatter = proc do |severity, datetime, progname, msg|
|
30
|
+
"#{msg}\n"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.instance
|
36
|
+
@@instance ||= self.new
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.setup(path, stdout = false)
|
40
|
+
self.instance.setup(path, stdout)
|
41
|
+
end
|
42
|
+
|
43
|
+
class << self
|
44
|
+
%w(debug info warn error fatal unknown).each do |name|
|
45
|
+
define_method(name) do |message|
|
46
|
+
self.instance.logger.send(name.to_sym, message)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module BetterErrors
|
4
|
+
class MiddlewareWrapper
|
5
|
+
|
6
|
+
def initialize(app)
|
7
|
+
@@middleware ||= BetterErrors::Middleware.new(app)
|
8
|
+
@@middleware.instance_variable_set(:@app, app)
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
env['action_dispatch.request.parameters'] = Rack::Request.new(env).params
|
13
|
+
|
14
|
+
@@middleware.call(env)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
module FrameWithLiquidContext
|
20
|
+
|
21
|
+
extend ActiveSupport::Concern
|
22
|
+
|
23
|
+
included do
|
24
|
+
|
25
|
+
attr_accessor :liquid_context
|
26
|
+
|
27
|
+
alias_method_chain :local_variables, :liquid_context
|
28
|
+
|
29
|
+
class << self
|
30
|
+
|
31
|
+
alias_method_chain :from_exception, :liquid_context
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def local_variables_with_liquid_context
|
37
|
+
if self.liquid_context
|
38
|
+
scope = self.liquid_context.scopes.last.clone
|
39
|
+
|
40
|
+
scope.delete_if { |k, _| %w(models contents params session).include?(k) }.tap do |_scope|
|
41
|
+
_scope['site'] = _scope['site'].send(:_source).to_hash
|
42
|
+
_scope['page'] = _scope['page'].to_hash.delete_if { |k, _| %w(template).include?(k) }
|
43
|
+
end
|
44
|
+
else
|
45
|
+
self.local_variables_without_liquid_context
|
46
|
+
end
|
47
|
+
rescue Exception => e
|
48
|
+
puts "[BetterError] Fatal error: #{e.message}".red
|
49
|
+
puts e.backtrace.join("\n")
|
50
|
+
{}
|
51
|
+
end
|
52
|
+
|
53
|
+
module ClassMethods
|
54
|
+
|
55
|
+
def from_exception_with_liquid_context(exception)
|
56
|
+
from_exception_without_liquid_context(exception).tap do |list|
|
57
|
+
if exception.respond_to?(:liquid_context)
|
58
|
+
list.first.liquid_context = exception.liquid_context
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class StackFrame
|
67
|
+
include FrameWithLiquidContext
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|