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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/CHANGELOG.md +5 -0
  4. data/Gemfile +7 -0
  5. data/Gemfile.lock +19 -30
  6. data/bin/publish +8 -8
  7. data/example/server.rb +27 -0
  8. data/lib/locomotive/steam/exceptions.rb +2 -2
  9. data/lib/locomotive/steam/initializers.rb +6 -4
  10. data/lib/locomotive/steam/initializers/dragonfly.rb +19 -0
  11. data/lib/locomotive/steam/initializers/sprockets.rb +1 -0
  12. data/lib/locomotive/steam/liquid.rb +1 -1
  13. data/lib/locomotive/steam/liquid/filters/resize.rb +2 -1
  14. data/lib/locomotive/steam/liquid/scopeable.rb +2 -2
  15. data/lib/locomotive/steam/liquid/tags/consume.rb +6 -1
  16. data/lib/locomotive/steam/liquid/tags/editable/short_text.rb +1 -1
  17. data/lib/locomotive/steam/liquid/tags/snippet.rb +1 -1
  18. data/lib/locomotive/steam/middlewares.rb +15 -0
  19. data/lib/locomotive/steam/{server/middleware.rb → middlewares/base.rb} +13 -11
  20. data/lib/locomotive/steam/middlewares/dynamic_assets.rb +40 -0
  21. data/lib/locomotive/steam/{server → middlewares}/entry_submission.rb +4 -4
  22. data/lib/locomotive/steam/{server → middlewares}/favicon.rb +2 -3
  23. data/lib/locomotive/steam/{server → middlewares}/locale.rb +4 -4
  24. data/lib/locomotive/steam/{server → middlewares}/logging.rb +2 -2
  25. data/lib/locomotive/steam/{server → middlewares}/page.rb +4 -6
  26. data/lib/locomotive/steam/{server → middlewares}/path.rb +4 -4
  27. data/lib/locomotive/steam/{server → middlewares}/renderer.rb +6 -5
  28. data/lib/locomotive/steam/middlewares/stack.rb +66 -0
  29. data/lib/locomotive/steam/middlewares/static_assets.rb +25 -0
  30. data/lib/locomotive/steam/{server → middlewares}/templatized_page.rb +4 -4
  31. data/lib/locomotive/steam/{server → middlewares}/timezone.rb +4 -4
  32. data/lib/locomotive/steam/misc.rb +10 -0
  33. data/lib/locomotive/steam/monkey_patches.rb +3 -4
  34. data/lib/locomotive/steam/monkey_patches/haml.rb +3 -1
  35. data/lib/locomotive/steam/monkey_patches/mounter.rb +22 -0
  36. data/lib/locomotive/steam/server.rb +33 -58
  37. data/lib/locomotive/steam/services.rb +1 -0
  38. data/lib/locomotive/steam/services/dragonfly.rb +49 -0
  39. data/lib/locomotive/steam/{monkey_patches/httparty.rb → services/external_api.rb} +6 -6
  40. data/lib/locomotive/steam/services/markdown.rb +29 -0
  41. data/lib/locomotive/steam/standalone_server.rb +9 -12
  42. data/lib/locomotive/steam/version.rb +1 -1
  43. data/lib/steam.rb +0 -1
  44. data/locomotivecms_steam.gemspec +8 -9
  45. data/spec/integration/integration_helper.rb +2 -13
  46. data/spec/integration/server/basic_spec.rb +0 -6
  47. data/spec/integration/server/contact_form_spec.rb +0 -4
  48. data/spec/integration/server/liquid_spec.rb +0 -4
  49. data/spec/integration/server/with_scope_spec.rb +0 -4
  50. data/spec/spec_helper.rb +1 -0
  51. data/spec/support/helpers.rb +13 -4
  52. metadata +47 -57
  53. data/lib/locomotive/steam/initializers/markdown.rb +0 -27
  54. data/lib/locomotive/steam/initializers/will_paginate.rb +0 -16
  55. data/lib/locomotive/steam/listen.rb +0 -64
  56. data/lib/locomotive/steam/logger.rb +0 -54
  57. data/lib/locomotive/steam/monkey_patches/better_errors.rb +0 -70
  58. data/lib/locomotive/steam/monkey_patches/dragonfly.rb +0 -79
  59. data/lib/locomotive/steam/server/dynamic_assets.rb +0 -33
@@ -1,27 +0,0 @@
1
- require 'redcarpet'
2
-
3
- module Locomotive
4
- module Steam
5
- module Markdown
6
-
7
- def self.render(text)
8
- self.parser.render(text)
9
- end
10
-
11
- def self.parser
12
- @@markdown ||= Redcarpet::Markdown.new Redcarpet::Steam::HTML, {
13
- autolink: true,
14
- fenced_code: true,
15
- generate_toc: true,
16
- gh_blockcode: true,
17
- hard_wrap: true,
18
- no_intraemphasis: true,
19
- strikethrough: true,
20
- tables: true,
21
- xhtml: true
22
- }
23
- end
24
-
25
- end
26
- end
27
- end
@@ -1,16 +0,0 @@
1
- require 'will_paginate'
2
- require 'will_paginate/collection'
3
-
4
- Array.class_eval do
5
- def paginate(options = {})
6
- raise ArgumentError, "parameter hash expected (got #{options.inspect})" unless Hash === options
7
-
8
- WillPaginate::Collection.create(
9
- options[:page] || 1,
10
- options[:per_page] || 30,
11
- options[:total_entries] || self.length
12
- ) { |pager|
13
- pager.replace self[pager.offset, pager.per_page].to_a
14
- }
15
- end
16
- end
@@ -1,64 +0,0 @@
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
@@ -1,54 +0,0 @@
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
@@ -1,70 +0,0 @@
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
@@ -1,79 +0,0 @@
1
- module Locomotive
2
- module Steam
3
- class Dragonfly
4
-
5
- attr_accessor :path, :enabled
6
-
7
- def enabled?
8
- !!self.enabled
9
- end
10
-
11
- def resize_url(source, resize_string)
12
- _source = (case source
13
- when String then source
14
- when Hash then source['url'] || source[:url]
15
- else
16
- source.try(:url)
17
- end)
18
-
19
- if _source.blank?
20
- Locomotive::Steam::Logger.error "Unable to resize on the fly: #{source.inspect}"
21
- return
22
- end
23
-
24
- return _source unless self.enabled?
25
-
26
- if _source =~ /^http/
27
- file = self.class.app.fetch_url(_source)
28
- else
29
- file = self.class.app.fetch_file(File.join(self.path, 'public', _source))
30
- end
31
-
32
- file.process(:thumb, resize_string).url
33
- end
34
-
35
- def self.app
36
- ::Dragonfly[:images]
37
- end
38
-
39
-
40
- def self.instance
41
- @@instance ||= new
42
- end
43
-
44
- def self.setup!(path)
45
- self.instance.path = path
46
- self.instance.enabled = false
47
-
48
- begin
49
- require 'rack/cache'
50
- require 'dragonfly'
51
-
52
- ## initialize Dragonfly ##
53
- app = ::Dragonfly[:images].configure_with(:imagemagick)
54
-
55
- ## configure it ##
56
- ::Dragonfly[:images].configure do |c|
57
- convert = `which convert`.strip.presence || '/usr/bin/env convert'
58
- c.convert_command = convert
59
- c.identify_command = convert
60
-
61
- c.allow_fetch_url = true
62
- c.allow_fetch_file = true
63
-
64
- c.url_format = '/images/dynamic/:job/:basename.:format'
65
- end
66
-
67
- self.instance.enabled = true
68
- rescue Exception => e
69
-
70
- Locomotive::Steam::Logger.warn %{
71
- [Dragonfly] !disabled!
72
- [Dragonfly] If you want to take full benefits of all the features in the LocomotiveSteam, we recommend you to install ImageMagick and RMagick. Check out the documentation here: http://doc.locomotivecms.com/editor/installation.
73
- }
74
- end
75
- end
76
-
77
- end
78
- end
79
- end
@@ -1,33 +0,0 @@
1
- module Locomotive::Steam
2
- class Server
3
-
4
- class DynamicAssets < Middleware
5
-
6
- attr_reader :app, :sprockets, :regexp
7
-
8
- def initialize(app, site_path)
9
- super(app)
10
-
11
- @regexp = /^\/(javascripts|stylesheets)\/(.*)$/
12
-
13
- @sprockets = Locomotive::Mounter::Extensions::Sprockets.environment(site_path)
14
- end
15
-
16
- def call(env)
17
- if env['PATH_INFO'] =~ self.regexp
18
- env['PATH_INFO'] = $2
19
-
20
- begin
21
- self.sprockets.call(env)
22
- rescue Exception => e
23
- raise Locomotive::Steam::DefaultException.new "Unable to serve a dynamic asset. Please check the logs.", e
24
- end
25
- else
26
- app.call(env)
27
- end
28
- end
29
-
30
- end
31
-
32
- end
33
- end