marv 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,144 @@
1
+ require 'zip'
2
+
3
+ module Marv
4
+ module Project
5
+ class Actions
6
+
7
+ # Initialize project actions
8
+ def initialize(project, builder)
9
+ @project = project
10
+ @task = project.task
11
+ @builder = builder
12
+ @global = Marv::Global.new(project.task)
13
+ end
14
+
15
+ # Link project
16
+ def link(dir)
17
+ @link_dir = dir
18
+
19
+ link_options
20
+ link_target
21
+ create_link
22
+ end
23
+
24
+ # Packgage project
25
+ def package(filename)
26
+ @package_name = filename
27
+
28
+ create_package
29
+ end
30
+
31
+ # Ask for link details
32
+ def link_options
33
+ options = {}
34
+ options[:folder] = @task.ask "Where do you want to link your project?", :limited_to => ["themes", "plugins"], :default => "themes"
35
+
36
+ @link_options = options
37
+ end
38
+
39
+ # Link to server
40
+ def link_to_server
41
+ unless @link_dir.nil?
42
+ ::File.join(@global.servers_path, @link_dir, 'wp-content', @link_options[:folder], ::File.basename(@project.root))
43
+ end
44
+ end
45
+
46
+ # Link to wordpress
47
+ def link_to_folder
48
+ unless @link_dir.nil?
49
+ unless @global.servers.include?(@link_dir)
50
+ ::File.join(@link_dir, 'wp-content', @link_options[:folder], ::File.basename(@project.root))
51
+ end
52
+ end
53
+ end
54
+
55
+ # Link target
56
+ def link_target
57
+ target = ::File.join(@global.global_path, @link_options[:folder], ::File.basename(@project.root))
58
+ target = link_to_server unless link_to_server.nil?
59
+ target = link_to_folder unless link_to_folder.nil?
60
+
61
+ @link_target = target
62
+ end
63
+
64
+ # Create project link
65
+ def create_link
66
+ unless ::File.directory?(@project.build_path)
67
+ @task.shell.mute do
68
+ @task.empty_directory @project.build_path
69
+ end
70
+ end
71
+
72
+ @task.create_link @link_target, @project.build_path
73
+ end
74
+
75
+ # Create package
76
+ def create_package
77
+ create_package_dir
78
+ set_package_filename
79
+ build_to_temp_dir
80
+ create_temp_zip
81
+ create_zip_file
82
+ remove_temp_files
83
+ end
84
+
85
+ # Create package directory
86
+ def create_package_dir
87
+ @task.shell.mute do
88
+ unless ::File.directory?(@project.package_path)
89
+ @task.empty_directory @project.package_path
90
+ end
91
+ end
92
+ end
93
+
94
+ # Set the package file name
95
+ def set_package_filename
96
+ if @package_name.nil?
97
+ @package_name = ::File.basename(@project.root)
98
+ end
99
+ end
100
+
101
+ # Built to a temporary directory
102
+ def build_to_temp_dir
103
+ @builder.build_project
104
+
105
+ # Copy build files to temporary directory
106
+ @task.shell.mute do
107
+ @task.directory @project.build_path, ::File.join(@project.package_path, @package_name)
108
+ end
109
+ end
110
+
111
+ # Create temporary package
112
+ def create_temp_zip
113
+ tmp_filename = ::File.join(@project.package_path, "#{@package_name}.tmp")
114
+
115
+ # Create an temporary file
116
+ ::Zip.continue_on_exists_proc = true
117
+ ::Zip::File.open(tmp_filename, Zip::File::CREATE) do |zip|
118
+ # Get all filenames
119
+ filenames = ::Dir.glob(::File.join(@project.package_path, @package_name, '**', '*'))
120
+
121
+ # Add each file in the zip file
122
+ filenames.each do |filename|
123
+ zip.add filename.gsub("#{@project.package_path}/", ''), filename
124
+ end
125
+ end
126
+ end
127
+
128
+ # Create the package
129
+ def create_zip_file
130
+ zip_filename = ::File.join(@project.package_path, "#{@package_name}.zip")
131
+ @task.copy_file ::File.join(@project.package_path, "#{@package_name}.tmp"), zip_filename
132
+ end
133
+
134
+ # Remove temporary build directory
135
+ def remove_temp_files
136
+ @task.shell.mute do
137
+ @task.remove_dir ::File.join(@project.package_path, @package_name)
138
+ @task.remove_file ::File.join(@project.package_path, "#{@package_name}.tmp")
139
+ end
140
+ end
141
+
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,61 @@
1
+ require 'marv/project/builder/engines'
2
+ require 'marv/project/builder/assets'
3
+ require 'marv/project/builder/functions'
4
+ require 'marv/project/builder/templates'
5
+
6
+ module Marv
7
+ module Project
8
+ class Builder
9
+
10
+ attr_accessor :task, :project, :assets, :functions, :templates
11
+
12
+ # Initialize project builder
13
+ def initialize(project)
14
+ @project = project
15
+ @task = project.task
16
+ @config = project.config
17
+ @assets = Marv::Project::Assets.new(self)
18
+ @functions = Marv::Project::Functions.new(self)
19
+ @templates = Marv::Project::Templates.new(self)
20
+ end
21
+
22
+ # Start builder
23
+ def build_project
24
+ clean_directory
25
+
26
+ @assets.build_assets
27
+ @assets.clean_images
28
+ @assets.copy_images
29
+
30
+ @templates.clean_templates
31
+ @templates.copy_templates
32
+
33
+ @functions.clean_functions
34
+ @functions.copy_functions
35
+ @functions.clean_includes
36
+ @functions.copy_includes
37
+ @functions.clean_folders
38
+ @functions.copy_folders
39
+ end
40
+
41
+ # Build project to a directory
42
+ def build_to(dir)
43
+ build_project
44
+ # Remove build directory
45
+ @task.shell.mute do
46
+ @task.remove_dir ::File.expand_path(dir)
47
+ end
48
+ # Copy files from .watch/build directory
49
+ @task.directory @project.build_path, ::File.expand_path(dir)
50
+ end
51
+
52
+ # Clean build directory
53
+ def clean_directory
54
+ @task.shell.mute do
55
+ @task.remove_dir @project.build_path
56
+ end
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,112 @@
1
+ require 'sprockets'
2
+
3
+ module Marv
4
+ module Project
5
+ class Assets
6
+
7
+ # Initialize assets builder
8
+ def initialize(builder)
9
+ @builder = builder
10
+ @task = builder.task
11
+ @project = builder.project
12
+ @config = builder.project.config
13
+
14
+ init_sprockets
15
+ end
16
+
17
+ # Clean images
18
+ def clean_images
19
+ @task.shell.mute do
20
+ # Remove screenshot image
21
+ ::Dir.glob(::File.join(@project.build_path, 'screenshot.*')).each do |file|
22
+ @task.remove_file file
23
+ end
24
+
25
+ # Remove images folder
26
+ @task.remove_dir ::File.join(@project.build_path, 'images')
27
+ end
28
+ end
29
+
30
+ # Copy images
31
+ def copy_images
32
+ @task.shell.mute do
33
+ ::Dir.glob(::File.join(@project.assets_path, 'images', '*')).each do |filename|
34
+ # Check for screenshot and move it into main build directory
35
+ if filename.index(/screenshot/)
36
+ @task.copy_file filename, ::File.join(@project.build_path, ::File.basename(filename)), :force => true
37
+ else
38
+ # Copy the other files in images directory
39
+ @task.copy_file filename, ::File.join(@project.build_path, 'images'), :force => true
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ # Build assets
46
+ def build_assets
47
+ @project.assets.each do |asset|
48
+ # Catch any sprockets errors and continue the process
49
+ begin
50
+ build_asset_file asset
51
+ rescue Exception => e
52
+ print_asset_error asset, e.message
53
+ end
54
+ end
55
+ end
56
+
57
+ # Build asset file
58
+ def build_asset_file(asset)
59
+ destination = ::File.join(@project.build_path, asset)
60
+
61
+ @task.shell.mute do
62
+ sprocket = @sprockets.find_asset(asset.last)
63
+ # Create asset destination
64
+ @task.empty_directory ::File.dirname(destination) unless ::File.directory?(::File.dirname(destination))
65
+ # Write file to destination
66
+ sprocket.write_to(destination) unless sprocket.nil?
67
+ end
68
+ end
69
+
70
+ # Print error to screen and file
71
+ def print_asset_error(asset, message)
72
+ destination = ::File.join(@project.build_path, asset)
73
+
74
+ @task.say "Error while building #{asset.last}:"
75
+ @task.say message, :red
76
+
77
+ @task.shell.mute do
78
+ @task.create_file destination unless ::File.exists?(destination)
79
+ @task.append_to_file destination, message
80
+ end
81
+ end
82
+
83
+ # Init sprockets
84
+ def init_sprockets
85
+ @sprockets = ::Sprockets::Environment.new
86
+
87
+ ['javascripts', 'stylesheets'].each do |dir|
88
+ @sprockets.append_path ::File.join(@project.assets_path, dir)
89
+ end
90
+
91
+ # Check for js compression
92
+ if @config[:compress_js]
93
+ @sprockets.js_compressor = :uglify
94
+ end
95
+
96
+ # Check for css compression
97
+ if @config[:compress_css]
98
+ @sprockets.css_compressor = :scss
99
+ end
100
+
101
+ # Passing the @project instance variable to the Sprockets::Context instance
102
+ # used for processing the asset ERB files
103
+ @sprockets.context_class.instance_exec(@project) do |project|
104
+ define_method :config do
105
+ project.config
106
+ end
107
+ end
108
+ end
109
+
110
+ end
111
+ end
112
+ end
@@ -1,5 +1,7 @@
1
+ require 'tilt'
2
+
1
3
  module Tilt
2
- class LessTemplateWithPaths < LessTemplate
4
+ class SprocketsLessTemplate < LessTemplate
3
5
 
4
6
  class << self
5
7
  attr_accessor :load_path
@@ -0,0 +1,112 @@
1
+ module Marv
2
+ module Project
3
+ class Functions
4
+
5
+ # Initialize functions builder
6
+ def initialize(builder)
7
+ @builder = builder
8
+ @task = builder.task
9
+ @project = builder.project
10
+ @config = builder.project.config
11
+ end
12
+
13
+ # Clean functions
14
+ def clean_functions
15
+ @task.shell.mute do
16
+ #remove functions and plugin php
17
+ @task.remove_file ::File.join(@project.build_path, ::File.basename(@project.functions_file))
18
+ @task.remove_file ::File.join(@project.build_path, ::File.basename(@project.plugin_file))
19
+
20
+ # Remove functions folder
21
+ @task.remove_dir ::File.join(@project.build_path, 'functions')
22
+ end
23
+ end
24
+
25
+ # Copy functions
26
+ def copy_functions
27
+ @task.shell.mute do
28
+ files = copy_functions_files
29
+
30
+ ::Dir.glob(::File.join(@project.functions_path, '*')).each do |file|
31
+ unless files.include?(file)
32
+ @task.copy_file file, ::File.join(@project.build_path, 'functions', ::File.basename(file)), :force => true
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ # Copy functions
39
+ def copy_functions_files
40
+ files = [@project.functions_file, @project.plugin_file]
41
+
42
+ ::Dir.glob(::File.join(@project.functions_path, '*')).each do |file|
43
+ if files.include?(file)
44
+ @task.copy_file file, ::File.join(@project.build_path, ::File.basename(file)), :force => true
45
+ end
46
+ end
47
+
48
+ return files
49
+ end
50
+
51
+ # Clean includes
52
+ def clean_includes
53
+ @task.shell.mute do
54
+ @task.remove_dir ::File.join(@project.build_path, 'includes')
55
+ end
56
+ end
57
+
58
+ # Copy includes
59
+ def copy_includes
60
+ @task.shell.mute do
61
+ ::Dir.glob(::File.join(@project.includes_path, '**', '*')).each do |file|
62
+ source = file.gsub(@project.source_path, '')
63
+ target = ::File.join(@project.build_path, source)
64
+
65
+ @task.copy_file file, target, :force => true unless ::File.directory?(file)
66
+ end
67
+ end
68
+ end
69
+
70
+ # Clean folders
71
+ def clean_folders
72
+ @task.shell.mute do
73
+ # Clean extra folder from project root
74
+ extra_folders.each do |folder|
75
+ source = folder.gsub(@project.source_path, '')
76
+ target = ::File.join(@project.build_path, source)
77
+
78
+ @task.remove_dir target
79
+ end
80
+ end
81
+ end
82
+
83
+ # Copy folders
84
+ def copy_folders
85
+ @task.shell.mute do
86
+ # Copy extra folders to project root
87
+ extra_folders.each do |folder|
88
+ source = folder.gsub(@project.source_path, '')
89
+ target = ::File.join(@project.build_path, source)
90
+
91
+ @task.directory folder, target
92
+ end
93
+ end
94
+ end
95
+
96
+ # Extra folders
97
+ def extra_folders
98
+ default = ['assets', 'functions', 'includes', 'templates']
99
+ folders = []
100
+ # Remove marv folders from root path
101
+ ::Dir.glob(::File.join(@project.source_path, '*')).each do |folder|
102
+ if ::File.directory?(folder) and ! default.include?(::File.basename(folder))
103
+ folders << folder
104
+ end
105
+ end
106
+ # Return folders array
107
+ return folders
108
+ end
109
+
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,37 @@
1
+ module Marv
2
+ module Project
3
+ class Templates
4
+
5
+ # Initialize templates builder
6
+ def initialize(builder)
7
+ @builder = builder
8
+ @task = builder.task
9
+ @project = builder.project
10
+ @config = builder.project.config
11
+ end
12
+
13
+ # Clean Templates
14
+ def clean_templates
15
+ @task.shell.mute do
16
+ ::Dir.glob(::File.join(@project.build_path, '*.php')).each do |file|
17
+ unless file.include?('functions.php') || file.include?(::File.basename(@project.plugin_file))
18
+ @task.remove_file file
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ # Copy templates
25
+ def copy_templates
26
+ @task.shell.mute do
27
+ ::Dir.glob(::File.join(@project.templates_path, '**', '*')).each do |file|
28
+ target = ::File.join(@project.build_path, ::File.basename(file))
29
+
30
+ @task.copy_file file, target, :force => true unless ::File.directory?(file)
31
+ end
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end