marv 0.3.2 → 0.4.0

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.
Files changed (81) hide show
  1. data/.document +5 -0
  2. data/CHANGELOG.md +13 -0
  3. data/Gemfile +8 -10
  4. data/Gemfile.lock +16 -43
  5. data/LICENSE +0 -24
  6. data/README.md +9 -10
  7. data/Rakefile +4 -20
  8. data/VERSION +1 -1
  9. data/bin/marv +1 -1
  10. data/layouts/config/global.rb +31 -0
  11. data/layouts/config/project.rb +27 -0
  12. data/layouts/config/{router.php.erb → router.php} +5 -1
  13. data/layouts/config/server.rb +12 -0
  14. data/layouts/config/{wp-config.php.erb → wp-config.php} +0 -0
  15. data/layouts/plugin/{images → assets/images}/screenshot.png +0 -0
  16. data/layouts/plugin/{javascripts → assets/javascripts}/admin.coffee +0 -0
  17. data/layouts/plugin/{javascripts → assets/javascripts}/admin.js +0 -0
  18. data/layouts/plugin/{javascripts → assets/javascripts}/plugin.coffee +0 -0
  19. data/layouts/plugin/assets/javascripts/plugin.js +1 -0
  20. data/layouts/plugin/{stylesheets → assets/stylesheets}/plugin.scss +0 -0
  21. data/layouts/plugin/functions/{plugin.php.erb → plugin.php} +8 -7
  22. data/layouts/theme/{images → assets/images}/screenshot.png +0 -0
  23. data/layouts/theme/{javascripts → assets/javascripts}/admin.coffee +0 -0
  24. data/layouts/theme/{javascripts → assets/javascripts}/admin.js +0 -0
  25. data/layouts/theme/{javascripts → assets/javascripts}/theme.coffee +0 -0
  26. data/layouts/theme/{javascripts → assets/javascripts}/theme.js +0 -0
  27. data/layouts/theme/assets/stylesheets/_header.scss +18 -0
  28. data/layouts/theme/{stylesheets/style.scss.erb → assets/stylesheets/style.scss} +0 -0
  29. data/layouts/theme/functions/{functions.php.erb → functions.php} +0 -0
  30. data/layouts/theme/includes/{filters-admin.php.erb → filters-admin.php} +0 -0
  31. data/layouts/theme/includes/{filters.php.erb → filters.php} +0 -0
  32. data/layouts/theme/includes/{helpers.php.erb → helpers.php} +0 -0
  33. data/layouts/theme/templates/{404.php.erb → pages/404.php} +0 -0
  34. data/layouts/theme/templates/{archive.php.erb → pages/archive.php} +0 -0
  35. data/layouts/theme/templates/{author.php.erb → pages/author.php} +0 -0
  36. data/layouts/theme/templates/{search.php.erb → pages/search.php} +0 -0
  37. data/layouts/theme/templates/partials/{comments.php.erb → comments.php} +0 -0
  38. data/layouts/theme/templates/partials/{content-none.php.erb → content-none.php} +0 -0
  39. data/layouts/theme/templates/partials/{content.php.erb → content.php} +0 -0
  40. data/layouts/theme/templates/partials/{searchform.php.erb → searchform.php} +0 -0
  41. data/lib/marv.rb +8 -8
  42. data/lib/marv/cli.rb +15 -192
  43. data/lib/marv/cli/project.rb +57 -0
  44. data/lib/marv/cli/server.rb +65 -0
  45. data/lib/marv/global.rb +285 -0
  46. data/lib/marv/project/actions.rb +144 -0
  47. data/lib/marv/project/builder.rb +61 -0
  48. data/lib/marv/project/builder/assets.rb +112 -0
  49. data/lib/marv/{engines.rb → project/builder/engines.rb} +3 -1
  50. data/lib/marv/project/builder/functions.rb +112 -0
  51. data/lib/marv/project/builder/templates.rb +37 -0
  52. data/lib/marv/project/create.rb +139 -0
  53. data/lib/marv/project/guard.rb +83 -0
  54. data/lib/marv/project/guard/assets.rb +37 -0
  55. data/lib/{guard/marv → marv/project/guard}/config.rb +5 -9
  56. data/lib/marv/project/guard/functions.rb +44 -0
  57. data/lib/marv/project/guard/templates.rb +35 -0
  58. data/lib/marv/project/project.rb +149 -0
  59. data/lib/marv/server/actions.rb +79 -0
  60. data/lib/marv/server/create.rb +100 -0
  61. data/lib/marv/server/server.rb +201 -0
  62. data/marv.gemspec +69 -71
  63. metadata +82 -107
  64. data/.rspec +0 -1
  65. data/features/step_definitions/marv_steps.rb +0 -38
  66. data/features/support/env.rb +0 -17
  67. data/layouts/config/project-config.rb +0 -17
  68. data/layouts/plugin/javascripts/plugin.js +0 -1
  69. data/layouts/theme/stylesheets/_header.scss.erb +0 -18
  70. data/lib/guard/marv/assets.rb +0 -33
  71. data/lib/guard/marv/folders.rb +0 -33
  72. data/lib/guard/marv/functions.rb +0 -34
  73. data/lib/guard/marv/templates.rb +0 -33
  74. data/lib/marv/builder.rb +0 -355
  75. data/lib/marv/error.rb +0 -8
  76. data/lib/marv/generator.rb +0 -140
  77. data/lib/marv/guard.rb +0 -68
  78. data/lib/marv/project.rb +0 -134
  79. data/lib/marv/server.rb +0 -284
  80. data/spec/lib/marv/project_spec.rb +0 -34
  81. data/spec/spec_helper.rb +0 -12
@@ -1,33 +0,0 @@
1
- require 'guard'
2
- require 'guard/guard'
3
-
4
- module Guard
5
- class MarvFolders < ::Guard::Guard
6
-
7
- def initialize(watchers=[], options={})
8
- super
9
- end
10
-
11
- # Runs on marv watch
12
- def start
13
- copy_folders("Copying folders over", true)
14
- end
15
-
16
- # Runs on all command in guard console
17
- def run_all
18
- copy_folders("Rebuilding all folders", true)
19
- end
20
-
21
- # Called on file(s) modifications
22
- def run_on_change(paths)
23
- copy_folders("Folders have changed, copying over", nil)
24
- end
25
-
26
- # Copy folders
27
- def copy_folders(message, clean)
28
- UI.info message
29
- ::Marv::Guard.builder.copy_folders(clean)
30
- end
31
-
32
- end
33
- end
@@ -1,34 +0,0 @@
1
- require 'guard'
2
- require 'guard/guard'
3
-
4
- module Guard
5
- class MarvFunctions < ::Guard::Guard
6
-
7
- def initialize(watchers=[], options={})
8
- super
9
- end
10
-
11
- # Runs on marv watch
12
- def start
13
- copy_functions("Copying functions over", true)
14
- end
15
-
16
- # Runs on all command in guard console
17
- def run_all
18
- copy_functions("Rebuilding all functions", true)
19
- end
20
-
21
- # Called on file(s) modifications
22
- def run_on_change(paths)
23
- copy_functions("Functions have changed, copying over", nil)
24
- end
25
-
26
- # Copy and clean functions and includes folder
27
- def copy_functions(message, clean)
28
- UI.info message
29
- ::Marv::Guard.builder.copy_functions(clean)
30
- ::Marv::Guard.builder.copy_includes(clean)
31
- end
32
-
33
- end
34
- end
@@ -1,33 +0,0 @@
1
- require 'guard'
2
- require 'guard/guard'
3
-
4
- module Guard
5
- class MarvTemplates < ::Guard::Guard
6
-
7
- def initialize(watchers=[], options={})
8
- super
9
- end
10
-
11
- # Runs on marv watch
12
- def start
13
- copy_templates("Copying templates over", true)
14
- end
15
-
16
- # Runs on all command in guard console
17
- def run_all
18
- copy_templates("Rebuilding all templates", true)
19
- end
20
-
21
- # Called on file(s) modifications
22
- def run_on_change(paths)
23
- copy_templates("Templates have changed, copying over", nil)
24
- end
25
-
26
- # Copy templates
27
- def copy_templates(message, clean)
28
- UI.info message
29
- ::Marv::Guard.builder.copy_templates(clean)
30
- end
31
-
32
- end
33
- end
data/lib/marv/builder.rb DELETED
@@ -1,355 +0,0 @@
1
- require 'sprockets'
2
- require 'sass'
3
- require 'less'
4
- require 'zip'
5
- require 'marv/engines'
6
-
7
- module Marv
8
- class Builder
9
-
10
- def initialize(project)
11
- @project = project
12
- @task = project.task
13
- @templates_path = @project.templates_path
14
- @assets_path = @project.assets_path
15
- @functions_path = @project.functions_path
16
- @includes_path = @project.includes_path
17
- @package_path = @project.package_path
18
-
19
- init_sprockets
20
- end
21
-
22
- # Runs all the methods necessary to build a completed project
23
- def build
24
- clean_build_directory
25
- copy_folders
26
- copy_templates
27
- copy_functions
28
- copy_includes
29
- build_assets
30
- end
31
-
32
- # Use the rubyzip library to build a zip from the generated source
33
- def zip(filename=nil)
34
- filename = filename || File.basename(@project.root)
35
- project_base = File.basename(@project.root)
36
-
37
- zip_filename = File.join(File.basename(@package_path), "#{filename}.zip")
38
- # Create a temporary file for RubyZip to write to
39
- temp_filename = "#{zip_filename}.tmp"
40
-
41
- File.delete(temp_filename) if File.exists?(temp_filename)
42
-
43
- # Wrapping the zip creation in Thor's create_file to get "overwrite" prompts
44
- # Note: I could be overcomplicating this
45
- @task.create_file(zip_filename) do
46
- Zip::File.open(temp_filename, Zip::File::CREATE) do |zip|
47
- # Get all filenames in the build directory recursively
48
- filenames = Dir[File.join(@project.build_path, '**', '*')]
49
-
50
- # Remove the build directory path from the filename
51
- filenames.collect! {|path| path.gsub(/#{@project.build_path}\//, '')}
52
-
53
- # Add each file in the build directory to the zip file
54
- filenames.each do |filename|
55
- zip.add File.join(project_base, filename), File.join(@project.build_path, filename)
56
- end
57
- end
58
-
59
- # Give Thor contents of zip file for "overwrite" prompt
60
- File.open(temp_filename, 'rb') { |f| f.read }
61
- end
62
-
63
- # Clean up the temp file
64
- File.delete(temp_filename)
65
- end
66
-
67
- # Empty out the build directory
68
- def clean_build_directory
69
- # create build path if it does not exist
70
- unless File.exists?(@project.build_path)
71
- FileUtils.mkdir_p(@project.build_path)
72
- end
73
- # Empty the build path
74
- FileUtils.rm_rf Dir.glob(File.join(@project.build_path, '*'))
75
- end
76
-
77
- def clean_templates
78
- # TODO: cleaner way of removing templates only?
79
- Dir.glob(File.join(@project.build_path, '*.php')).each do |path|
80
- FileUtils.rm path unless path.include?('functions.php')
81
- end
82
- end
83
-
84
- def copy_templates(clean=nil)
85
- unless clean.nil?
86
- clean_templates
87
- end
88
-
89
- template_paths.each do |template_path|
90
- # Skip directories
91
- next if File.directory?(template_path)
92
-
93
- if template_path.end_with?('.erb')
94
- # Chop the .erb extension off the filename
95
- destination = File.join(@project.build_path, File.basename(template_path).slice(0..-5))
96
-
97
- write_erb(template_path, destination)
98
- else
99
- # Regular old copy of PHP-only files
100
- FileUtils.cp template_path, @project.build_path
101
- end
102
- end
103
- end
104
-
105
- def clean_functions
106
- #remove functions php
107
- if File.exists?(File.join(@project.build_path, 'functions.php'))
108
- FileUtils.rm File.join(@project.build_path, 'functions.php')
109
- end
110
- # Remove plugin file
111
- if File.exists?(@project.project_php_file)
112
- FileUtils.rm File.join(@project.build_path, @project.project_php_file)
113
- end
114
- # Remove functions folder
115
- if File.directory?(File.join(@project.build_path, 'functions'))
116
- FileUtils.rm_rf File.join(@project.build_path, 'functions')
117
- end
118
- end
119
-
120
- def copy_functions(clean=nil)
121
- # Clean functions
122
- unless clean.nil?
123
- clean_functions
124
- end
125
-
126
- # Copy functions
127
- functions_erb_path = File.join(@functions_path, 'functions.php.erb')
128
- functions_php_path = File.join(@functions_path, 'functions.php')
129
- plugin_php_path = File.join(@functions_path, @project.project_php_file)
130
-
131
- if File.exists?(functions_erb_path)
132
- destination = File.join(@project.build_path, 'functions.php')
133
- write_erb(functions_erb_path, destination)
134
- elsif File.exists?(functions_php_path)
135
- FileUtils.cp functions_php_path, @project.build_path
136
- end
137
-
138
- if File.exists?(plugin_php_path)
139
- FileUtils.cp plugin_php_path, @project.build_path
140
- end
141
-
142
- functions_paths = Dir.glob(File.join(@functions_path, '*')).reject do |filename|
143
- [functions_erb_path, functions_php_path, plugin_php_path].include?(filename)
144
- end
145
-
146
- unless functions_paths.empty?
147
- # Create the functions folder in the build directory
148
- unless File.directory?(File.join(@project.build_path, 'functions'))
149
- FileUtils.mkdir_p(File.join(@project.build_path, 'functions'))
150
- end
151
-
152
- # Iterate over all files in source/functions, skipping the actual functions.php file
153
- paths = Dir.glob(File.join(@functions_path, '**', '*')).reject do |filename|
154
- [functions_erb_path, functions_php_path, plugin_php_path].include?(filename)
155
- end
156
-
157
- copy_paths_with_erb(paths, @functions_path, File.join(@project.build_path, 'functions'))
158
- end
159
- end
160
-
161
- def clean_includes
162
- FileUtils.rm_rf File.join(@project.build_path, 'includes')
163
- end
164
-
165
- def copy_includes(clean=nil)
166
- # Clean Includes
167
- unless clean.nil?
168
- clean_includes
169
- end
170
-
171
- # Copy includes
172
- unless Dir.glob(File.join(@includes_path, '*')).empty?
173
- # Create the includes folder in the build directory
174
- unless File.directory?(File.join(@project.build_path, 'includes'))
175
- FileUtils.mkdir(File.join(@project.build_path, 'includes'))
176
- end
177
-
178
- # Iterate over all files in source/includes, so we can exclude if necessary
179
- paths = Dir.glob(File.join(@includes_path, '**', '*'))
180
- copy_paths_with_erb(paths, @includes_path, File.join(@project.build_path, 'includes'))
181
- end
182
- end
183
-
184
- def clean_folders(folder)
185
- # Clean folder
186
- relative_path = folder.gsub(@project.source_path, '')
187
- destination = File.join(@project.build_path, relative_path)
188
-
189
- FileUtils.rm_rf destination
190
- end
191
-
192
- def copy_folders(clean=nil)
193
- folders = Dir.glob(File.join(@project.source_path, '*'))
194
-
195
- folders.each do |folder|
196
- if File.directory?(folder)
197
- unless [@assets_path, @templates_path, @functions_path, @includes_path].include?(folder)
198
- # Clean folders
199
- unless clean.nil?
200
- clean_folders(folder)
201
- end
202
- # Copy folders
203
- paths = Dir.glob(File.join(folder, '**', '*'))
204
- copy_paths_with_erb(paths, @project.source_path, @project.build_path)
205
- end
206
- end
207
- end
208
- end
209
-
210
- def clean_images
211
- FileUtils.rm_rf File.join(@project.build_path, 'images')
212
- end
213
-
214
- def build_assets(clean=nil)
215
- # Clean images
216
- unless clean.nil?
217
- clean_images
218
- end
219
-
220
- # Build assets
221
- default_assets = [['style.css'], ['admin.css'], ['javascripts', 'theme.js'], ['javascripts', 'admin.js']]
222
- additional_assets = @project.config[:additional_assets]
223
-
224
- if additional_assets
225
- assets = default_assets + additional_assets
226
- else
227
- assets = default_assets
228
- end
229
-
230
- assets.each do |asset|
231
- destination = File.join(@project.build_path, asset)
232
-
233
- # Catch any sprockets errors and continue the process
234
- begin
235
- @task.shell.mute do
236
- sprocket = @sprockets.find_asset(asset.last)
237
-
238
- FileUtils.mkdir_p(File.dirname(destination)) unless File.directory?(File.dirname(destination))
239
- sprocket.write_to(destination) unless sprocket.nil?
240
- end
241
- rescue Exception => e
242
- @task.say "Error while building #{asset.last}:"
243
- @task.say e.message, :red
244
-
245
- File.open(destination, 'w') do |file|
246
- file.puts(e.message)
247
- end
248
-
249
- # Re-initializing sprockets to prevent further errors
250
- # TODO: This is done for lack of a better solution
251
- init_sprockets
252
- end
253
- end
254
-
255
- # Copy the images directory over
256
- if File.directory?(File.join(@assets_path, 'images'))
257
- FileUtils.cp_r(File.join(@assets_path, 'images'), @project.build_path)
258
- end
259
-
260
- # Check for screenshot and move it into main build directory
261
- Dir.glob(File.join(@project.build_path, 'images', '*')).each do |filename|
262
- if filename.index(/screenshot\.(png|jpg|jpeg|gif)/)
263
- FileUtils.mv(filename, @project.build_path + File::SEPARATOR )
264
- end
265
- end
266
- end
267
-
268
- private
269
-
270
- def copy_paths_with_erb(paths, source_dir, destination_dir)
271
- paths.each do |path|
272
- # Remove source directory from full file path to get the relative path
273
- relative_path = path.gsub(source_dir, '')
274
-
275
- destination = File.join(destination_dir, relative_path)
276
-
277
- if destination.end_with?('.erb')
278
- # Remove the .erb extension if the path was an erb file
279
- destination = destination.slice(0..-5)
280
- # And process it as an erb
281
- write_erb(path, destination)
282
- else
283
- # Otherwise, we simply move the file over
284
- FileUtils.mkdir_p(destination) if File.directory?(path)
285
- FileUtils.cp path, destination unless File.directory?(path)
286
- end
287
- end
288
- end
289
-
290
- def init_sprockets
291
- @sprockets = Sprockets::Environment.new
292
-
293
- ['javascripts', 'stylesheets'].each do |dir|
294
- @sprockets.append_path File.join(@assets_path, dir)
295
- end
296
-
297
- if @project.config[:compress_js]
298
- @sprockets.js_compressor = :uglify
299
- end
300
-
301
- if @project.config[:compress_css]
302
- @sprockets.css_compressor = :scss
303
- end
304
-
305
- # Add assets/styleshets to load path for Less Engine
306
- Tilt::LessTemplateWithPaths.load_path = File.join(@assets_path, 'stylesheets')
307
-
308
- @sprockets.register_engine '.less', Tilt::LessTemplateWithPaths
309
-
310
- # Passing the @project instance variable to the Sprockets::Context instance
311
- # used for processing the asset ERB files. Ruby meta-programming, FTW.
312
- @sprockets.context_class.instance_exec(@project) do |project|
313
- define_method :config do
314
- project.config
315
- end
316
- end
317
- end
318
-
319
- def template_paths
320
- Dir.glob(File.join(@templates_path, '**', '*'))
321
- end
322
-
323
- # Generate a unique filename for the zip output
324
- def get_output_filename(basename)
325
- package_path_base = File.basename(@package_path)
326
- filename = File.join(package_path_base, "#{basename}.zip")
327
-
328
- i = 1
329
- while File.exists?(filename)
330
- filename = File.join(package_path_base, "#{basename}(#{i}).zip")
331
- i += 1
332
- end
333
-
334
- filename
335
- end
336
-
337
- protected
338
-
339
- # Write an .erb from source to destination, catching and reporting errors along the way
340
- def write_erb(source, destination)
341
- begin
342
- @task.shell.mute do
343
- @task.create_file(destination) do
344
- @project.parse_erb(source)
345
- end
346
- end
347
- rescue Exception => e
348
- @task.say "Error while building #{File.basename(source)}:"
349
- @task.say e.message + "\n", :red
350
- exit
351
- end
352
- end
353
-
354
- end
355
- end