locomotivecms_wagon 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data/.gitignore +27 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +8 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +68 -0
  6. data/Rakefile +57 -0
  7. data/TODO +57 -0
  8. data/bin/wagon +9 -0
  9. data/generators/blank/Gemfile.tt +20 -0
  10. data/generators/blank/app/content_types/.empty_directory +1 -0
  11. data/generators/blank/app/views/pages/404.liquid +11 -0
  12. data/generators/blank/app/views/pages/index.liquid +19 -0
  13. data/generators/blank/app/views/snippets/.empty_directory +1 -0
  14. data/generators/blank/config/deploy.yml +12 -0
  15. data/generators/blank/config/site.yml.tt +16 -0
  16. data/generators/blank/config/translations.yml +8 -0
  17. data/generators/blank/config.ru +3 -0
  18. data/generators/blank/data/.empty_directory +1 -0
  19. data/generators/blank/public/fonts/.empty_directory +1 -0
  20. data/generators/blank/public/images/.empty_directory +1 -0
  21. data/generators/blank/public/javascripts/.empty_directory +1 -0
  22. data/generators/blank/public/samples/.empty_directory +1 -0
  23. data/generators/blank/public/stylesheets/.empty_directory +1 -0
  24. data/generators/bootstrap/Gemfile.tt +20 -0
  25. data/generators/bootstrap/app/content_types/.empty_directory +1 -0
  26. data/generators/bootstrap/app/views/pages/404.liquid +13 -0
  27. data/generators/bootstrap/app/views/pages/404.liquid.haml +10 -0
  28. data/generators/bootstrap/app/views/pages/index.liquid +89 -0
  29. data/generators/bootstrap/app/views/pages/index.liquid.haml +72 -0
  30. data/generators/bootstrap/app/views/snippets/footer.liquid +3 -0
  31. data/generators/bootstrap/app/views/snippets/footer.liquid.haml +2 -0
  32. data/generators/bootstrap/config/deploy.yml +12 -0
  33. data/generators/bootstrap/config/site.yml.tt +16 -0
  34. data/generators/bootstrap/config/translations.yml +8 -0
  35. data/generators/bootstrap/config.ru +3 -0
  36. data/generators/bootstrap/data/.empty_directory +1 -0
  37. data/generators/bootstrap/public/fonts/FontAwesome.otf +0 -0
  38. data/generators/bootstrap/public/fonts/font-awesome-ie7.min.css +23 -0
  39. data/generators/bootstrap/public/fonts/font-awesome.css +469 -0
  40. data/generators/bootstrap/public/fonts/font-awesome.min.css +34 -0
  41. data/generators/bootstrap/public/fonts/fontawesome-webfont.eot +0 -0
  42. data/generators/bootstrap/public/fonts/fontawesome-webfont.ttf +0 -0
  43. data/generators/bootstrap/public/fonts/fontawesome-webfont.woff +0 -0
  44. data/generators/bootstrap/public/javascripts/bootstrap.js +2159 -0
  45. data/generators/bootstrap/public/javascripts/bootstrap.min.js +6 -0
  46. data/generators/bootstrap/public/samples/.empty_directory +1 -0
  47. data/generators/bootstrap/public/stylesheets/application.css.scss +39 -0
  48. data/generators/bootstrap/public/stylesheets/bootstrap-responsive.css +1092 -0
  49. data/generators/bootstrap/public/stylesheets/bootstrap-responsive.min.css +9 -0
  50. data/generators/bootstrap/public/stylesheets/bootstrap.css +5652 -0
  51. data/generators/bootstrap/public/stylesheets/bootstrap.min.css +726 -0
  52. data/generators/content_type/app/content_types/%name%.yml.tt +58 -0
  53. data/generators/content_type/data/%name%.yml.tt +24 -0
  54. data/generators/foundation/Gemfile.tt +20 -0
  55. data/generators/foundation/app/content_types/.empty_directory +1 -0
  56. data/generators/foundation/app/views/pages/404.liquid +13 -0
  57. data/generators/foundation/app/views/pages/404.liquid.haml +10 -0
  58. data/generators/foundation/app/views/pages/index.liquid +152 -0
  59. data/generators/foundation/app/views/pages/index.liquid.haml +130 -0
  60. data/generators/foundation/app/views/snippets/footer.liquid +16 -0
  61. data/generators/foundation/app/views/snippets/footer.liquid.haml +23 -0
  62. data/generators/foundation/config/deploy.yml +12 -0
  63. data/generators/foundation/config/site.yml.tt +16 -0
  64. data/generators/foundation/config/translations.yml +8 -0
  65. data/generators/foundation/config.ru +3 -0
  66. data/generators/foundation/data/.empty_directory +1 -0
  67. data/generators/foundation/public/fonts/.empty_directory +1 -0
  68. data/generators/foundation/public/javascripts/foundation/foundation.alerts.js +50 -0
  69. data/generators/foundation/public/javascripts/foundation/foundation.clearing.js +480 -0
  70. data/generators/foundation/public/javascripts/foundation/foundation.cookie.js +74 -0
  71. data/generators/foundation/public/javascripts/foundation/foundation.dropdown.js +130 -0
  72. data/generators/foundation/public/javascripts/foundation/foundation.forms.js +395 -0
  73. data/generators/foundation/public/javascripts/foundation/foundation.joyride.js +612 -0
  74. data/generators/foundation/public/javascripts/foundation/foundation.js +372 -0
  75. data/generators/foundation/public/javascripts/foundation/foundation.magellan.js +130 -0
  76. data/generators/foundation/public/javascripts/foundation/foundation.orbit.js +365 -0
  77. data/generators/foundation/public/javascripts/foundation/foundation.placeholder.js +159 -0
  78. data/generators/foundation/public/javascripts/foundation/foundation.reveal.js +270 -0
  79. data/generators/foundation/public/javascripts/foundation/foundation.section.js +272 -0
  80. data/generators/foundation/public/javascripts/foundation/foundation.tooltips.js +195 -0
  81. data/generators/foundation/public/javascripts/foundation/foundation.topbar.js +225 -0
  82. data/generators/foundation/public/javascripts/foundation.min.js +14 -0
  83. data/generators/foundation/public/javascripts/vendor/custom.modernizr.js +4 -0
  84. data/generators/foundation/public/javascripts/vendor/jquery.js +9597 -0
  85. data/generators/foundation/public/javascripts/vendor/zepto.js +1884 -0
  86. data/generators/foundation/public/samples/.empty_directory +1 -0
  87. data/generators/foundation/public/stylesheets/foundation.css +3818 -0
  88. data/generators/foundation/public/stylesheets/foundation.min.css +1 -0
  89. data/generators/foundation/public/stylesheets/normalize.css +396 -0
  90. data/generators/page/template.liquid.haml.tt +35 -0
  91. data/generators/page/template.liquid.tt +1 -0
  92. data/generators/snippet/template.liquid.haml.tt +4 -0
  93. data/generators/snippet/template.liquid.tt +4 -0
  94. data/lib/locomotive/wagon/cli.rb +238 -0
  95. data/lib/locomotive/wagon/exceptions.rb +35 -0
  96. data/lib/locomotive/wagon/generators/content_type.rb +47 -0
  97. data/lib/locomotive/wagon/generators/page.rb +63 -0
  98. data/lib/locomotive/wagon/generators/site/base.rb +30 -0
  99. data/lib/locomotive/wagon/generators/site/blank.rb +23 -0
  100. data/lib/locomotive/wagon/generators/site/bootstrap.rb +35 -0
  101. data/lib/locomotive/wagon/generators/site/foundation.rb +35 -0
  102. data/lib/locomotive/wagon/generators/site/unzip.rb +81 -0
  103. data/lib/locomotive/wagon/generators/site.rb +99 -0
  104. data/lib/locomotive/wagon/generators/snippet.rb +60 -0
  105. data/lib/locomotive/wagon/liquid/drops/base.rb +44 -0
  106. data/lib/locomotive/wagon/liquid/drops/content_entry.rb +48 -0
  107. data/lib/locomotive/wagon/liquid/drops/content_types.rb +121 -0
  108. data/lib/locomotive/wagon/liquid/drops/page.rb +36 -0
  109. data/lib/locomotive/wagon/liquid/drops/site.rb +21 -0
  110. data/lib/locomotive/wagon/liquid/errors.rb +7 -0
  111. data/lib/locomotive/wagon/liquid/filters/date.rb +98 -0
  112. data/lib/locomotive/wagon/liquid/filters/html.rb +154 -0
  113. data/lib/locomotive/wagon/liquid/filters/misc.rb +28 -0
  114. data/lib/locomotive/wagon/liquid/filters/resize.rb +18 -0
  115. data/lib/locomotive/wagon/liquid/filters/text.rb +50 -0
  116. data/lib/locomotive/wagon/liquid/filters/translate.rb +24 -0
  117. data/lib/locomotive/wagon/liquid/patches.rb +47 -0
  118. data/lib/locomotive/wagon/liquid/tags/consume.rb +58 -0
  119. data/lib/locomotive/wagon/liquid/tags/csrf.rb +34 -0
  120. data/lib/locomotive/wagon/liquid/tags/editable/base.rb +46 -0
  121. data/lib/locomotive/wagon/liquid/tags/editable/control.rb +19 -0
  122. data/lib/locomotive/wagon/liquid/tags/editable/file.rb +15 -0
  123. data/lib/locomotive/wagon/liquid/tags/editable/long_text.rb +15 -0
  124. data/lib/locomotive/wagon/liquid/tags/editable/short_text.rb +15 -0
  125. data/lib/locomotive/wagon/liquid/tags/editable.rb +5 -0
  126. data/lib/locomotive/wagon/liquid/tags/extends.rb +25 -0
  127. data/lib/locomotive/wagon/liquid/tags/google_analytics.rb +28 -0
  128. data/lib/locomotive/wagon/liquid/tags/inline_editor.rb +16 -0
  129. data/lib/locomotive/wagon/liquid/tags/locale_switcher.rb +106 -0
  130. data/lib/locomotive/wagon/liquid/tags/nav.rb +167 -0
  131. data/lib/locomotive/wagon/liquid/tags/paginate.rb +105 -0
  132. data/lib/locomotive/wagon/liquid/tags/seo.rb +74 -0
  133. data/lib/locomotive/wagon/liquid/tags/snippet.rb +44 -0
  134. data/lib/locomotive/wagon/liquid/tags/with_scope.rb +43 -0
  135. data/lib/locomotive/wagon/liquid.rb +19 -0
  136. data/lib/locomotive/wagon/listen.rb +57 -0
  137. data/lib/locomotive/wagon/logger.rb +54 -0
  138. data/lib/locomotive/wagon/misc/core_ext.rb +29 -0
  139. data/lib/locomotive/wagon/misc/dragonfly.rb +79 -0
  140. data/lib/locomotive/wagon/misc/httparty.rb +46 -0
  141. data/lib/locomotive/wagon/misc/i18n.rb +2 -0
  142. data/lib/locomotive/wagon/misc/will_paginate.rb +16 -0
  143. data/lib/locomotive/wagon/misc.rb +5 -0
  144. data/lib/locomotive/wagon/server/dynamic_assets.rb +31 -0
  145. data/lib/locomotive/wagon/server/entry_submission.rb +116 -0
  146. data/lib/locomotive/wagon/server/favicon.rb +17 -0
  147. data/lib/locomotive/wagon/server/locale.rb +42 -0
  148. data/lib/locomotive/wagon/server/logging.rb +32 -0
  149. data/lib/locomotive/wagon/server/middleware.rb +59 -0
  150. data/lib/locomotive/wagon/server/not_found.rb +19 -0
  151. data/lib/locomotive/wagon/server/page.rb +61 -0
  152. data/lib/locomotive/wagon/server/path.rb +34 -0
  153. data/lib/locomotive/wagon/server/renderer.rb +105 -0
  154. data/lib/locomotive/wagon/server/templatized_page.rb +32 -0
  155. data/lib/locomotive/wagon/server.rb +81 -0
  156. data/lib/locomotive/wagon/standalone_server.rb +28 -0
  157. data/lib/locomotive/wagon/version.rb +5 -0
  158. data/lib/locomotive/wagon.rb +163 -0
  159. data/locales/de.yml +156 -0
  160. data/locales/en.yml +177 -0
  161. data/locales/es.yml +132 -0
  162. data/locales/et.yml +153 -0
  163. data/locales/fr.yml +146 -0
  164. data/locales/it.yml +154 -0
  165. data/locales/nb.yml +190 -0
  166. data/locales/nl.yml +159 -0
  167. data/locales/pl.yml +202 -0
  168. data/locales/pt-BR.yml +138 -0
  169. data/locales/ru.yml +223 -0
  170. data/locomotivecms_wagon.gemspec +44 -0
  171. data/spec/integration/cassettes/pull.yml +590 -0
  172. data/spec/integration/cassettes/push.yml +810 -0
  173. data/spec/integration/integration_helper.rb +14 -0
  174. data/spec/integration/server_spec.rb +38 -0
  175. data/spec/integration/sites_spec.rb +29 -0
  176. data/spec/spec_helper.rb +12 -0
  177. data/spec/support/helpers.rb +13 -0
  178. metadata +544 -0
@@ -0,0 +1,238 @@
1
+ require 'thor'
2
+ require 'thor/runner'
3
+
4
+ module Locomotive
5
+ module Wagon
6
+ module CLI
7
+
8
+ module CheckPath
9
+
10
+ protected
11
+
12
+ # Check if the path given in option ('.' by default) points to a LocomotiveCMS
13
+ # site. It is also possible to pass a path other than the one from the options.
14
+ #
15
+ # @param [ String ] path The optional path of the site instead of options['path']
16
+ #
17
+ # @return [ String ] The fullpath to the LocomotiveCMS site or nil if it is not a valid site.
18
+ #
19
+ def check_path!(path = nil)
20
+ path ||= options['path']
21
+
22
+ path = path == '.' ? Dir.pwd : File.expand_path(path)
23
+
24
+ (File.exists?(File.join(path, 'config', 'site.yml')) ? path : nil).tap do |_path|
25
+ if _path.nil?
26
+ say 'The path does not point to a LocomotiveCMS site', :red
27
+ end
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ class Generate < Thor
34
+
35
+ include Locomotive::Wagon::CLI::CheckPath
36
+
37
+ class_option :path, aliases: '-p', type: :string, default: '.', optional: true, desc: 'if your LocomotiveCMS site is not in the current path'
38
+
39
+ desc 'content_type NAME FIELDS', 'Create a content type with NAME as the slug and FIELDS as the list of fields.'
40
+ long_desc <<-LONGDESC
41
+ Create a content type with NAME as the slug and FIELDS as the list of fields.
42
+ The fields follows that schema:
43
+
44
+ field_1[:type][:required] field_2[:type][:required]
45
+
46
+ Examples:
47
+
48
+ * wagon generate content_type songs name:string duration:string
49
+
50
+ * wagon generate content_type posts title body:text:true published_at:date
51
+ LONGDESC
52
+ def content_type(name, *fields)
53
+ say('The fields are missing', :red) and return false if fields.empty?
54
+
55
+ if check_path!
56
+ Locomotive::Wagon.generate :content_type, name, self.options['path'], fields
57
+ end
58
+ end
59
+
60
+ desc 'page FULLPATH', 'Create a page. No need to pass an extension to the FULLPATH arg'
61
+ long_desc <<-LONGDESC
62
+ Create a page. The generator will ask for the extension (liquid or haml) and also
63
+ if the page is localized or not.
64
+
65
+ Examples:
66
+
67
+ * wagon generate page contact
68
+
69
+ * wagon generate page about_us/me
70
+ LONGDESC
71
+ def page(fullpath)
72
+ if path = check_path!
73
+ locales = self.site_config(path)['locales']
74
+ Locomotive::Wagon.generate :page, fullpath, self.options['path'], locales
75
+ end
76
+ end
77
+
78
+ desc 'snippet SLUG', 'Create a snippet'
79
+ long_desc <<-LONGDESC
80
+ Create a snippet. The generator will ask for the extension (liquid or haml) and also
81
+ if the snippet is localized or not.
82
+
83
+ Example:
84
+
85
+ * wagon generate snippet footer
86
+ LONGDESC
87
+ def snippet(slug)
88
+ if path = check_path!
89
+ locales = self.site_config(path)['locales']
90
+ Locomotive::Wagon.generate :snippet, slug, self.options['path'], locales
91
+ end
92
+ end
93
+
94
+ protected
95
+
96
+ # Read the YAML config file of a LocomotiveCMS site.
97
+ # The path should be returned by the check_path! method first.
98
+ #
99
+ # @param [ String ] path The full path to a LocomotiveCMS site.
100
+ #
101
+ # @return [ Hash ] The site
102
+ #
103
+ def site_config(path = nil)
104
+ YAML.load_file(File.join(path, 'config', 'site.yml'))
105
+ end
106
+
107
+ end
108
+
109
+ class Main < Thor
110
+
111
+ include Locomotive::Wagon::CLI::CheckPath
112
+
113
+ desc 'version', 'Version of the LocomotiveCMS wagon'
114
+ def version
115
+ require 'locomotive/wagon/version'
116
+ say Locomotive::Wagon::VERSION
117
+ end
118
+
119
+ desc 'init NAME [PATH]', 'Create a brand new LocomotiveCMS site'
120
+ method_option :template, aliases: '-t', type: 'string', default: 'blank', desc: 'instead of building from a blank site, you can have a pre-fetched site with form a template (see the templates command)'
121
+ def init(name, path = '.')
122
+ require 'locomotive/wagon/generators/site'
123
+ generator = Locomotive::Wagon::Generators::Site.get(options[:template])
124
+ if generator.nil?
125
+ say "Unknown site template '#{options[:template]}'", :red
126
+ else
127
+ begin
128
+ Locomotive::Wagon.init(name, path, generator)
129
+ rescue GeneratorException => e
130
+ say e.message, :red
131
+ end
132
+ end
133
+ end
134
+
135
+ desc 'generate TYPE ...ARGS', 'Generate resources (content_types, page, snippets) for a LocomotiveCMS site'
136
+ subcommand 'generate', Generate
137
+
138
+ desc 'list_templates', 'List all the templates to create either a site or a content type'
139
+ def list_templates
140
+ require 'locomotive/wagon/generators/site'
141
+ if Locomotive::Wagon::Generators::Site.empty?
142
+ say 'No templates', :red
143
+ else
144
+ Locomotive::Wagon::Generators::Site.list.each do |info|
145
+ say info.name, :bold, false
146
+ say " - #{info.description}" unless info.description.blank?
147
+ end
148
+ end
149
+ end
150
+
151
+ desc 'serve [PATH]', 'Serve a LocomotiveCMS site from the file system'
152
+ method_option :host, aliases: '-h', type: 'string', default: '0.0.0.0', desc: 'The host (address) of the Thin server'
153
+ method_option :port, aliases: '-p', type: 'string', default: '3333', desc: 'The port of the Thin server'
154
+ def serve(path = '.')
155
+ if check_path!(path)
156
+ begin
157
+ Locomotive::Wagon.serve(path, options)
158
+ rescue Exception => e
159
+ say e.message, :red
160
+ end
161
+ end
162
+ end
163
+
164
+ desc 'push ENV [PATH]', 'Push a site to a remote LocomotiveCMS engine'
165
+ method_option :resources, aliases: '-r', type: 'array', default: nil, desc: 'Only push the resource(s) passed in argument'
166
+ method_option :force, aliases: '-f', type: 'boolean', default: false, desc: 'Force the push of a resource'
167
+ method_option :data, aliases: '-d', type: 'boolean', default: false, desc: 'Push the content entries and the editable elements (by default, they are not)'
168
+ def push(env, path = '.')
169
+ if check_path!(path)
170
+ if connection_info = self.retrieve_connection_info(env, path)
171
+ begin
172
+ Locomotive::Wagon.push(path, connection_info, options)
173
+ rescue Exception => e
174
+ say e.message, :red
175
+ end
176
+ end
177
+ end
178
+ end
179
+
180
+ desc 'pull ENV [PATH]', 'Pull a site from a remote LocomotiveCMS engine'
181
+ method_option :resources, aliases: '-r', type: 'array', default: nil, desc: 'Only pull the resource(s) passed in argument'
182
+ # method_option :force, aliases: '-f', type: 'boolean', default: false, desc: 'Force the push of a resource'
183
+ # method_option :data, aliases: '-d', type: 'boolean', default: false, desc: 'Push the content entries and the editable elements (by default, they are not)'
184
+ def pull(env, path = '.')
185
+ if check_path!(path)
186
+ if connection_info = self.retrieve_connection_info(env, path)
187
+ begin
188
+ Locomotive::Wagon.pull(path, connection_info, options)
189
+ rescue Exception => e
190
+ say e.message, :red
191
+ end
192
+ end
193
+ end
194
+ end
195
+
196
+ desc 'destroy ENV [PATH]', 'Destroy a remote LocomotiveCMS engine'
197
+ def destroy(env, path = '.')
198
+ if check_path!(path)
199
+ if connection_info = self.retrieve_connection_info(env, path)
200
+ if ask('Are you sure ?', limited_to: %w(yes no)) == 'yes'
201
+ Locomotive::Wagon.destroy(path, connection_info)
202
+ else
203
+ say 'The destroy operation has been cancelled', :red
204
+ end
205
+ end
206
+ end
207
+ end
208
+
209
+ protected
210
+
211
+ # From a site specified by a path, retrieve the information of the connection
212
+ # for a environment located in the config/deploy.yml file of the site.
213
+ #
214
+ # @param [ String ] env The environment (development, staging, production, ...etc)
215
+ # @param [ String ] path The path of the local site
216
+ #
217
+ # @return [ Hash ] The information of the connection or nil if errors
218
+ #
219
+ def retrieve_connection_info(env, path)
220
+ connection_info = nil
221
+ begin
222
+ path_to_deploy_file = File.join(path, 'config', 'deploy.yml')
223
+ connection_info = YAML::load(File.open(path_to_deploy_file).read)[env.to_s]
224
+
225
+ if connection_info.nil?
226
+ raise "No #{env.to_s} environment found in the config/deploy.yml file"
227
+ end
228
+ rescue Exception => e
229
+ say "Unable to read the information about the remote LocomotiveCMS site (#{e.message})", :red
230
+ end
231
+ connection_info
232
+ end
233
+
234
+ end
235
+
236
+ end
237
+ end
238
+ end
@@ -0,0 +1,35 @@
1
+ module Locomotive
2
+ module Wagon
3
+
4
+ class DefaultException < ::Exception
5
+
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::Wagon::Logger.fatal full_error_message
19
+ end
20
+
21
+ end
22
+
23
+ class MounterException < DefaultException
24
+ end
25
+
26
+ class GeneratorException < DefaultException
27
+
28
+ def log_backtrace(parent_exception)
29
+ # Logger not initialized at this step
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,47 @@
1
+ require 'thor/group'
2
+ require 'ostruct'
3
+ require 'active_support'
4
+ require 'active_support/core_ext'
5
+ require 'faker'
6
+
7
+ module Locomotive
8
+ module Wagon
9
+ module Generators
10
+ class ContentType < Thor::Group
11
+
12
+ include Thor::Actions
13
+
14
+ argument :name
15
+ argument :target_path
16
+ argument :fields
17
+
18
+ def copy_sources
19
+ directory('.', target_path, { recursive: true }, {
20
+ name: self.name,
21
+ fields: extract_fields(fields)
22
+ })
23
+ end
24
+
25
+ def self.source_root
26
+ File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'generators', 'content_type')
27
+ end
28
+
29
+ protected
30
+
31
+ def extract_fields(fields)
32
+ fields.map do |raw_attributes|
33
+ name, type, required = raw_attributes.split(':')
34
+
35
+ OpenStruct.new({
36
+ name: name,
37
+ type: type || 'string',
38
+ required: %w(true required).include?(required)
39
+ })
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,63 @@
1
+ require 'thor/group'
2
+ require 'active_support'
3
+ require 'active_support/core_ext'
4
+
5
+ module Locomotive
6
+ module Wagon
7
+ module Generators
8
+ class Page < Thor::Group
9
+
10
+ include Thor::Actions
11
+
12
+ argument :slug
13
+ argument :target_path # path to the site
14
+ argument :locales
15
+
16
+ attr_accessor :haml
17
+
18
+ def ask_for_haml
19
+ self.haml = yes?('Do you prefer a HAML template ?')
20
+ end
21
+
22
+ def apply_locales?
23
+ self.locales.shift # remove the default locale
24
+
25
+ unless self.locales.empty?
26
+ unless yes?('Do you want to generate templates for each locale ?')
27
+ self.locales = []
28
+ end
29
+ end
30
+ end
31
+
32
+ def create_page
33
+ extension = self.haml ? 'liquid.haml' : 'liquid'
34
+
35
+ segments = self.slug.split('/')
36
+ while segment = segments.pop do
37
+ options = { slug: segment, translated: false }
38
+ file_path = File.join(pages_path, segments, segment)
39
+
40
+ template "template.#{extension}.tt", "#{file_path}.#{extension}", options
41
+
42
+ self.locales.each do |locale|
43
+ options[:translated] = true
44
+ template "template.#{extension}.tt", "#{file_path}.#{locale}.#{extension}", options
45
+ end
46
+ end
47
+ end
48
+
49
+ def self.source_root
50
+ File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'generators', 'page')
51
+ end
52
+
53
+ protected
54
+
55
+ def pages_path
56
+ File.join(target_path, 'app', 'views', 'pages')
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,30 @@
1
+ require 'thor/group'
2
+ require 'active_support'
3
+ require 'active_support/core_ext'
4
+
5
+ module Locomotive
6
+ module Wagon
7
+ module Generators
8
+ module Site
9
+
10
+ class Base < Thor::Group
11
+
12
+ include Thor::Actions
13
+
14
+ argument :name
15
+ argument :target_path
16
+
17
+ def self.source_root
18
+ File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'generators', self.name.demodulize.underscore)
19
+ end
20
+
21
+ def destination
22
+ File.join(target_path, name)
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ module Locomotive
2
+ module Wagon
3
+ module Generators
4
+ module Site
5
+
6
+ class Blank < Base
7
+
8
+ def copy_sources
9
+ directory('.', self.destination, { recursive: true }, {
10
+ name: self.name,
11
+ version: Locomotive::Wagon::VERSION
12
+ })
13
+ end
14
+
15
+ end
16
+
17
+ Locomotive::Wagon::Generators::Site.register(:blank, Blank, %{
18
+ A blank LocomotiveCMS site with the minimal files.
19
+ })
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ module Locomotive
2
+ module Wagon
3
+ module Generators
4
+ module Site
5
+
6
+ class Bootstrap < Base
7
+
8
+ def copy_sources
9
+ directory('.', self.destination, { recursive: true }, {
10
+ name: self.name,
11
+ version: Locomotive::Wagon::VERSION
12
+ })
13
+ end
14
+
15
+ def choose_haml_over_html
16
+ if yes?('Do you prefer HAML templates ?')
17
+ remove_file File.join(self.destination, 'app/views/pages/index.liquid')
18
+ remove_file File.join(self.destination, 'app/views/pages/404.liquid')
19
+ remove_file File.join(self.destination, 'app/views/snippets/footer.liquid')
20
+ else
21
+ remove_file File.join(self.destination, 'app/views/pages/index.liquid.haml')
22
+ remove_file File.join(self.destination, 'app/views/pages/404.liquid.haml')
23
+ remove_file File.join(self.destination, 'app/views/snippets/footer.liquid.haml')
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ Locomotive::Wagon::Generators::Site.register(:bootstrap, Bootstrap, %{
30
+ A LocomotiveCMS site powered by Twitter bootstrap (v2.2.2).
31
+ })
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ module Locomotive
2
+ module Wagon
3
+ module Generators
4
+ module Site
5
+
6
+ class Foundation < Base
7
+
8
+ def copy_sources
9
+ directory('.', self.destination, { recursive: true }, {
10
+ name: self.name,
11
+ version: Locomotive::Wagon::VERSION
12
+ })
13
+ end
14
+
15
+ def choose_haml_over_html
16
+ if yes?('Do you prefer HAML templates ?')
17
+ remove_file File.join(self.destination, 'app/views/pages/index.liquid')
18
+ remove_file File.join(self.destination, 'app/views/pages/404.liquid')
19
+ remove_file File.join(self.destination, 'app/views/snippets/footer.liquid')
20
+ else
21
+ remove_file File.join(self.destination, 'app/views/pages/index.liquid.haml')
22
+ remove_file File.join(self.destination, 'app/views/pages/404.liquid.haml')
23
+ remove_file File.join(self.destination, 'app/views/snippets/footer.liquid.haml')
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ Locomotive::Wagon::Generators::Site.register(:foundation, Foundation, %{
30
+ A LocomotiveCMS site powered by Foundation (v4.0.9).
31
+ })
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,81 @@
1
+ require 'open-uri'
2
+ require 'zip/zipfilesystem'
3
+
4
+ module Locomotive
5
+ module Wagon
6
+ module Generators
7
+ module Site
8
+
9
+ class Unzip < Base
10
+
11
+ def prepare
12
+ remove_file join('tmp')
13
+ empty_directory join('tmp')
14
+ end
15
+
16
+ def ask_for_location
17
+ @location = ask('What is the location (on the filesystem or url) of the zip file ?')
18
+ raise GeneratorException.new('Please enter a location') if @location.blank?
19
+ end
20
+
21
+ def download_or_copy
22
+ @template_path = join('tmp', File.basename(@location))
23
+
24
+ if @location =~ /^https?:\/\//
25
+ say "downloading...#{@location}"
26
+ create_file @template_path, open(@location).read
27
+ else
28
+ say "copying...#{@location}"
29
+ create_file @template_path, open(@location, 'rb') { |io| io.read }
30
+ end
31
+ end
32
+
33
+ def unzip
34
+ say "unzipping...#{@template_path}"
35
+
36
+ begin
37
+ Zip::ZipFile.open(@template_path) do |zipfile|
38
+ zipfile.each do |file|
39
+ next if file.name =~ /^__MACOSX/
40
+ zipfile.extract(file, join('tmp', file.name))
41
+
42
+ @path = $1 if file.name =~ /(.*)\/config\/site.yml$/
43
+ end
44
+ end
45
+ rescue Exception => e
46
+ raise GeneratorException.new("Unable to unzip the archive")
47
+ end
48
+
49
+ raise GeneratorException.new('Not a valid LocomotiveCMS site') if @path.blank?
50
+ end
51
+
52
+ def copy_sources
53
+ self.class.source_root = File.expand_path(join('tmp', @path, '/'))
54
+ say "copying files from #{self.class.source_root} / #{self.destination}"
55
+ directory('.', self.destination, { recursive: true })
56
+ end
57
+
58
+ def self.source_root
59
+ # only way to change the source root from the instance
60
+ @@source_root
61
+ end
62
+
63
+ def self.source_root=(value)
64
+ @@source_root = value
65
+ end
66
+
67
+ protected
68
+
69
+ def join(*args)
70
+ File.join(self.destination, *args)
71
+ end
72
+
73
+ end
74
+
75
+ Locomotive::Wagon::Generators::Site.register(:unzip, Unzip, %{
76
+ Unzip a local or remote (http, https, ftp) zipped LocomotiveCMS site.
77
+ })
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,99 @@
1
+ require 'ostruct'
2
+ require 'singleton'
3
+
4
+ module Locomotive
5
+ module Wagon
6
+ module Generators
7
+
8
+ module Site
9
+
10
+ # Register a generator by adding it to the list of existing generators.
11
+ #
12
+ # @param [ String ] name The name of the generator
13
+ # @param [ Class ] klass The class of the generator
14
+ # @param [ String ] description The description of the generator (can be nil)
15
+ #
16
+ # @return [ Boolean ] True if the registration has been successful, false otherwise.
17
+ #
18
+ def self.register(name, klass, description = nil)
19
+ Locomotive::Wagon::Generators::Site::List.instance.register(name, klass, description)
20
+ end
21
+
22
+ # Return the information about a generator from its name.
23
+ #
24
+ # @param [ String ] name The name of the generator
25
+ #
26
+ # @return [ Object ] The information of the found generator or nil
27
+ #
28
+ def self.get(name)
29
+ Locomotive::Wagon::Generators::Site::List.instance.get(name)
30
+ end
31
+
32
+ # List all the generators
33
+ #
34
+ # @return [ Array ] The filtered (or not) list of generators
35
+ #
36
+ def self.list
37
+ Locomotive::Wagon::Generators::Site::List.instance._list
38
+ end
39
+
40
+ # Tell if the list of generators is empty or not .
41
+ #
42
+ # @return [ Boolean ] True if empty
43
+ #
44
+ def self.empty?
45
+ Locomotive::Wagon::Generators::Site::List.instance._list.empty?
46
+ end
47
+
48
+ class List
49
+
50
+ include ::Singleton
51
+
52
+ attr_accessor :_list
53
+
54
+ def initialize
55
+ self._list = []
56
+ end
57
+
58
+ # Return the information about a generator from its name.
59
+ #
60
+ # @param [ String ] name The name of the generator
61
+ #
62
+ # @return [ Object ] The information of the found generator or nil
63
+ #
64
+ def get(name)
65
+ self._list.detect { |entry| entry.name == name.to_sym }
66
+ end
67
+
68
+ # Register a generator by adding it to the list of existing generators.
69
+ #
70
+ # @param [ String ] name The name of the generator
71
+ # @param [ Class ] klass The class of the generator
72
+ # @param [ String ] description The description of the generator (can be nil)
73
+ #
74
+ # @return [ Boolean ] True if the registration has been successful, false otherwise.
75
+ #
76
+ def register(name, klass, description = nil)
77
+ return false unless self.get(name).nil?
78
+
79
+ self._list << OpenStruct.new({
80
+ name: name.to_sym,
81
+ klass: klass,
82
+ description: description ? description.strip.gsub("\n", '') : nil
83
+ })
84
+
85
+ self._list.last
86
+ end
87
+ end
88
+
89
+ end
90
+
91
+ end
92
+ end
93
+ end
94
+
95
+ require 'locomotive/wagon/generators/site/base'
96
+ require 'locomotive/wagon/generators/site/blank'
97
+ require 'locomotive/wagon/generators/site/bootstrap'
98
+ require 'locomotive/wagon/generators/site/foundation'
99
+ require 'locomotive/wagon/generators/site/unzip'