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
@@ -0,0 +1,139 @@
1
+ module Marv
2
+ module Project
3
+ class Create
4
+
5
+ # Initialize project creator
6
+ def initialize(task, dir)
7
+ @task = task
8
+ @dir = dir
9
+ @path = project_path
10
+ @global = Marv::Global.new(task)
11
+ @options = project_options
12
+ @layout = layout_path
13
+
14
+ create_project
15
+ end
16
+
17
+ # Project path
18
+ def project_path
19
+ ::File.expand_path(@dir)
20
+ end
21
+
22
+ # Ask for project details
23
+ def project_options
24
+ # Check if project exists and abort
25
+ if ::File.directory?(@path)
26
+ @task.say "Project already exists", :red
27
+ abort
28
+ end
29
+
30
+ @task.say "This will create a new project.", :cyan
31
+ @task.say "Please enter project details below."
32
+
33
+ # Get project options
34
+ options = {}
35
+
36
+ options[:name] = @task.ask "Enter project name", :default => @global.config[:name]
37
+ options[:uri] = @task.ask "Enter project URI", :default => @global.config[:uri]
38
+ options[:version] = @task.ask "Enter project version", :default => @global.config[:version]
39
+ options[:description] = @task.ask "Enter project description", :default => @global.config[:description]
40
+
41
+ options.merge!(ask_author_details)
42
+ options.merge!(ask_project_layout)
43
+
44
+ return options
45
+ end
46
+
47
+ # Ask author details
48
+ def ask_author_details
49
+ options = {}
50
+
51
+ options[:author] = @task.ask "Enter project author", :default => @global.config[:author]
52
+ options[:author_uri] = @task.ask "Enter project author URI", :default => @global.config[:author_uri]
53
+ options[:license_name] = @task.ask "Enter project license name", :default => @global.config[:license_name]
54
+ options[:license_uri] = @task.ask "Enter project license URI", :default => @global.config[:license_uri]
55
+
56
+ return options
57
+ end
58
+
59
+ # Ask project layout
60
+ def ask_project_layout
61
+ options = {}
62
+
63
+ if @task.yes?("Do you want to use a local layout?")
64
+ options[:local_layout] = true
65
+ options[:layout] = @task.ask "Which layout do you want to use?", :limited_to => @global.layouts
66
+ else
67
+ options[:local_layout] = false
68
+ options[:layout] = @task.ask "Which layout do you want to use?", :limited_to => ["theme", "plugin"], :default => "theme"
69
+ end
70
+
71
+ return options
72
+ end
73
+
74
+ # Choosen layout path
75
+ def layout_path
76
+ layout = ::File.expand_path(::File.join(Marv.root, 'layouts', @options[:layout]))
77
+
78
+ if @options[:local_layout]
79
+ layout = ::File.join(@global.layouts_path, @options[:layout])
80
+ end
81
+
82
+ return layout
83
+ end
84
+
85
+ # Project config template
86
+ def config_template
87
+ ::File.expand_path(::File.join(Marv.root, 'layouts', 'config', 'project.rb'))
88
+ end
89
+
90
+ # Create project directories
91
+ def create_project_dirs
92
+ ::Dir.glob(::File.join(@layout, '**', '*')).each do |dir|
93
+ if ::File.directory?(dir)
94
+ # Get source and target files
95
+ source_dir = dir.gsub(@layout, '')
96
+ target_dir = ::File.join(@path, 'source', source_dir)
97
+
98
+ @task.empty_directory target_dir unless ::File.directory?(target_dir)
99
+ end
100
+ end
101
+
102
+ # Create .wacth dir
103
+ @task.shell.mute do
104
+ watch_dir = ::File.join(@path, '.watch', 'build')
105
+ @task.empty_directory watch_dir unless ::File.directory?(watch_dir)
106
+ end
107
+ end
108
+
109
+ # Create config file
110
+ def create_config_file
111
+ @project = Marv::Project::Project.new(@task, @path, @options)
112
+
113
+ config_rb = ::File.join(@path, 'config.rb')
114
+ @global.template config_template, config_rb, @project.context unless ::File.exists?(config_rb)
115
+ end
116
+
117
+ # Parse layout files in project dir
118
+ def parse_layout_files
119
+ ::Dir.glob(::File.join(@layout, '**', '*')).each do |file|
120
+ unless ::File.directory?(file)
121
+ # Get source and target files
122
+ source_file = file.gsub(@layout, '')
123
+ target_file = ::File.join(@path, 'source', source_file)
124
+ # Parse template file
125
+ @global.template file, target_file, @project.context
126
+ end
127
+ end
128
+ end
129
+
130
+ # Create a new project
131
+ def create_project
132
+ create_project_dirs
133
+ create_config_file
134
+ parse_layout_files
135
+ end
136
+
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,83 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+
4
+ # Marv pry console actions
5
+ require 'marv/project/guard/assets'
6
+ require 'marv/project/guard/config'
7
+ require 'marv/project/guard/functions'
8
+ require 'marv/project/guard/templates'
9
+
10
+ module Marv
11
+ module Project
12
+ module Guard
13
+
14
+ class << self
15
+ attr_accessor :project, :task, :builder
16
+ end
17
+
18
+ # Add guard
19
+ def self.add_guard(&block)
20
+ @additional_guards ||= []
21
+ @additional_guards << block
22
+ end
23
+
24
+ # Start project watcher
25
+ def self.start(project, builder, options={}, livereload={})
26
+ @project = project
27
+ @task = project.task
28
+ @builder = builder
29
+ @options = project.config
30
+
31
+ @options_hash = ""
32
+ @options.each do |k,v|
33
+ @options_hash << ", :#{k} => '#{v}'"
34
+ end
35
+
36
+ (@additional_guards || []).each do |block|
37
+ result = block.call(@options, livereload)
38
+ self.project_contents << result unless result.nil?
39
+ end
40
+ # Start guard watching
41
+ ::Guard.start({ :guardfile_contents => self.project_contents }).join
42
+ end
43
+
44
+ # Guard contents
45
+ def self.project_contents
46
+ assets_path = @project.assets_path.gsub(/#{@project.root}\//, '')
47
+ source_path = @project.source_path.gsub(/#{@project.root}\//, '')
48
+ config_file = @project.config_file.gsub(/#{@project.root}\//, '')
49
+
50
+ contents = %Q{
51
+ guard 'config'#{@options_hash} do
52
+ watch("#{config_file}")
53
+ end
54
+ guard 'assets' do
55
+ watch(%r{#{assets_path}/javascripts/*})
56
+ watch(%r{#{assets_path}/stylesheets/*})
57
+ watch(%r{#{assets_path}/images/*})
58
+ end
59
+ guard 'templates' do
60
+ watch(%r{#{source_path}/templates/*})
61
+ watch(%r{#{source_path}/partials/*})
62
+ end
63
+ guard 'functions' do
64
+ watch(%r{#{source_path}/functions/*})
65
+ watch(%r{#{source_path}/includes/*})
66
+ end
67
+ }
68
+
69
+ # Enable livereload
70
+ if @options[:livereload]
71
+ contents << %Q{
72
+ guard 'livereload' do
73
+ watch(%r{#{source_path}/*})
74
+ end
75
+ }
76
+ end
77
+
78
+ return contents
79
+ end
80
+
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,37 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+
4
+ module Guard
5
+ class Assets < ::Guard::Guard
6
+
7
+ def initialize(watchers=[], options={})
8
+ super
9
+ end
10
+
11
+ # Runs on marv watch
12
+ def start
13
+ build_all_assets "Building all assets"
14
+ end
15
+
16
+ # Runs on all command in guard console
17
+ def run_all
18
+ build_all_assets "Rebuilding all assets", true
19
+ end
20
+
21
+ # Called on file(s) modifications
22
+ def run_on_change(paths)
23
+ build_all_assets "Assets have changed, rebuilding..."
24
+ end
25
+
26
+ # Build all assets
27
+ def build_all_assets(message, clean=nil)
28
+ builder = Marv::Project::Guard.builder.assets
29
+
30
+ UI.info message
31
+ builder.clean_images unless clean.nil?
32
+ builder.copy_images
33
+ builder.build_assets
34
+ end
35
+
36
+ end
37
+ end
@@ -2,33 +2,29 @@ require 'guard'
2
2
  require 'guard/guard'
3
3
 
4
4
  module Guard
5
- class MarvConfig < ::Guard::Guard
5
+ class Config < ::Guard::Guard
6
6
 
7
7
  def initialize(watchers=[], options={})
8
+ @builder = Marv::Project::Guard.builder
8
9
  super
9
10
  end
10
11
 
11
12
  # This method should be mainly used for "reload"
12
13
  def reload
13
14
  UI.info "Reloading project config"
14
- ::Marv::Guard.project.load_config
15
+ @builder.build_project
15
16
  end
16
17
 
17
18
  # Runs on all command in guard console
18
19
  def run_all
19
20
  UI.info "Reloading project config"
20
- ::Marv::Guard.project.load_config
21
- true
21
+ @builder.build_project
22
22
  end
23
23
 
24
24
  # Called on file(s) modifications
25
25
  def run_on_change(paths)
26
26
  UI.info "Project config changed, reloading"
27
- ::Marv::Guard.project.load_config
28
- ::Marv::Guard.builder = ::Marv::Builder.new(::Marv::Guard.project)
29
-
30
- # Rebuild everything if the config changes
31
- ::Marv::Guard.builder.build
27
+ @builder.build_project
32
28
  end
33
29
 
34
30
  end
@@ -0,0 +1,44 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+
4
+ module Guard
5
+ class Functions < ::Guard::Guard
6
+
7
+ def initialize(watchers=[], options={})
8
+ super
9
+ end
10
+
11
+ # Runs on marv watch
12
+ def start
13
+ copy_all_functions "Copying functions over"
14
+ end
15
+
16
+ # Runs on all command in guard console
17
+ def run_all
18
+ copy_all_functions "Rebuilding all functions", true
19
+ end
20
+
21
+ # Called on file(s) modifications
22
+ def run_on_change(paths)
23
+ copy_all_functions "Functions have changed, copying over"
24
+ end
25
+
26
+ # Copy all functions
27
+ def copy_all_functions(message, clean=nil)
28
+ builder = Marv::Project::Guard.builder.functions
29
+
30
+ UI.info message
31
+
32
+ unless clean.nil?
33
+ builder.clean_functions
34
+ builder.clean_includes
35
+ builder.clean_folders
36
+ end
37
+
38
+ builder.copy_functions
39
+ builder.copy_includes
40
+ builder.copy_folders
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,35 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+
4
+ module Guard
5
+ class Templates < ::Guard::Guard
6
+
7
+ def initialize(watchers=[], options={})
8
+ super
9
+ end
10
+
11
+ # Runs on marv watch
12
+ def start
13
+ copy_all_templates "Copying templates over"
14
+ end
15
+
16
+ # Runs on all command in guard console
17
+ def run_all
18
+ copy_all_templates "Rebuilding all templates", true
19
+ end
20
+
21
+ # Called on file(s) modifications
22
+ def run_on_change(paths)
23
+ copy_all_templates "Templates have changed, copying over"
24
+ end
25
+
26
+ def copy_all_templates(message, clean=nil)
27
+ builder = Marv::Project::Guard.builder.templates
28
+
29
+ UI.info message
30
+ builder.clean_templates unless clean.nil?
31
+ builder.copy_templates
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,149 @@
1
+ require 'marv/project/builder'
2
+ require 'marv/project/guard'
3
+ require 'marv/project/actions'
4
+ require 'marv/project/create'
5
+
6
+ module Marv
7
+ module Project
8
+ class Project
9
+
10
+ attr_accessor :root, :config, :task, :assets, :context
11
+
12
+ # Initialize project config
13
+ def initialize(task, dir, options)
14
+ @task = task
15
+ @global = Marv::Global.new(task)
16
+ @dir = ::File.expand_path(dir)
17
+ @options = options
18
+ @root = root_path
19
+ @config_file = config_file
20
+ @config = project_config
21
+ @assets = project_assets
22
+ @context = project_context
23
+ end
24
+
25
+ # Project id
26
+ def project_id
27
+ ::File.basename(@dir).gsub(/\W/, '_').downcase
28
+ end
29
+
30
+ # Project root path
31
+ def root_path
32
+ ::File.expand_path(@dir)
33
+ end
34
+
35
+ # Project source path
36
+ def source_path
37
+ ::File.join(root_path, 'source')
38
+ end
39
+
40
+ # Project build path
41
+ def build_path
42
+ ::File.join(root_path, '.watch', 'build')
43
+ end
44
+
45
+ # Project package path
46
+ def package_path
47
+ ::File.join(root_path, 'package')
48
+ end
49
+
50
+ # Project assets path
51
+ def assets_path
52
+ ::File.join(source_path, 'assets')
53
+ end
54
+
55
+ # Project functions path
56
+ def functions_path
57
+ ::File.join(source_path, 'functions')
58
+ end
59
+
60
+ # Project templates path
61
+ def templates_path
62
+ ::File.join(source_path, 'templates')
63
+ end
64
+
65
+ # Project includes path
66
+ def includes_path
67
+ ::File.join(source_path, 'includes')
68
+ end
69
+
70
+ # Config file
71
+ def config_file
72
+ ::File.join(root_path, 'config.rb')
73
+ end
74
+
75
+ # Plugin php file
76
+ def plugin_file
77
+ ::File.join(functions_path, "#{project_id.gsub('_', '-')}.php")
78
+ end
79
+
80
+ # Theme functions file
81
+ def functions_file
82
+ ::File.join(functions_path, 'functions.php')
83
+ end
84
+
85
+ # Project config file
86
+ def project_config
87
+ config = {}
88
+
89
+ # Merge global config
90
+ config.merge!(@global.config)
91
+
92
+ if @options.nil?
93
+ config.merge!(project_config_file)
94
+ else
95
+ optional_config_file
96
+ config.merge!(@options)
97
+ end
98
+
99
+ return config
100
+ end
101
+
102
+ # Check for config.rb in project folder
103
+ def project_config_file
104
+ config_file = {}
105
+
106
+ if ::File.exists?(@config_file)
107
+ config_file = @global.load_ruby_config(@config_file)
108
+ else
109
+ @task.say "Could not find the config file!", :red
110
+ @task.say "Are you sure you're in a marv project directory?"
111
+ abort
112
+ end
113
+
114
+ return config_file
115
+ end
116
+
117
+ # Check for config file in options
118
+ def optional_config_file
119
+ if ::File.exists?(@options.to_s)
120
+ @options = @global.load_ruby_config(::File.expand_path(@options))
121
+ end
122
+ end
123
+
124
+ # Get all project assets
125
+ def project_assets
126
+ assets = [
127
+ ['style.css'],
128
+ ['plugin.css'],
129
+ ['admin.css'],
130
+ ['javascripts', 'theme.js'],
131
+ ['javascripts', 'plugin.js'],
132
+ ['javascripts', 'admin.js']
133
+ ]
134
+
135
+ if project_config[:additional_assets]
136
+ assets = assets | project_config[:additional_assets]
137
+ end
138
+
139
+ return assets
140
+ end
141
+
142
+ # Get project class context
143
+ def project_context
144
+ instance_eval('binding')
145
+ end
146
+
147
+ end
148
+ end
149
+ end