locomotivecms_steam 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +19 -30
- data/bin/publish +8 -8
- data/example/server.rb +27 -0
- data/lib/locomotive/steam/exceptions.rb +2 -2
- data/lib/locomotive/steam/initializers.rb +6 -4
- data/lib/locomotive/steam/initializers/dragonfly.rb +19 -0
- data/lib/locomotive/steam/initializers/sprockets.rb +1 -0
- data/lib/locomotive/steam/liquid.rb +1 -1
- data/lib/locomotive/steam/liquid/filters/resize.rb +2 -1
- data/lib/locomotive/steam/liquid/scopeable.rb +2 -2
- data/lib/locomotive/steam/liquid/tags/consume.rb +6 -1
- data/lib/locomotive/steam/liquid/tags/editable/short_text.rb +1 -1
- data/lib/locomotive/steam/liquid/tags/snippet.rb +1 -1
- data/lib/locomotive/steam/middlewares.rb +15 -0
- data/lib/locomotive/steam/{server/middleware.rb → middlewares/base.rb} +13 -11
- data/lib/locomotive/steam/middlewares/dynamic_assets.rb +40 -0
- data/lib/locomotive/steam/{server → middlewares}/entry_submission.rb +4 -4
- data/lib/locomotive/steam/{server → middlewares}/favicon.rb +2 -3
- data/lib/locomotive/steam/{server → middlewares}/locale.rb +4 -4
- data/lib/locomotive/steam/{server → middlewares}/logging.rb +2 -2
- data/lib/locomotive/steam/{server → middlewares}/page.rb +4 -6
- data/lib/locomotive/steam/{server → middlewares}/path.rb +4 -4
- data/lib/locomotive/steam/{server → middlewares}/renderer.rb +6 -5
- data/lib/locomotive/steam/middlewares/stack.rb +66 -0
- data/lib/locomotive/steam/middlewares/static_assets.rb +25 -0
- data/lib/locomotive/steam/{server → middlewares}/templatized_page.rb +4 -4
- data/lib/locomotive/steam/{server → middlewares}/timezone.rb +4 -4
- data/lib/locomotive/steam/misc.rb +10 -0
- data/lib/locomotive/steam/monkey_patches.rb +3 -4
- data/lib/locomotive/steam/monkey_patches/haml.rb +3 -1
- data/lib/locomotive/steam/monkey_patches/mounter.rb +22 -0
- data/lib/locomotive/steam/server.rb +33 -58
- data/lib/locomotive/steam/services.rb +1 -0
- data/lib/locomotive/steam/services/dragonfly.rb +49 -0
- data/lib/locomotive/steam/{monkey_patches/httparty.rb → services/external_api.rb} +6 -6
- data/lib/locomotive/steam/services/markdown.rb +29 -0
- data/lib/locomotive/steam/standalone_server.rb +9 -12
- data/lib/locomotive/steam/version.rb +1 -1
- data/lib/steam.rb +0 -1
- data/locomotivecms_steam.gemspec +8 -9
- data/spec/integration/integration_helper.rb +2 -13
- data/spec/integration/server/basic_spec.rb +0 -6
- data/spec/integration/server/contact_form_spec.rb +0 -4
- data/spec/integration/server/liquid_spec.rb +0 -4
- data/spec/integration/server/with_scope_spec.rb +0 -4
- data/spec/spec_helper.rb +1 -0
- data/spec/support/helpers.rb +13 -4
- metadata +47 -57
- data/lib/locomotive/steam/initializers/markdown.rb +0 -27
- data/lib/locomotive/steam/initializers/will_paginate.rb +0 -16
- data/lib/locomotive/steam/listen.rb +0 -64
- data/lib/locomotive/steam/logger.rb +0 -54
- data/lib/locomotive/steam/monkey_patches/better_errors.rb +0 -70
- data/lib/locomotive/steam/monkey_patches/dragonfly.rb +0 -79
- data/lib/locomotive/steam/server/dynamic_assets.rb +0 -33
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'coffee_script'
|
2
|
+
|
3
|
+
module Locomotive::Steam
|
4
|
+
module Middlewares
|
5
|
+
|
6
|
+
class DynamicAssets < Base
|
7
|
+
|
8
|
+
attr_reader :app, :regexp
|
9
|
+
|
10
|
+
def initialize(app)
|
11
|
+
super(app)
|
12
|
+
|
13
|
+
@regexp = /^\/(javascripts|stylesheets)\/(.*)$/
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
dup._call(env) # thread-safe purpose
|
18
|
+
end
|
19
|
+
|
20
|
+
def _call(env)
|
21
|
+
if env['PATH_INFO'] =~ self.regexp
|
22
|
+
env['PATH_INFO'] = $2
|
23
|
+
|
24
|
+
base_path = env['steam.mounting_point'].path
|
25
|
+
|
26
|
+
begin
|
27
|
+
sprockets = Locomotive::Mounter::Extensions::Sprockets.environment(base_path)
|
28
|
+
sprockets.call(env)
|
29
|
+
rescue Exception => e
|
30
|
+
raise Locomotive::Steam::DefaultException.new "Unable to serve a dynamic asset. Please check the logs.", e
|
31
|
+
end
|
32
|
+
else
|
33
|
+
app.call(env)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Locomotive::Steam
|
2
|
-
|
2
|
+
module Middlewares
|
3
3
|
|
4
4
|
# Mimic the submission of a content entry
|
5
5
|
#
|
6
|
-
class EntrySubmission <
|
6
|
+
class EntrySubmission < Base
|
7
7
|
|
8
|
-
def
|
9
|
-
|
8
|
+
def _call(env)
|
9
|
+
super
|
10
10
|
|
11
11
|
if self.request.post? && env['PATH_INFO'] =~ /^\/entry_submissions\/(.*)/
|
12
12
|
self.process_form($1)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Locomotive::Steam
|
2
|
-
|
2
|
+
module Middlewares
|
3
3
|
|
4
4
|
# Set the locale from the path if possible or use the default one
|
5
5
|
# Examples:
|
@@ -7,10 +7,10 @@ module Locomotive::Steam
|
|
7
7
|
# /fr/ => locale = :fr
|
8
8
|
# /index => locale = :en (default one)
|
9
9
|
#
|
10
|
-
class Locale <
|
10
|
+
class Locale < Base
|
11
11
|
|
12
|
-
def
|
13
|
-
|
12
|
+
def _call(env)
|
13
|
+
super
|
14
14
|
|
15
15
|
self.set_locale!(env)
|
16
16
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module Locomotive::Steam
|
2
|
-
|
2
|
+
module Middlewares
|
3
3
|
|
4
4
|
# Sanitize the path from the previous middleware in order
|
5
5
|
# to make it work for the renderer.
|
6
6
|
#
|
7
|
-
class Page <
|
7
|
+
class Page < Base
|
8
8
|
|
9
|
-
def
|
10
|
-
|
9
|
+
def _call(env)
|
10
|
+
super
|
11
11
|
|
12
12
|
self.set_page!(env)
|
13
13
|
|
@@ -27,8 +27,6 @@ module Locomotive::Steam
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def fetch_page
|
30
|
-
|
31
|
-
|
32
30
|
matchers = self.path_combinations(self.path)
|
33
31
|
|
34
32
|
pages = self.mounting_point.pages.values.find_all do |_page|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module Locomotive::Steam
|
2
|
-
|
2
|
+
module Middlewares
|
3
3
|
|
4
4
|
# Sanitize the path from the previous middleware in order
|
5
5
|
# to make it work for the renderer.
|
6
6
|
#
|
7
|
-
class Path <
|
7
|
+
class Path < Base
|
8
8
|
|
9
|
-
def
|
10
|
-
|
9
|
+
def _call(env)
|
10
|
+
super
|
11
11
|
|
12
12
|
self.set_path!(env)
|
13
13
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Locomotive::Steam
|
2
|
-
|
2
|
+
module Middlewares
|
3
3
|
|
4
|
-
class Renderer <
|
4
|
+
class Renderer < Base
|
5
5
|
|
6
|
-
def
|
7
|
-
|
6
|
+
def _call(env)
|
7
|
+
super
|
8
8
|
|
9
9
|
if self.page
|
10
10
|
if self.page.redirect?
|
@@ -107,8 +107,9 @@ module Locomotive::Steam
|
|
107
107
|
site: self.site,
|
108
108
|
page: self.page,
|
109
109
|
mounting_point: self.mounting_point,
|
110
|
+
services: self.services,
|
110
111
|
inline_editor: false,
|
111
|
-
logger: Locomotive::
|
112
|
+
logger: Locomotive::Common::Logger
|
112
113
|
}
|
113
114
|
end
|
114
115
|
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'rack/session/moneta'
|
2
|
+
require 'rack/builder'
|
3
|
+
require 'rack/lint'
|
4
|
+
require 'dragonfly/middleware'
|
5
|
+
|
6
|
+
module Locomotive
|
7
|
+
module Steam
|
8
|
+
module Middlewares
|
9
|
+
|
10
|
+
class Stack
|
11
|
+
|
12
|
+
def initialize(options)
|
13
|
+
@options = prepare_options(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create
|
17
|
+
options = @options
|
18
|
+
|
19
|
+
Rack::Builder.new do
|
20
|
+
use Rack::Lint
|
21
|
+
|
22
|
+
use Middlewares::Favicon
|
23
|
+
|
24
|
+
if options[:serve_assets]
|
25
|
+
use Middlewares::StaticAssets, {
|
26
|
+
urls: ['/images', '/fonts', '/samples', '/media']
|
27
|
+
}
|
28
|
+
|
29
|
+
use Middlewares::DynamicAssets
|
30
|
+
end
|
31
|
+
|
32
|
+
use ::Dragonfly::Middleware, :steam
|
33
|
+
|
34
|
+
use Rack::Session::Moneta, options[:moneta]
|
35
|
+
|
36
|
+
use Middlewares::Logging
|
37
|
+
|
38
|
+
use Middlewares::EntrySubmission
|
39
|
+
|
40
|
+
use Middlewares::Path
|
41
|
+
use Middlewares::Locale
|
42
|
+
use Middlewares::Timezone
|
43
|
+
|
44
|
+
use Middlewares::Page
|
45
|
+
use Middlewares::TemplatizedPage
|
46
|
+
|
47
|
+
run Middlewares::Renderer.new
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
def prepare_options(options)
|
54
|
+
{
|
55
|
+
serve_assets: false,
|
56
|
+
moneta: {
|
57
|
+
store: Moneta.new(:Memory, :expires => true)
|
58
|
+
}
|
59
|
+
}.merge(options)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rack/static'
|
2
|
+
|
3
|
+
module Locomotive::Steam
|
4
|
+
module Middlewares
|
5
|
+
|
6
|
+
class StaticAssets < ::Rack::Static
|
7
|
+
|
8
|
+
alias_method :call_without_threadsafety, :call
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
dup._call(env) # thread-safe purpose
|
12
|
+
end
|
13
|
+
|
14
|
+
def _call(env)
|
15
|
+
mounting_point = env['steam.mounting_point']
|
16
|
+
|
17
|
+
@file_server = Rack::File.new(mounting_point.assets_path)
|
18
|
+
|
19
|
+
call_without_threadsafety(env)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Locomotive::Steam
|
2
|
-
|
2
|
+
module Middlewares
|
3
3
|
|
4
|
-
class TemplatizedPage <
|
4
|
+
class TemplatizedPage < Base
|
5
5
|
|
6
|
-
def
|
7
|
-
|
6
|
+
def _call(env)
|
7
|
+
super
|
8
8
|
|
9
9
|
if self.page && self.page.templatized?
|
10
10
|
self.set_content_entry!(env)
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Locomotive::Steam
|
2
|
-
|
2
|
+
module Middlewares
|
3
3
|
|
4
4
|
# Set the timezone according to the settings of the site
|
5
5
|
#
|
6
|
-
class Timezone <
|
6
|
+
class Timezone < Base
|
7
7
|
|
8
|
-
def
|
9
|
-
|
8
|
+
def _call(env)
|
9
|
+
super
|
10
10
|
|
11
11
|
Time.use_zone(site.try(:timezone) || 'UTC') do
|
12
12
|
app.call(env)
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require_relative 'core_ext.rb'
|
2
|
+
|
3
|
+
require_relative 'initializers/i18n.rb'
|
4
|
+
require_relative 'initializers/markdown.rb'
|
5
|
+
require_relative 'initializers/will_paginate.rb'
|
6
|
+
|
7
|
+
require_relative 'monkey_patches/httparty.rb'
|
8
|
+
require_relative 'monkey_patches/dragonfly.rb'
|
9
|
+
require_relative 'monkey_patches/mounter.rb'
|
10
|
+
require_relative 'monkey_patches/haml.rb'
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require_relative 'monkey_patches/httparty.rb'
|
2
|
-
require_relative 'monkey_patches/dragonfly.rb'
|
1
|
+
# require_relative 'monkey_patches/httparty.rb'
|
2
|
+
# require_relative 'monkey_patches/dragonfly.rb'
|
3
3
|
require_relative 'monkey_patches/mounter.rb'
|
4
|
-
require_relative 'monkey_patches/haml.rb'
|
5
|
-
require_relative 'monkey_patches/better_errors.rb'
|
4
|
+
require_relative 'monkey_patches/haml.rb'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'haml'
|
2
|
+
|
1
3
|
module Haml::Filters
|
2
4
|
|
3
5
|
remove_filter("Markdown") #remove the existing Markdown filter
|
@@ -7,7 +9,7 @@ module Haml::Filters
|
|
7
9
|
include Haml::Filters::Base
|
8
10
|
|
9
11
|
def render text
|
10
|
-
Locomotive::Steam::Markdown.
|
12
|
+
Locomotive::Steam::Markdown.new.render text
|
11
13
|
end
|
12
14
|
|
13
15
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'locomotive/mounter'
|
2
|
+
|
1
3
|
module Locomotive
|
2
4
|
module Mounter
|
3
5
|
module Models
|
@@ -28,5 +30,25 @@ module Locomotive
|
|
28
30
|
|
29
31
|
end
|
30
32
|
end
|
33
|
+
|
34
|
+
module Reader
|
35
|
+
module FileSystem
|
36
|
+
class Runner
|
37
|
+
|
38
|
+
def new_mounting_point(host)
|
39
|
+
self.mounting_point
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class MountingPoint
|
47
|
+
|
48
|
+
def assets_path
|
49
|
+
File.join(self.path, 'public')
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
31
53
|
end
|
32
54
|
end
|
@@ -1,80 +1,55 @@
|
|
1
|
-
|
2
|
-
require 'coffee_script'
|
3
|
-
|
4
|
-
require_relative 'listen'
|
5
|
-
require_relative 'server/middleware'
|
6
|
-
require_relative 'server/favicon'
|
7
|
-
require_relative 'server/dynamic_assets'
|
8
|
-
require_relative 'server/logging'
|
9
|
-
require_relative 'server/entry_submission'
|
10
|
-
require_relative 'server/path'
|
11
|
-
require_relative 'server/locale'
|
12
|
-
require_relative 'server/page'
|
13
|
-
require_relative 'server/timezone'
|
14
|
-
require_relative 'server/templatized_page'
|
15
|
-
require_relative 'server/renderer'
|
16
|
-
|
17
|
-
require_relative 'liquid'
|
18
|
-
require_relative 'initializers'
|
1
|
+
require_relative 'core_ext'
|
19
2
|
require_relative 'monkey_patches'
|
3
|
+
require_relative 'liquid'
|
4
|
+
require_relative 'services'
|
5
|
+
require_relative 'middlewares'
|
20
6
|
|
21
7
|
module Locomotive::Steam
|
22
8
|
class Server
|
23
9
|
|
24
|
-
|
25
|
-
Locomotive::Steam::Dragonfly.setup!(reader.mounting_point.path)
|
26
|
-
|
27
|
-
Sprockets::Sass.add_sass_functions = false
|
10
|
+
attr_reader :reader, :app, :options
|
28
11
|
|
29
|
-
|
30
|
-
@
|
12
|
+
def initialize(reader, options = {})
|
13
|
+
@reader = reader
|
14
|
+
@options = options
|
31
15
|
|
32
|
-
|
16
|
+
stack = Middlewares::Stack.new(options)
|
17
|
+
@app = stack.create
|
33
18
|
end
|
34
19
|
|
35
20
|
def call(env)
|
36
|
-
env
|
37
|
-
@app.call(env)
|
21
|
+
dup._call(env) # thread-safe purpose
|
38
22
|
end
|
39
23
|
|
40
|
-
|
41
|
-
|
42
|
-
def create_rack_app(reader)
|
43
|
-
Rack::Builder.new do
|
44
|
-
use Rack::Lint
|
45
|
-
|
46
|
-
use BetterErrors::MiddlewareWrapper
|
47
|
-
|
48
|
-
use Rack::Session::Cookie, {
|
49
|
-
key: 'steam.session',
|
50
|
-
path: '/',
|
51
|
-
expire_after: 2592000,
|
52
|
-
secret: 'uselessinlocal'
|
53
|
-
}
|
24
|
+
def _call(env)
|
25
|
+
set_request(env)
|
54
26
|
|
55
|
-
|
27
|
+
set_mounting_point(env)
|
56
28
|
|
57
|
-
|
58
|
-
urls: ['/images', '/fonts', '/samples', '/media'],
|
59
|
-
root: File.join(reader.mounting_point.path, 'public')
|
60
|
-
}
|
29
|
+
set_services(env)
|
61
30
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
use Logging
|
31
|
+
@app.call(env)
|
32
|
+
end
|
66
33
|
|
67
|
-
|
34
|
+
protected
|
68
35
|
|
69
|
-
|
70
|
-
|
71
|
-
|
36
|
+
def set_request(env)
|
37
|
+
@request = Rack::Request.new(env)
|
38
|
+
env['steam.request'] = @request
|
39
|
+
end
|
72
40
|
|
73
|
-
|
74
|
-
|
41
|
+
def set_mounting_point(env)
|
42
|
+
# one single mounting point per site
|
43
|
+
@mounting_point = @reader.new_mounting_point(@request.host)
|
44
|
+
env['steam.mounting_point'] = @reader.mounting_point
|
45
|
+
end
|
75
46
|
|
76
|
-
|
77
|
-
|
47
|
+
def set_services(env)
|
48
|
+
env['steam.services'] = {
|
49
|
+
dragonfly: Locomotive::Steam::Services::Dragonfly.new(@mounting_point.path),
|
50
|
+
markdown: Locomotive::Steam::Services::Markdown.new,
|
51
|
+
external_api: Locomotive::Steam::Services::ExternalAPI.new
|
52
|
+
}
|
78
53
|
end
|
79
54
|
|
80
55
|
end
|