locomotivecms_mounter 1.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/locomotive/mounter/config.rb +21 -0
- data/lib/locomotive/mounter/engine_api.rb +40 -0
- data/lib/locomotive/mounter/exceptions.rb +38 -0
- data/lib/locomotive/mounter/extensions/compass.rb +36 -0
- data/lib/locomotive/mounter/extensions/httmultiparty.rb +22 -0
- data/lib/locomotive/mounter/extensions/tilt/css.rb +31 -0
- data/lib/locomotive/mounter/extensions/tilt/haml.rb +27 -0
- data/lib/locomotive/mounter/extensions/tilt/liquid.rb +23 -0
- data/lib/locomotive/mounter/extensions/tilt/template.rb +11 -0
- data/lib/locomotive/mounter/fields.rb +250 -0
- data/lib/locomotive/mounter/models/base.rb +41 -0
- data/lib/locomotive/mounter/models/content_asset.rb +84 -0
- data/lib/locomotive/mounter/models/content_entry.rb +290 -0
- data/lib/locomotive/mounter/models/content_field.rb +128 -0
- data/lib/locomotive/mounter/models/content_select_option.rb +29 -0
- data/lib/locomotive/mounter/models/content_type.rb +217 -0
- data/lib/locomotive/mounter/models/editable_element.rb +27 -0
- data/lib/locomotive/mounter/models/page.rb +377 -0
- data/lib/locomotive/mounter/models/site.rb +27 -0
- data/lib/locomotive/mounter/models/snippet.rb +55 -0
- data/lib/locomotive/mounter/models/theme_asset.rb +135 -0
- data/lib/locomotive/mounter/models/translation.rb +28 -0
- data/lib/locomotive/mounter/mounting_point.rb +49 -0
- data/lib/locomotive/mounter/reader/api/base.rb +49 -0
- data/lib/locomotive/mounter/reader/api/content_assets_reader.rb +40 -0
- data/lib/locomotive/mounter/reader/api/content_entries_reader.rb +141 -0
- data/lib/locomotive/mounter/reader/api/content_types_reader.rb +74 -0
- data/lib/locomotive/mounter/reader/api/pages_reader.rb +174 -0
- data/lib/locomotive/mounter/reader/api/site_reader.rb +37 -0
- data/lib/locomotive/mounter/reader/api/snippets_reader.rb +59 -0
- data/lib/locomotive/mounter/reader/api/theme_assets_reader.rb +42 -0
- data/lib/locomotive/mounter/reader/api/translations_reader.rb +28 -0
- data/lib/locomotive/mounter/reader/api.rb +49 -0
- data/lib/locomotive/mounter/reader/file_system/base.rb +65 -0
- data/lib/locomotive/mounter/reader/file_system/content_assets_reader.rb +88 -0
- data/lib/locomotive/mounter/reader/file_system/content_entries_reader.rb +101 -0
- data/lib/locomotive/mounter/reader/file_system/content_types_reader.rb +88 -0
- data/lib/locomotive/mounter/reader/file_system/pages_reader.rb +206 -0
- data/lib/locomotive/mounter/reader/file_system/site_reader.rb +24 -0
- data/lib/locomotive/mounter/reader/file_system/snippets_reader.rb +78 -0
- data/lib/locomotive/mounter/reader/file_system/theme_assets_reader.rb +78 -0
- data/lib/locomotive/mounter/reader/file_system/translations_reader.rb +36 -0
- data/lib/locomotive/mounter/reader/file_system.rb +42 -0
- data/lib/locomotive/mounter/reader/runner.rb +89 -0
- data/lib/locomotive/mounter/utils/hash.rb +31 -0
- data/lib/locomotive/mounter/utils/string.rb +17 -0
- data/lib/locomotive/mounter/utils/yaml.rb +125 -0
- data/lib/locomotive/mounter/version.rb +8 -0
- data/lib/locomotive/mounter/writer/api/base.rb +323 -0
- data/lib/locomotive/mounter/writer/api/content_assets_writer.rb +74 -0
- data/lib/locomotive/mounter/writer/api/content_entries_writer.rb +223 -0
- data/lib/locomotive/mounter/writer/api/content_types_writer.rb +151 -0
- data/lib/locomotive/mounter/writer/api/pages_writer.rb +225 -0
- data/lib/locomotive/mounter/writer/api/site_writer.rb +164 -0
- data/lib/locomotive/mounter/writer/api/snippets_writer.rb +111 -0
- data/lib/locomotive/mounter/writer/api/theme_assets_writer.rb +152 -0
- data/lib/locomotive/mounter/writer/api/translations_writer.rb +83 -0
- data/lib/locomotive/mounter/writer/api.rb +62 -0
- data/lib/locomotive/mounter/writer/file_system/base.rb +61 -0
- data/lib/locomotive/mounter/writer/file_system/content_assets_writer.rb +33 -0
- data/lib/locomotive/mounter/writer/file_system/content_entries_writer.rb +29 -0
- data/lib/locomotive/mounter/writer/file_system/content_types_writer.rb +27 -0
- data/lib/locomotive/mounter/writer/file_system/pages_writer.rb +73 -0
- data/lib/locomotive/mounter/writer/file_system/site_writer.rb +25 -0
- data/lib/locomotive/mounter/writer/file_system/snippets_writer.rb +54 -0
- data/lib/locomotive/mounter/writer/file_system/theme_assets_writer.rb +35 -0
- data/lib/locomotive/mounter/writer/file_system/translations_writer.rb +22 -0
- data/lib/locomotive/mounter/writer/file_system.rb +69 -0
- data/lib/locomotive/mounter/writer/runner.rb +68 -0
- data/lib/locomotive/mounter.rb +97 -0
- metadata +487 -0
@@ -0,0 +1,69 @@
|
|
1
|
+
module Locomotive
|
2
|
+
module Mounter
|
3
|
+
module Writer
|
4
|
+
|
5
|
+
module FileSystem
|
6
|
+
|
7
|
+
# Build a singleton instance of the Runner class.
|
8
|
+
#
|
9
|
+
# @return [ Object ] A singleton instance of the Runner class
|
10
|
+
#
|
11
|
+
def self.instance
|
12
|
+
@@instance ||= Runner.new(:file_system)
|
13
|
+
end
|
14
|
+
|
15
|
+
class Runner < Locomotive::Mounter::Writer::Runner
|
16
|
+
|
17
|
+
attr_accessor :target_path
|
18
|
+
|
19
|
+
# # Write the data of a mounting point instance to a target folder
|
20
|
+
# #
|
21
|
+
# # @param [ Hash ] parameters The parameters. It should contain the mounting_point and target_path keys.
|
22
|
+
# #
|
23
|
+
# # @return [ String ] The target path
|
24
|
+
# #
|
25
|
+
# def run!(parameters = {})
|
26
|
+
# self.mounting_point = parameters[:mounting_point]
|
27
|
+
|
28
|
+
|
29
|
+
# return nil if self.target_path.blank? || self.mounting_point.nil?
|
30
|
+
|
31
|
+
# self.write_all
|
32
|
+
|
33
|
+
# self.target_path
|
34
|
+
# end
|
35
|
+
|
36
|
+
# Check the existence of the target_path parameter
|
37
|
+
#
|
38
|
+
def prepare
|
39
|
+
self.target_path = parameters[:target_path]
|
40
|
+
|
41
|
+
if self.target_path.blank?
|
42
|
+
raise Locomotive::Mounter::WriterException.new('target_path is required')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# List of all the writers
|
47
|
+
#
|
48
|
+
# @return [ Array ] List of the writer classes
|
49
|
+
#
|
50
|
+
def writers
|
51
|
+
[SiteWriter, PagesWriter, SnippetsWriter, ContentTypesWriter, ContentEntriesWriter, ContentAssetsWriter, ThemeAssetsWriter, TranslationsWriter]
|
52
|
+
end
|
53
|
+
|
54
|
+
# # Execute all the writers
|
55
|
+
# def write_all
|
56
|
+
# self.writers.each do |klass|
|
57
|
+
# writer = klass.new(self.mounting_point, self.target_path)
|
58
|
+
# writer.prepare
|
59
|
+
# writer.write
|
60
|
+
# end
|
61
|
+
# end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Locomotive
|
2
|
+
module Mounter
|
3
|
+
module Writer
|
4
|
+
|
5
|
+
class Runner
|
6
|
+
|
7
|
+
attr_accessor :kind, :parameters, :mounting_point
|
8
|
+
|
9
|
+
def initialize(kind)
|
10
|
+
self.kind = kind
|
11
|
+
|
12
|
+
# avoid to load all the ruby files at the startup, only when we need it
|
13
|
+
base_dir = File.join(File.dirname(__FILE__), kind.to_s)
|
14
|
+
require File.join(base_dir, 'base.rb')
|
15
|
+
Dir[File.join(base_dir, '*.rb')].each { |lib| require lib }
|
16
|
+
end
|
17
|
+
|
18
|
+
# Write the data of a mounting point instance to a target folder
|
19
|
+
#
|
20
|
+
# @param [ Hash ] parameters The parameters. It should contain the mounting_point and target_path keys.
|
21
|
+
#
|
22
|
+
def run!(parameters = {})
|
23
|
+
self.parameters = parameters.symbolize_keys
|
24
|
+
|
25
|
+
self.mounting_point = self.parameters.delete(:mounting_point)
|
26
|
+
|
27
|
+
self.prepare
|
28
|
+
|
29
|
+
self.write_all
|
30
|
+
end
|
31
|
+
|
32
|
+
# Before starting to write anything
|
33
|
+
# Can be defined by writer runners
|
34
|
+
def prepare
|
35
|
+
end
|
36
|
+
|
37
|
+
# List of all the writers
|
38
|
+
#
|
39
|
+
# @return [ Array ] List of the writer classes
|
40
|
+
#
|
41
|
+
def writers
|
42
|
+
raise Locomotive::Mounter::ImplementationIsMissingException.new("[#{self.kind}] Writers are missing")
|
43
|
+
end
|
44
|
+
|
45
|
+
# Execute all the writers
|
46
|
+
def write_all
|
47
|
+
only = parameters[:only].try(:map) do |name|
|
48
|
+
"#{name}_writer".camelize
|
49
|
+
end.try(:insert, 0, 'SiteWriter')
|
50
|
+
|
51
|
+
begin
|
52
|
+
self.writers.each do |klass|
|
53
|
+
next if only && !only.include?(klass.name.demodulize)
|
54
|
+
writer = klass.new(self.mounting_point, self)
|
55
|
+
writer.prepare
|
56
|
+
writer.write
|
57
|
+
end
|
58
|
+
rescue Exception => e
|
59
|
+
Locomotive::Mounter.logger.error e.backtrace
|
60
|
+
puts "\n\nBlocking Error: #{e.message.colorize(:red)}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
$:.unshift File.expand_path(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
# Force encoding to UTF-8
|
4
|
+
Encoding.default_internal = Encoding.default_external = 'UTF-8'
|
5
|
+
|
6
|
+
require 'logger'
|
7
|
+
require 'colorize'
|
8
|
+
|
9
|
+
require 'active_support'
|
10
|
+
require 'active_support/core_ext'
|
11
|
+
require 'stringex'
|
12
|
+
require 'tempfile'
|
13
|
+
|
14
|
+
require 'tilt'
|
15
|
+
require 'haml'
|
16
|
+
require 'compass'
|
17
|
+
|
18
|
+
require 'httmultiparty'
|
19
|
+
require 'mime/types'
|
20
|
+
|
21
|
+
require 'locomotive/mounter/version'
|
22
|
+
require 'locomotive/mounter/exceptions'
|
23
|
+
require 'locomotive/mounter/config'
|
24
|
+
require 'locomotive/mounter/fields'
|
25
|
+
require 'locomotive/mounter/mounting_point'
|
26
|
+
require 'locomotive/mounter/engine_api'
|
27
|
+
|
28
|
+
# Extensions
|
29
|
+
require 'locomotive/mounter/extensions/httmultiparty'
|
30
|
+
require 'locomotive/mounter/extensions/compass'
|
31
|
+
require 'locomotive/mounter/extensions/tilt/template'
|
32
|
+
require 'locomotive/mounter/extensions/tilt/css'
|
33
|
+
require 'locomotive/mounter/extensions/tilt/haml'
|
34
|
+
require 'locomotive/mounter/extensions/tilt/liquid'
|
35
|
+
|
36
|
+
# Utils
|
37
|
+
require 'locomotive/mounter/utils/hash'
|
38
|
+
require 'locomotive/mounter/utils/yaml'
|
39
|
+
require 'locomotive/mounter/utils/string'
|
40
|
+
|
41
|
+
# Models
|
42
|
+
require 'locomotive/mounter/models/base'
|
43
|
+
Dir[File.join(File.dirname(__FILE__), 'mounter/models', '*.rb')].each { |lib| require lib }
|
44
|
+
|
45
|
+
# Readers: Filesystem / API
|
46
|
+
require 'locomotive/mounter/reader/runner'
|
47
|
+
require 'locomotive/mounter/reader/file_system'
|
48
|
+
require 'locomotive/mounter/reader/api'
|
49
|
+
|
50
|
+
# Writer: Filesystem
|
51
|
+
require 'locomotive/mounter/writer/runner'
|
52
|
+
require 'locomotive/mounter/writer/file_system'
|
53
|
+
require 'locomotive/mounter/writer/api'
|
54
|
+
|
55
|
+
module Locomotive
|
56
|
+
|
57
|
+
module Mounter
|
58
|
+
|
59
|
+
TEMPLATE_EXTENSIONS = %w(liquid haml)
|
60
|
+
|
61
|
+
@@logger = Logger.new(STDOUT).tap { |log| log.level = Logger::DEBUG }
|
62
|
+
|
63
|
+
@@mount_point = nil
|
64
|
+
|
65
|
+
# default locale
|
66
|
+
@@locale = I18n.locale
|
67
|
+
|
68
|
+
def self.mount(options)
|
69
|
+
@@mount_point = Locomotive::Mounter::Config[:reader].run!(options)
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.logger
|
73
|
+
@@logger
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.logger=(logger)
|
77
|
+
@@logger = logger
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.locale
|
81
|
+
@@locale
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.locale=(locale)
|
85
|
+
@@locale = locale.to_sym
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.with_locale(locale, &block)
|
89
|
+
tmp, @@locale = @@locale, locale.try(:to_sym) || @@locale
|
90
|
+
yield.tap do
|
91
|
+
@@locale = tmp
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|