locomotivecms_builder 1.0.0.alpha2 → 1.0.0.alpha3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +0 -1
- data/lib/locomotive/builder/exceptions.rb +13 -3
- data/lib/locomotive/builder/listen.rb +10 -1
- data/lib/locomotive/builder/logger.rb +54 -0
- data/lib/locomotive/builder/misc/dragonfly.rb +4 -7
- data/lib/locomotive/builder/misc/httparty.rb +2 -3
- data/lib/locomotive/builder/server/locale.rb +1 -1
- data/lib/locomotive/builder/server/logging.rb +32 -0
- data/lib/locomotive/builder/server/middleware.rb +7 -2
- data/lib/locomotive/builder/server/not_found.rb +1 -0
- data/lib/locomotive/builder/server/page.rb +3 -1
- data/lib/locomotive/builder/server/renderer.rb +3 -3
- data/lib/locomotive/builder/server.rb +3 -0
- data/lib/locomotive/builder/version.rb +1 -1
- data/lib/locomotive/builder.rb +11 -15
- data/locomotivecms_builder.gemspec +1 -1
- metadata +7 -5
data/Rakefile
CHANGED
@@ -3,9 +3,19 @@ module Locomotive
|
|
3
3
|
|
4
4
|
class DefaultException < ::Exception
|
5
5
|
|
6
|
-
def initialize(message = nil)
|
7
|
-
|
8
|
-
|
6
|
+
def initialize(message = nil, parent_exception = nil)
|
7
|
+
self.log_backtrace(parent_exception) if parent_exception
|
8
|
+
|
9
|
+
super(message)
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def log_backtrace(parent_exception)
|
15
|
+
full_error_message = "#{parent_exception.message}\n\t"
|
16
|
+
full_error_message += parent_exception.backtrace.join("\n\t")
|
17
|
+
full_error_message += "\n\n"
|
18
|
+
Locomotive::Builder::Logger.fatal full_error_message
|
9
19
|
end
|
10
20
|
|
11
21
|
end
|
@@ -30,7 +30,16 @@ module Locomotive::Builder
|
|
30
30
|
|
31
31
|
def apply(definition)
|
32
32
|
reloader = Proc.new do |modified, added, removed|
|
33
|
-
|
33
|
+
resources = [*definition.last]
|
34
|
+
names = resources.map { |n| "\"#{n}\"" }.join(', ')
|
35
|
+
|
36
|
+
Locomotive::Builder::Logger.info "* Reloaded #{names} at #{Time.now}"
|
37
|
+
|
38
|
+
begin
|
39
|
+
reader.reload(resources)
|
40
|
+
rescue Exception => e
|
41
|
+
Locomotive::Builder::MounterException.new('Unable to reload', e)
|
42
|
+
end
|
34
43
|
end
|
35
44
|
|
36
45
|
filter = definition[1]
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Locomotive
|
2
|
+
module Builder
|
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/builder.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', 'builder.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
|
@@ -65,15 +65,12 @@ module Locomotive
|
|
65
65
|
c.url_format = '/images/dynamic/:job/:basename.:format'
|
66
66
|
end
|
67
67
|
|
68
|
-
puts 'Dragonfly enabled'
|
69
|
-
|
70
68
|
self.instance.enabled = true
|
71
69
|
rescue Exception => e
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
puts 'Dragonfly disabled'
|
70
|
+
Locomotive::Builder::Logger.warn %{
|
71
|
+
[Dragonfly] !disabled!
|
72
|
+
[Dragonfly] If you want to take full benefits of all the features in the LocomotiveBuilder, we recommend you to install ImageMagick and RMagick. Check out the documentation here: http://doc.locomotivecms.com/editor/installation.
|
73
|
+
}
|
77
74
|
end
|
78
75
|
end
|
79
76
|
|
@@ -22,7 +22,7 @@ module Locomotive
|
|
22
22
|
|
23
23
|
path ||= '/'
|
24
24
|
|
25
|
-
#
|
25
|
+
# Locomotive::Builder::Logger.debug "[WebService] consuming #{path}, #{options.inspect}"
|
26
26
|
|
27
27
|
response = self.get(path, options)
|
28
28
|
|
@@ -34,8 +34,7 @@ module Locomotive
|
|
34
34
|
_response.collect(&:underscore_keys)
|
35
35
|
end
|
36
36
|
else
|
37
|
-
#
|
38
|
-
puts "[Locomotive][Builder][Error] consuming #{path}, #{options.inspect}, response = #{response.inspect}"
|
37
|
+
Locomotive::Builder::Logger.error "[WebService] consumed #{path}, #{options.inspect}, response = #{response.inspect}"
|
39
38
|
nil
|
40
39
|
end
|
41
40
|
|
@@ -31,7 +31,7 @@ module Locomotive::Builder
|
|
31
31
|
Locomotive::Mounter.locale = locale
|
32
32
|
::I18n.locale = locale
|
33
33
|
|
34
|
-
|
34
|
+
self.log "Detecting locale #{locale.upcase}"
|
35
35
|
|
36
36
|
env['builder.locale'] = locale
|
37
37
|
env['builder.path'] = self.path
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Locomotive::Builder
|
2
|
+
class Server
|
3
|
+
|
4
|
+
# Track the request into the current logger
|
5
|
+
#
|
6
|
+
class Logging < Middleware
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
now = Time.now
|
10
|
+
|
11
|
+
log "Started #{env['REQUEST_METHOD'].upcase} \"#{env['PATH_INFO']}\" at #{now}"
|
12
|
+
|
13
|
+
app.call(env).tap do |response|
|
14
|
+
done_in_ms = (Time.now - now) * 1000
|
15
|
+
log "Completed #{code_to_human(response.first)} in #{done_in_ms}ms\n\n"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def code_to_human(code)
|
22
|
+
case code.to_i
|
23
|
+
when 200 then '200 OK'
|
24
|
+
when 301 then '301 Found'
|
25
|
+
when 302 then '302 Found'
|
26
|
+
when 404 then '404 Not Found'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -44,8 +44,13 @@ module Locomotive::Builder
|
|
44
44
|
self.request.content_type == 'application/json' || File.extname(self.request.path) == '.json'
|
45
45
|
end
|
46
46
|
|
47
|
-
def redirect_to(location)
|
48
|
-
|
47
|
+
def redirect_to(location, type = 301)
|
48
|
+
self.log "Redirected to #{location}"
|
49
|
+
[type, { 'Content-Type' => 'text/html', 'Location' => location }, []]
|
50
|
+
end
|
51
|
+
|
52
|
+
def log(msg)
|
53
|
+
Locomotive::Builder::Logger.info msg
|
49
54
|
end
|
50
55
|
|
51
56
|
end
|
@@ -6,12 +6,12 @@ module Locomotive::Builder
|
|
6
6
|
def call(env)
|
7
7
|
self.set_accessors(env)
|
8
8
|
|
9
|
-
puts "[Builder|Renderer] page = #{page.inspect}"
|
10
|
-
|
11
9
|
if self.page
|
12
10
|
if self.page.redirect?
|
13
|
-
|
11
|
+
self.redirect_to(self.page.redirect_url, self.page.redirect_type)
|
14
12
|
else
|
13
|
+
self.log "Rendered liquid template"
|
14
|
+
|
15
15
|
type = self.page.response_type || 'text/html'
|
16
16
|
html = self.render
|
17
17
|
|
@@ -5,6 +5,7 @@ require 'locomotive/builder/listen'
|
|
5
5
|
require 'locomotive/builder/server/middleware'
|
6
6
|
require 'locomotive/builder/server/favicon'
|
7
7
|
require 'locomotive/builder/server/dynamic_assets'
|
8
|
+
require 'locomotive/builder/server/logging'
|
8
9
|
require 'locomotive/builder/server/entry_submission'
|
9
10
|
require 'locomotive/builder/server/path'
|
10
11
|
require 'locomotive/builder/server/locale'
|
@@ -60,6 +61,8 @@ module Locomotive::Builder
|
|
60
61
|
use Favicon
|
61
62
|
use DynamicAssets
|
62
63
|
|
64
|
+
use Logging
|
65
|
+
|
63
66
|
use EntrySubmission
|
64
67
|
|
65
68
|
use Path
|
data/lib/locomotive/builder.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'locomotive/builder/version'
|
2
|
+
require 'locomotive/builder/logger'
|
2
3
|
require 'locomotive/builder/exceptions'
|
3
4
|
|
4
5
|
module Locomotive
|
@@ -141,27 +142,22 @@ module Locomotive
|
|
141
142
|
# @param [ Object ] An instance of the reader is the get_reader parameter has been set.
|
142
143
|
#
|
143
144
|
def self.require_mounter(path, get_reader = false)
|
144
|
-
|
145
|
+
Locomotive::Builder::Logger.setup(path, false)
|
145
146
|
|
146
|
-
|
147
|
-
FileUtils.mkdir_p(File.dirname(logfile))
|
147
|
+
require 'locomotive/mounter'
|
148
148
|
|
149
|
-
Locomotive::Mounter.logger = ::Logger.
|
150
|
-
log.level = Logger::DEBUG
|
151
|
-
end
|
149
|
+
Locomotive::Mounter.logger = Locomotive::Builder::Logger.instance.logger
|
152
150
|
|
153
|
-
# begin
|
154
151
|
if get_reader
|
155
|
-
|
156
|
-
|
157
|
-
|
152
|
+
begin
|
153
|
+
reader = Locomotive::Mounter::Reader::FileSystem.instance
|
154
|
+
reader.run!(path: path)
|
155
|
+
reader
|
156
|
+
rescue Exception => e
|
157
|
+
raise Locomotive::Builder::MounterException.new "Unable to read the local LocomotiveCMS site. Please check the logs.", e
|
158
|
+
end
|
158
159
|
end
|
159
|
-
# rescue Exception => e
|
160
|
-
# Locomotive::Mounter.logger.error e.backtrace
|
161
|
-
# raise Locomotive::Builder::MounterException.new "Unable to read the local LocomotiveCMS site: #{e.message}\nPlease check the logs file (#{path}/log/mounter.log)"
|
162
|
-
# end if get_reader
|
163
160
|
end
|
164
161
|
|
165
|
-
|
166
162
|
end
|
167
163
|
end
|
@@ -31,7 +31,7 @@ Gem::Specification.new do |gem|
|
|
31
31
|
gem.add_dependency 'rmagick', '2.12.2'
|
32
32
|
gem.add_dependency 'httmultiparty', '~> 0.3.8'
|
33
33
|
gem.add_dependency 'will_paginate', '~> 3.0.3'
|
34
|
-
gem.add_dependency 'locomotivecms_mounter', '1.0.0.
|
34
|
+
gem.add_dependency 'locomotivecms_mounter', '1.0.0.alpha2'
|
35
35
|
|
36
36
|
gem.add_dependency 'faker', '~> 0.9.5'
|
37
37
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: locomotivecms_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: 6
|
5
|
-
version: 1.0.0.
|
5
|
+
version: 1.0.0.alpha3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Didier Lafforgue
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-01-
|
13
|
+
date: 2013-01-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
type: :runtime
|
@@ -195,7 +195,7 @@ dependencies:
|
|
195
195
|
requirements:
|
196
196
|
- - '='
|
197
197
|
- !ruby/object:Gem::Version
|
198
|
-
version: 1.0.0.
|
198
|
+
version: 1.0.0.alpha2
|
199
199
|
name: locomotivecms_mounter
|
200
200
|
prerelease: false
|
201
201
|
requirement: !ruby/object:Gem::Requirement
|
@@ -203,7 +203,7 @@ dependencies:
|
|
203
203
|
requirements:
|
204
204
|
- - '='
|
205
205
|
- !ruby/object:Gem::Version
|
206
|
-
version: 1.0.0.
|
206
|
+
version: 1.0.0.alpha2
|
207
207
|
- !ruby/object:Gem::Dependency
|
208
208
|
type: :runtime
|
209
209
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -391,6 +391,7 @@ files:
|
|
391
391
|
- lib/locomotive/builder/liquid/tags/snippet.rb
|
392
392
|
- lib/locomotive/builder/liquid/tags/with_scope.rb
|
393
393
|
- lib/locomotive/builder/listen.rb
|
394
|
+
- lib/locomotive/builder/logger.rb
|
394
395
|
- lib/locomotive/builder/misc.rb
|
395
396
|
- lib/locomotive/builder/misc/core_ext.rb
|
396
397
|
- lib/locomotive/builder/misc/dragonfly.rb
|
@@ -402,6 +403,7 @@ files:
|
|
402
403
|
- lib/locomotive/builder/server/entry_submission.rb
|
403
404
|
- lib/locomotive/builder/server/favicon.rb
|
404
405
|
- lib/locomotive/builder/server/locale.rb
|
406
|
+
- lib/locomotive/builder/server/logging.rb
|
405
407
|
- lib/locomotive/builder/server/middleware.rb
|
406
408
|
- lib/locomotive/builder/server/not_found.rb
|
407
409
|
- lib/locomotive/builder/server/page.rb
|
@@ -442,7 +444,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
442
444
|
- !ruby/object:Gem::Version
|
443
445
|
segments:
|
444
446
|
- 0
|
445
|
-
hash: -
|
447
|
+
hash: -1360444636888489867
|
446
448
|
version: '0'
|
447
449
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
448
450
|
none: false
|