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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 286924b9da97684b0d41b2f7665c1bf10d8e7a3c
4
- data.tar.gz: 995313de3bb43273c996c3bed12154fb03e6ac0d
3
+ metadata.gz: 8893681c8f5eb7eb8d2679fd660ae4aed7e731f5
4
+ data.tar.gz: 9ee2f1cacf9d807e2194f139cabd844743cf3dc7
5
5
  SHA512:
6
- metadata.gz: d54ce2aac8f838cc950fae949838fa61cb1b223bd43c9cb37abfff14abc41d34feae2674fb45efeec822a924b833834ed2f3d66a32a0de44cff2ae2321888941
7
- data.tar.gz: aabe22de1742646c3ee9281b87845ac1cf87b5eb1a26ba3f93b83133103724b318f62dbd534727cf32723519e563fa6c0493e159426605931955bf67e2b54e90
6
+ metadata.gz: 9090a78846cc972558e88da4dba21c6aa44b30585608467ca09e666e18022f85572f3de3861be7e7c95a13433a37410270417edf9a71095c69ad181bb08c5089
7
+ data.tar.gz: 0ef2642d9cf8fe0d28cf30621f48eabf294ce02d396e37096031455d8f3062b809f88bae38270587b09233d316d8f2580a124e04ce4e0619656b68fd9d6d757d
data/.gitignore CHANGED
@@ -19,3 +19,7 @@ doc/
19
19
 
20
20
  .rspec
21
21
  spec/fixtures/default/log/*
22
+
23
+ .ruby-*
24
+
25
+ log
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### VERSION 0.1.1
2
+
3
+ * refactoring
4
+ * remove logger from core
5
+
1
6
  ### VERSION 0.0.1
2
7
 
3
8
  * bug fix
data/Gemfile CHANGED
@@ -2,7 +2,14 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
+ group :development do
6
+ gem 'locomotivecms_common', '~> 0.0.1', require: 'common' # path: '../common'
7
+ gem 'thin'
8
+ end
9
+
5
10
  group :test do
6
11
  gem 'pry'
7
12
  gem 'coveralls', require: false
8
13
  end
14
+
15
+ gem 'thin'
data/Gemfile.lock CHANGED
@@ -1,13 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- locomotivecms_steam (0.1.0)
5
- activesupport (~> 3.2)
6
- better_errors (~> 1.0)
7
- dragonfly (~> 0.9)
8
- listen (~> 2.7)
4
+ locomotivecms_steam (0.1.1)
5
+ dragonfly (~> 1.0.3)
9
6
  locomotivecms-solid
7
+ locomotivecms_common (~> 0.0.1)
10
8
  locomotivecms_mounter
9
+ moneta (~> 0.7.20)
11
10
  rack-cache (~> 1.1)
12
11
  redcarpet (~> 3.1)
13
12
  sprockets (~> 2.0)
@@ -22,14 +21,6 @@ GEM
22
21
  i18n (~> 0.6, >= 0.6.4)
23
22
  multi_json (~> 1.0)
24
23
  addressable (2.3.6)
25
- better_errors (1.1.0)
26
- coderay (>= 1.0.0)
27
- erubis (>= 2.6.6)
28
- celluloid (0.15.2)
29
- timers (~> 1.1.0)
30
- celluloid-io (0.15.0)
31
- celluloid (>= 0.15.0)
32
- nio4r (>= 0.5.0)
33
24
  chronic (0.10.2)
34
25
  chunky_png (1.3.0)
35
26
  coderay (1.1.0)
@@ -39,10 +30,10 @@ GEM
39
30
  coffee-script-source (1.7.0)
40
31
  colorize (0.5.8)
41
32
  commonjs (0.2.7)
42
- compass (0.12.4)
33
+ compass (0.12.5)
43
34
  chunky_png (~> 1.2)
44
35
  fssm (>= 0.2.7)
45
- sass (~> 3.2.17)
36
+ sass (~> 3.2.19)
46
37
  coveralls (0.7.0)
47
38
  multi_json (~> 1.3)
48
39
  rest-client
@@ -51,14 +42,14 @@ GEM
51
42
  thor
52
43
  crack (0.4.2)
53
44
  safe_yaml (~> 1.0.0)
45
+ daemons (1.1.9)
54
46
  diff-lcs (1.2.5)
55
47
  docile (1.1.3)
56
- dragonfly (0.9.15)
48
+ dragonfly (1.0.4)
57
49
  multi_json (~> 1.0)
58
50
  rack
59
- erubis (2.7.0)
51
+ eventmachine (1.0.3)
60
52
  execjs (2.0.2)
61
- ffi (1.9.3)
62
53
  fssm (0.2.10)
63
54
  haml (4.0.5)
64
55
  tilt
@@ -66,7 +57,7 @@ GEM
66
57
  httmultiparty (0.3.10)
67
58
  httparty (>= 0.7.3)
68
59
  multipart-post
69
- httparty (0.13.0)
60
+ httparty (0.13.1)
70
61
  json (~> 1.8)
71
62
  multi_xml (>= 0.5.2)
72
63
  i18n (0.6.9)
@@ -79,14 +70,10 @@ GEM
79
70
  addressable (~> 2.3)
80
71
  less (2.2.2)
81
72
  commonjs (~> 0.2.6)
82
- listen (2.7.1)
83
- celluloid (>= 0.15.2)
84
- celluloid-io (>= 0.15.0)
85
- rb-fsevent (>= 0.9.3)
86
- rb-inotify (>= 0.9)
87
73
  locomotivecms-liquid (2.6.0)
88
74
  locomotivecms-solid (0.2.2.1)
89
75
  locomotivecms-liquid (~> 2.6.0)
76
+ locomotivecms_common (0.0.1)
90
77
  locomotivecms_mounter (1.4.0)
91
78
  RedCloth (~> 4.2.3)
92
79
  activesupport (~> 3.2.15)
@@ -112,10 +99,10 @@ GEM
112
99
  logger (1.2.8)
113
100
  method_source (0.8.2)
114
101
  mime-types (1.25.1)
102
+ moneta (0.7.20)
115
103
  multi_json (1.7.9)
116
104
  multi_xml (0.5.5)
117
105
  multipart-post (2.0.0)
118
- nio4r (1.0.0)
119
106
  pry (0.9.12.6)
120
107
  coderay (~> 1.0)
121
108
  method_source (~> 0.8)
@@ -126,9 +113,6 @@ GEM
126
113
  rack-test (0.6.2)
127
114
  rack (>= 1.0)
128
115
  rake (10.2.2)
129
- rb-fsevent (0.9.4)
130
- rb-inotify (0.9.3)
131
- ffi (>= 0.5.0)
132
116
  redcarpet (3.1.1)
133
117
  rest-client (1.6.7)
134
118
  mime-types (>= 1.16)
@@ -141,7 +125,7 @@ GEM
141
125
  diff-lcs (>= 1.1.3, < 2.0)
142
126
  rspec-mocks (2.14.6)
143
127
  safe_yaml (1.0.1)
144
- sass (3.2.18)
128
+ sass (3.2.19)
145
129
  simplecov (0.8.2)
146
130
  docile (~> 1.1.0)
147
131
  multi_json
@@ -159,9 +143,12 @@ GEM
159
143
  stringex (2.0.11)
160
144
  term-ansicolor (1.3.0)
161
145
  tins (~> 1.0)
146
+ thin (1.6.2)
147
+ daemons (>= 1.0.9)
148
+ eventmachine (>= 1.0.0)
149
+ rack (>= 1.0.0)
162
150
  thor (0.18.1)
163
151
  tilt (1.4.1)
164
- timers (1.1.0)
165
152
  tins (1.0.0)
166
153
  tzinfo (0.3.39)
167
154
  vcr (2.9.0)
@@ -179,10 +166,12 @@ DEPENDENCIES
179
166
  coveralls
180
167
  i18n-spec
181
168
  launchy
169
+ locomotivecms_common (~> 0.0.1)
182
170
  locomotivecms_steam!
183
171
  pry
184
172
  rack-test
185
173
  rake (~> 10.1)
186
174
  rspec (~> 2.14)
175
+ thin
187
176
  vcr
188
177
  webmock
data/bin/publish CHANGED
@@ -6,8 +6,8 @@ require_relative '../lib/steam'
6
6
 
7
7
  class Publish
8
8
 
9
- def start version, rvm=false
10
- system "rvm use #{rvm}"
9
+ def start # version, rvm=false
10
+ # system "rvm use #{rvm}"
11
11
 
12
12
  system "bundle && bundle exec rspec"
13
13
  system "gem build locomotivecms_steam.gemspec"
@@ -19,10 +19,10 @@ class Publish
19
19
 
20
20
  end
21
21
 
22
- if ARGV.length != 1 # or !ARGV[0].match(/\d{1,3}.\d{1,3}.\d{1,3}/)
23
- puts 'HELP: '
24
- puts '$ bin/publish [ruby-2.1.1@steam]'
25
- exit 0
26
- end
22
+ # if ARGV.length != 1 # or !ARGV[0].match(/\d{1,3}.\d{1,3}.\d{1,3}/)
23
+ # puts 'HELP: '
24
+ # puts '$ bin/publish [ruby-2.1.1@steam]'
25
+ # exit 0
26
+ # end
27
27
 
28
- Publish.new.start ARGV[0]
28
+ Publish.new.start # ARGV[0]
data/example/server.rb ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+
6
+ Bundler.require
7
+
8
+ require 'thin'
9
+ require 'common'
10
+
11
+ require_relative '../lib/steam'
12
+ require_relative '../lib/locomotive/steam/server'
13
+ require_relative '../lib/locomotive/steam/initializers'
14
+
15
+ path = ENV['SITE_PATH'] || File.join(File.expand_path(File.dirname(__FILE__)), '../spec/fixtures/default')
16
+ reader = Locomotive::Mounter::Reader::FileSystem.instance
17
+ reader.run!(path: path)
18
+
19
+ app = Locomotive::Steam::Server.new(reader, {
20
+ serve_assets: true
21
+ })
22
+
23
+ server = Thin::Server.new('localhost', '3333', app)
24
+ server.threaded = true
25
+
26
+ Locomotive::Common::Logger.info 'Server started...'
27
+ server.start
@@ -15,7 +15,7 @@ module Locomotive
15
15
  full_error_message = "#{parent_exception.message}\n\t"
16
16
  full_error_message += parent_exception.backtrace.join("\n\t")
17
17
  full_error_message += "\n\n"
18
- Locomotive::Steam::Logger.fatal full_error_message
18
+ Locomotive::Common::Logger.fatal full_error_message
19
19
  end
20
20
 
21
21
  end
@@ -40,7 +40,7 @@ module Locomotive
40
40
 
41
41
  message = "#{self.template.filepath}:#{line}:in `#{self.name}'"
42
42
 
43
- Locomotive::Steam::Logger.fatal "[ERROR] #{exception.message} - #{message}\n".red
43
+ Locomotive::Common::Logger.fatal "[ERROR] #{exception.message} - #{message}\n".red
44
44
 
45
45
  exception.backtrace.unshift message
46
46
  end
@@ -1,5 +1,7 @@
1
- require_relative 'core_ext.rb'
2
-
1
+ require_relative 'initializers/sprockets.rb'
3
2
  require_relative 'initializers/i18n.rb'
4
- require_relative 'initializers/markdown.rb'
5
- require_relative 'initializers/will_paginate.rb'
3
+ require_relative 'initializers/dragonfly.rb'
4
+
5
+ Locomotive::Common.configure do |config|
6
+ config.notifier = Locomotive::Common::Logger.setup
7
+ end
@@ -0,0 +1,19 @@
1
+ require 'dragonfly'
2
+ require 'common'
3
+
4
+ # Configure
5
+ Dragonfly.app(:steam).configure do
6
+ plugin :imagemagick,
7
+ convert_command: `which convert`.strip.presence || '/usr/local/bin/convert',
8
+ identify_command: `which identify`.strip.presence || '/usr/local/bin/identify'
9
+
10
+ protect_from_dos_attacks true
11
+
12
+ url_format '/images/dynamic/:job/:basename.:ext'
13
+
14
+ fetch_file_whitelist /public/
15
+
16
+ fetch_url_whitelist /.+/
17
+ end
18
+
19
+ Dragonfly.logger = Locomotive::Common::Logger.instance
@@ -0,0 +1 @@
1
+ Sprockets::Sass.add_sass_functions = false
@@ -6,7 +6,7 @@ require_relative 'liquid/drops/base'
6
6
  require_relative 'liquid/tags/hybrid'
7
7
  require_relative 'liquid/tags/path_helper'
8
8
 
9
- %w{. drops tags filters }.each do |dir|
9
+ %w{. drops tags filters}.each do |dir|
10
10
  Dir[File.join(File.dirname(__FILE__), 'liquid', dir, '*.rb')].each { |lib| require lib }
11
11
  end
12
12
 
@@ -5,7 +5,8 @@ module Locomotive
5
5
  module Resize
6
6
 
7
7
  def resize(input, resize_string)
8
- Locomotive::Steam::Dragonfly.instance.resize_url(input, resize_string)
8
+ dragonfly = @context.registers[:services][:dragonfly]
9
+ dragonfly.resize_url(input, resize_string)
9
10
  end
10
11
 
11
12
  end
@@ -13,7 +13,7 @@ module Locomotive
13
13
  # build the chains of conditions
14
14
  conditions = _conditions.map { |name, value| Condition.new(name, value) }
15
15
 
16
- Locomotive::Steam::Logger.info "[with_scope] conditions: #{conditions.map(&:to_s).join(', ')}"
16
+ Locomotive::Common::Logger.info "[with_scope] conditions: #{conditions.map(&:to_s).join(', ')}"
17
17
 
18
18
  # get only the entries matching ALL the conditions
19
19
  _entries = entries.find_all do |content|
@@ -38,7 +38,7 @@ module Locomotive
38
38
 
39
39
  name, direction = order_by.split.map(&:to_sym)
40
40
 
41
- Locomotive::Steam::Logger.info "[with_scope] order_by #{name} #{direction || 'asc'}"
41
+ Locomotive::Common::Logger.info "[with_scope] order_by #{name} #{direction || 'asc'}"
42
42
 
43
43
  if direction == :asc || direction.nil?
44
44
  entries.sort { |a, b| a.send(name) <=> b.send(name) }
@@ -72,7 +72,8 @@ module Locomotive
72
72
  def render_all_without_cache(context)
73
73
  context.stack do
74
74
  begin
75
- context.scopes.last[@target.to_s] = Locomotive::Steam::Httparty::Webservice.consume(@url, @options.symbolize_keys)
75
+ context.scopes.last[@target.to_s] = external_api_service(context).consume(@url, @options.symbolize_keys)
76
+
76
77
  self.cached_response = context.scopes.last[@target.to_s]
77
78
  rescue Timeout::Error
78
79
  context.scopes.last[@target.to_s] = self.cached_response
@@ -88,6 +89,10 @@ module Locomotive
88
89
  end
89
90
  end
90
91
 
92
+ def external_api_service(context)
93
+ context.registers[:services][:external_api]
94
+ end
95
+
91
96
  end
92
97
 
93
98
  ::Liquid::Template.register_tag('consume', Consume)
@@ -6,7 +6,7 @@ module Locomotive
6
6
  class ShortText < Base
7
7
 
8
8
  def render(context)
9
- Locomotive::Steam::Logger.warn " [#{self.current_block_name(context)}/#{@slug}] The editable_{short|long}_text tags are deprecated. Use editable_text instead.".colorize(:orange)
9
+ Locomotive::Common::Logger.warn " [#{self.current_block_name(context)}/#{@slug}] The editable_{short|long}_text tags are deprecated. Use editable_text instead.".colorize(:orange)
10
10
  super(context)
11
11
  end
12
12
 
@@ -30,7 +30,7 @@ module Locomotive
30
30
  partial.render(context)
31
31
  end)
32
32
 
33
- Locomotive::Steam::Logger.info " Steamed snippet #{name}"
33
+ Locomotive::Common::Logger.info " Steamed snippet #{name}"
34
34
 
35
35
  output
36
36
  end
@@ -0,0 +1,15 @@
1
+ require_relative 'middlewares/base'
2
+
3
+ require_relative 'middlewares/favicon'
4
+ require_relative 'middlewares/static_assets'
5
+ require_relative 'middlewares/dynamic_assets'
6
+ require_relative 'middlewares/logging'
7
+ require_relative 'middlewares/entry_submission'
8
+ require_relative 'middlewares/path'
9
+ require_relative 'middlewares/locale'
10
+ require_relative 'middlewares/page'
11
+ require_relative 'middlewares/timezone'
12
+ require_relative 'middlewares/templatized_page'
13
+ require_relative 'middlewares/renderer'
14
+
15
+ require_relative 'middlewares/stack'
@@ -1,10 +1,10 @@
1
1
  module Locomotive::Steam
2
- class Server
2
+ module Middlewares
3
3
 
4
- class Middleware
5
-
6
- attr_accessor :app, :request, :path, :liquid_assigns
4
+ class Base
7
5
 
6
+ attr_accessor :app, :request, :path
7
+ attr_accessor :liquid_assigns, :services
8
8
  attr_accessor :mounting_point, :page, :content_entry
9
9
 
10
10
  def initialize(app = nil)
@@ -12,17 +12,19 @@ module Locomotive::Steam
12
12
  end
13
13
 
14
14
  def call(env)
15
- app.call(env)
15
+ dup._call(env) # thread-safe purpose
16
+ end
17
+
18
+ def _call(env)
19
+ self.set_accessors(env)
16
20
  end
17
21
 
18
22
  protected
19
23
 
20
24
  def set_accessors(env)
21
- self.path = env['steam.path']
22
- self.request = Rack::Request.new(env)
23
- self.mounting_point = env['steam.mounting_point']
24
- self.page = env['steam.page']
25
- self.content_entry = env['steam.content_entry']
25
+ %w(path request mounting_point page content_entry services).each do |name|
26
+ self.send(:"#{name}=", env["steam.#{name}"])
27
+ end
26
28
 
27
29
  env['steam.liquid_assigns'] ||= {}
28
30
  self.liquid_assigns = env['steam.liquid_assigns']
@@ -52,7 +54,7 @@ module Locomotive::Steam
52
54
  end
53
55
 
54
56
  def log(msg)
55
- Locomotive::Steam::Logger.info msg
57
+ Locomotive::Common::Logger.info msg
56
58
  end
57
59
 
58
60
  end