marv 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/.document +5 -0
  2. data/.gitmodules +3 -0
  3. data/.rspec +1 -0
  4. data/CHANGELOG.md +8 -0
  5. data/Gemfile +29 -0
  6. data/Gemfile.lock +140 -0
  7. data/LICENSE +20 -0
  8. data/README.md +49 -0
  9. data/Rakefile +54 -0
  10. data/VERSION +1 -0
  11. data/bin/marv +12 -0
  12. data/features/step_definitions/marv_steps.rb +38 -0
  13. data/features/support/env.rb +17 -0
  14. data/layouts/config/config.tt +19 -0
  15. data/layouts/default/functions/functions.php.erb +34 -0
  16. data/layouts/default/javascripts/admin.js +1 -0
  17. data/layouts/default/javascripts/theme.js +1 -0
  18. data/layouts/default/stylesheets/_header.scss.erb +18 -0
  19. data/layouts/default/stylesheets/_reset.scss +5 -0
  20. data/layouts/default/stylesheets/_typography.scss +5 -0
  21. data/layouts/default/stylesheets/style.css.scss.erb +32 -0
  22. data/layouts/default/templates/404.php.erb +10 -0
  23. data/layouts/default/templates/archive.php.erb +11 -0
  24. data/layouts/default/templates/attachment.php.erb +32 -0
  25. data/layouts/default/templates/comments.php +2 -0
  26. data/layouts/default/templates/footer.php +9 -0
  27. data/layouts/default/templates/header.php.erb +30 -0
  28. data/layouts/default/templates/index.php +4 -0
  29. data/layouts/default/templates/page.php +14 -0
  30. data/layouts/default/templates/partials/loop.php.erb +36 -0
  31. data/layouts/default/templates/search.php.erb +12 -0
  32. data/layouts/default/templates/sidebar.php +9 -0
  33. data/layouts/default/templates/single.php.erb +30 -0
  34. data/lib/guard/marv/assets.rb +31 -0
  35. data/lib/guard/marv/config.rb +34 -0
  36. data/lib/guard/marv/functions.rb +36 -0
  37. data/lib/guard/marv/templates.rb +28 -0
  38. data/lib/marv.rb +11 -0
  39. data/lib/marv/builder.rb +282 -0
  40. data/lib/marv/cli.rb +86 -0
  41. data/lib/marv/config.rb +61 -0
  42. data/lib/marv/engines.rb +12 -0
  43. data/lib/marv/error.rb +8 -0
  44. data/lib/marv/generator.rb +138 -0
  45. data/lib/marv/guard.rb +65 -0
  46. data/lib/marv/project.rb +162 -0
  47. data/lib/marv/version.rb +3 -0
  48. data/marv.gemspec +145 -0
  49. data/spec/lib/marv/config_spec.rb +79 -0
  50. data/spec/lib/marv/project_spec.rb +34 -0
  51. data/spec/spec_helper.rb +13 -0
  52. metadata +404 -0
@@ -0,0 +1,138 @@
1
+
2
+ module Marv
3
+ class Generator
4
+ class << self
5
+ def run(project, layout='default')
6
+ generator = self.new(project, layout)
7
+ generator.run
8
+ end
9
+ end
10
+
11
+ def initialize(project, layout='default')
12
+ @project = project
13
+ @task = project.task
14
+ @layout = layout
15
+ end
16
+
17
+ def create_structure
18
+ # Create the build directory for Marv output
19
+ @task.empty_directory @project.build_path
20
+
21
+ source_paths = [
22
+ ['assets', 'images'],
23
+ ['assets', 'javascripts'],
24
+ ['assets', 'stylesheets'],
25
+ ['assets', 'lib'],
26
+
27
+ ['functions'],
28
+
29
+ ['includes'],
30
+ ['extras'],
31
+
32
+ ['templates', 'pages'],
33
+ ['templates', 'partials'],
34
+ ]
35
+
36
+ # Build out Marv structure in the source directory
37
+ source_paths.each do |path|
38
+ @task.empty_directory File.join(@project.source_path, path)
39
+ end
40
+
41
+ self
42
+ end
43
+
44
+ def copy_stylesheets
45
+ source = File.expand_path(File.join(self.layout_path, 'stylesheets'))
46
+ target = File.expand_path(File.join(@project.assets_path, 'stylesheets'))
47
+
48
+ render_directory(source, target)
49
+
50
+ self
51
+ end
52
+
53
+ def copy_javascript
54
+ source = File.expand_path(File.join(self.layout_path, 'javascripts'))
55
+ target = File.expand_path(File.join(@project.assets_path, 'javascripts'))
56
+
57
+ render_directory(source, target)
58
+
59
+ self
60
+ end
61
+
62
+ def copy_templates
63
+ source = File.expand_path(File.join(self.layout_path, 'templates'))
64
+ target = File.expand_path(File.join(@project.source_path, 'templates'))
65
+
66
+ render_directory(source, target)
67
+
68
+ self
69
+ end
70
+
71
+ def copy_functions
72
+ source = File.expand_path(File.join(self.layout_path, 'functions', 'functions.php.erb'))
73
+ target = File.expand_path(File.join(@project.source_path, 'functions', 'functions.php'))
74
+
75
+ write_template(source, target)
76
+ end
77
+
78
+ def layout_path
79
+ @layout_path ||= File.join(Marv::ROOT, 'layouts', @layout)
80
+ end
81
+
82
+ def run
83
+ write_config
84
+ create_structure
85
+ copy_stylesheets
86
+ copy_javascript
87
+ copy_templates
88
+ copy_functions
89
+ return self
90
+ end
91
+
92
+ def write_config
93
+ unless File.exists?(@project.global_config_file)
94
+ @task.shell.mute do
95
+ @task.create_file(@project.global_config_file) do
96
+ "# Place your global configuration values here\n# config[:livereload] = true"
97
+ end
98
+ end
99
+ end
100
+
101
+ write_template(['config', 'config.tt'], @project.config_file)
102
+
103
+ self
104
+ end
105
+
106
+ def write_template(source, target)
107
+ source = File.join(source)
108
+ template = File.expand_path(@task.find_in_source_paths((source)))
109
+ target = File.expand_path(File.join(target))
110
+
111
+ @task.create_file target do
112
+ @project.parse_erb(template)
113
+ end
114
+ end
115
+
116
+ protected
117
+ def render_directory(source, target)
118
+ Dir.glob("#{source}/**/*") do |file|
119
+ unless File.directory?(file)
120
+ source_file = file.gsub(source, '')
121
+ target_file = File.join(target, source_file)
122
+
123
+ if source_file.end_with? ".erb"
124
+ target_file = target_file.slice(0..-5)
125
+
126
+ content = @project.parse_erb(file)
127
+ else
128
+ content = File.open(file).read
129
+ end
130
+
131
+ @task.create_file target_file do
132
+ content
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
data/lib/marv/guard.rb ADDED
@@ -0,0 +1,65 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+
4
+ module Marv
5
+ module Guard
6
+
7
+ class << self
8
+ attr_accessor :project, :task, :builder
9
+ end
10
+
11
+ def self.add_guard(&block)
12
+ @additional_guards ||= []
13
+ @additional_guards << block
14
+ end
15
+
16
+ def self.start(project, task, options={}, livereload={})
17
+ @project = project
18
+ @task = task
19
+ @builder = Builder.new(project)
20
+
21
+ options_hash = ""
22
+ options.each do |k,v|
23
+ options_hash << ", :#{k} => '#{v}'"
24
+ end
25
+
26
+ assets_path = @project.assets_path.gsub(/#{@project.root}\//, '')
27
+ source_path = @project.source_path.gsub(/#{@project.root}\//, '')
28
+ config_file = @project.config_file.gsub(/#{@project.root}\//, '')
29
+
30
+ guardfile_contents = %Q{
31
+ guard 'marvconfig'#{options_hash} do
32
+ watch("#{config_file}")
33
+ end
34
+ guard 'marvassets' do
35
+ watch(%r{#{assets_path}/javascripts/*})
36
+ watch(%r{#{assets_path}/stylesheets/*})
37
+ watch(%r{#{assets_path}/images/*})
38
+ end
39
+ guard 'marvtemplates' do
40
+ watch(%r{#{source_path}/templates/*})
41
+ watch(%r{#{source_path}/partials/*})
42
+ end
43
+ guard 'marvfunctions' do
44
+ watch(%r{#{source_path}/functions/*})
45
+ watch(%r{#{source_path}/includes/*})
46
+ watch(%r{#{source_path}/extras/*})
47
+ end
48
+ }
49
+
50
+ if @project.config[:livereload]
51
+ guardfile_contents << %Q{
52
+ guard 'livereload' do
53
+ watch(%r{#{source_path}/*})
54
+ end
55
+ }
56
+ end
57
+
58
+ (@additional_guards || []).each do |block|
59
+ result = block.call(options, livereload)
60
+ guardfile_contents << result unless result.nil?
61
+ end
62
+ ::Guard.start({ :guardfile_contents => guardfile_contents }).join
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,162 @@
1
+ require 'pathname'
2
+ require 'compass'
3
+
4
+ module Marv
5
+ class Project
6
+ class << self
7
+ def create(root, config, task)
8
+ root = File.expand_path(root)
9
+
10
+ project = self.new(root, task, config)
11
+ Generator.run(project)
12
+
13
+ project
14
+ end
15
+ end
16
+
17
+ attr_accessor :root, :config, :task
18
+
19
+ def initialize(root, task, config={}, config_file=nil)
20
+ @root = File.expand_path(root)
21
+ @config = config || {}
22
+ @task = task
23
+ @config_file = config_file
24
+
25
+ self.load_config if @config.empty?
26
+ end
27
+
28
+ def assets_path
29
+ @assets_path ||= File.join(self.source_path, 'assets')
30
+ end
31
+
32
+ def build_path
33
+ File.join(self.root, '.watch', 'build')
34
+ end
35
+
36
+ def source_path
37
+ File.join(self.root, 'source')
38
+ end
39
+
40
+ def package_path
41
+ File.join(self.root, 'package')
42
+ end
43
+
44
+ def templates_path
45
+ File.join(self.source_path, 'templates')
46
+ end
47
+
48
+ def functions_path
49
+ File.join(self.source_path, 'functions')
50
+ end
51
+
52
+ def includes_path
53
+ File.join(self.source_path, 'includes')
54
+ end
55
+
56
+ def extras_path
57
+ File.join(self.source_path, 'extras')
58
+ end
59
+
60
+ def config_file
61
+ @config_file ||= File.join(self.root, 'config.rb')
62
+ end
63
+
64
+ def global_config_file
65
+ @global_config_file ||= File.join(ENV['HOME'], '.watch', 'config.rb')
66
+ end
67
+
68
+ # Create a symlink from source to the project build dir
69
+ def link(source)
70
+ source = File.expand_path(source)
71
+
72
+ unless File.directory?(File.dirname(source))
73
+ raise Marv::LinkSourceDirNotFound
74
+ end
75
+
76
+ @task.link_file build_path, source
77
+ end
78
+
79
+ def theme_id
80
+ File.basename(self.root).gsub(/\W/, '_')
81
+ end
82
+
83
+ def load_config
84
+ config = {}
85
+
86
+ # Check for global (user) config.rb
87
+ if File.exists?(self.global_config_file)
88
+ config.merge!(load_ruby_config(self.global_config_file))
89
+ end
90
+
91
+ # Check for config.rb
92
+ if File.exists?(self.config_file)
93
+ config.merge!(load_ruby_config(self.config_file))
94
+ else
95
+ # Old format of config file
96
+ if File.exists?(File.join(self.root, 'config.json'))
97
+ config.merge!(convert_old_config)
98
+ else
99
+ raise Error, "Could not find the config file, are you sure you're in a
100
+ marv project directory?"
101
+ end
102
+ end
103
+
104
+ @config = config
105
+ end
106
+
107
+ def get_binding
108
+ binding
109
+ end
110
+
111
+ def parse_erb(file)
112
+ ERB.new(::File.binread(file), nil, '-', '@output_buffer').result(binding)
113
+ end
114
+
115
+ private
116
+
117
+ def convert_old_config
118
+ require 'json'
119
+
120
+ # Let the user know what is going to happen
121
+ @task.say("It looks like you are using the old JSON-format config. Marv will now try converting your config to the new Ruby format.")
122
+ @task.ask(" Press any key to continue...")
123
+
124
+ begin
125
+ old_file_name = File.join(self.root, 'config.json')
126
+ # Parse the old config format, convert keys to symbols
127
+ @config = JSON.parse(File.open(old_file_name).read).inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
128
+
129
+ @task.create_file(@config_file) do
130
+ # Find the config.tt template, and parse it using ERB
131
+ config_template_path = @task.find_in_source_paths(File.join(['config', 'config.tt']))
132
+ parse_erb(File.expand_path(config_template_path))
133
+ end
134
+ rescue Exception => e
135
+ @task.say "Error while building new config file:", Thor::Shell::Color::RED
136
+ @task.say e.message, Thor::Shell::Color::RED
137
+ @task.say "You'll need to either fix the error and try again, or manually convert your config.json file to Ruby format (config.rb)"
138
+ exit
139
+ end
140
+
141
+ @task.say "Success! Double-check that all your config values were moved over, and you can now delete config.json.", Thor::Shell::Color::GREEN
142
+
143
+ # We now have a Ruby config file, so we can continue loading as normal
144
+ return load_ruby_config(self.config_file)
145
+ end
146
+
147
+ def load_ruby_config(file)
148
+ config = {}
149
+
150
+ begin
151
+ # Config file is just executed as straight ruby
152
+ eval(File.read(file))
153
+ rescue Exception => e
154
+ @task.say "Error while evaluating config file:"
155
+ @task.say e.message, Thor::Shell::Color::RED
156
+ end
157
+
158
+ return config
159
+ end
160
+
161
+ end
162
+ end
@@ -0,0 +1,3 @@
1
+ module Marv
2
+ VERSION = "0.1"
3
+ end
data/marv.gemspec ADDED
@@ -0,0 +1,145 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "marv"
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Hardpixel"]
12
+ s.date = "2014-07-28"
13
+ s.description = "A toolkit for bootstrapping and developing WordPress themes using Sass, LESS, and CoffeeScript."
14
+ s.email = "info@hardpixel.eu"
15
+ s.executables = ["marv"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.md"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitmodules",
23
+ ".rspec",
24
+ "CHANGELOG.md",
25
+ "Gemfile",
26
+ "Gemfile.lock",
27
+ "LICENSE",
28
+ "README.md",
29
+ "Rakefile",
30
+ "VERSION",
31
+ "bin/marv",
32
+ "features/step_definitions/marv_steps.rb",
33
+ "features/support/env.rb",
34
+ "layouts/config/config.tt",
35
+ "layouts/default/functions/functions.php.erb",
36
+ "layouts/default/javascripts/admin.js",
37
+ "layouts/default/javascripts/theme.js",
38
+ "layouts/default/stylesheets/_header.scss.erb",
39
+ "layouts/default/stylesheets/_reset.scss",
40
+ "layouts/default/stylesheets/_typography.scss",
41
+ "layouts/default/stylesheets/style.css.scss.erb",
42
+ "layouts/default/templates/404.php.erb",
43
+ "layouts/default/templates/archive.php.erb",
44
+ "layouts/default/templates/attachment.php.erb",
45
+ "layouts/default/templates/comments.php",
46
+ "layouts/default/templates/footer.php",
47
+ "layouts/default/templates/header.php.erb",
48
+ "layouts/default/templates/index.php",
49
+ "layouts/default/templates/page.php",
50
+ "layouts/default/templates/partials/loop.php.erb",
51
+ "layouts/default/templates/search.php.erb",
52
+ "layouts/default/templates/sidebar.php",
53
+ "layouts/default/templates/single.php.erb",
54
+ "lib/guard/marv/assets.rb",
55
+ "lib/guard/marv/config.rb",
56
+ "lib/guard/marv/functions.rb",
57
+ "lib/guard/marv/templates.rb",
58
+ "lib/marv.rb",
59
+ "lib/marv/builder.rb",
60
+ "lib/marv/cli.rb",
61
+ "lib/marv/config.rb",
62
+ "lib/marv/engines.rb",
63
+ "lib/marv/error.rb",
64
+ "lib/marv/generator.rb",
65
+ "lib/marv/guard.rb",
66
+ "lib/marv/project.rb",
67
+ "lib/marv/version.rb",
68
+ "marv.gemspec",
69
+ "spec/lib/marv/config_spec.rb",
70
+ "spec/lib/marv/project_spec.rb",
71
+ "spec/spec_helper.rb"
72
+ ]
73
+ s.homepage = "https://github.com/hardpixel/marv"
74
+ s.licenses = ["MIT"]
75
+ s.require_paths = ["lib"]
76
+ s.rubygems_version = "1.8.23"
77
+ s.summary = "A tool for developing wordpress themes"
78
+
79
+ if s.respond_to? :specification_version then
80
+ s.specification_version = 3
81
+
82
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
83
+ s.add_runtime_dependency(%q<thor>, [">= 0.18.1"])
84
+ s.add_runtime_dependency(%q<guard>, [">= 2.2.1"])
85
+ s.add_runtime_dependency(%q<guard-livereload>, [">= 2.0.0"])
86
+ s.add_runtime_dependency(%q<sprockets>, [">= 2.12.0"])
87
+ s.add_runtime_dependency(%q<rubyzip>, [">= 1.0.0"])
88
+ s.add_runtime_dependency(%q<json>, [">= 1.8.0"])
89
+ s.add_runtime_dependency(%q<sass>, [">= 3.3.0"])
90
+ s.add_runtime_dependency(%q<sprockets-sass>, [">= 1.2.0"])
91
+ s.add_runtime_dependency(%q<compass>, [">= 1.0.0.alpha.21"])
92
+ s.add_runtime_dependency(%q<rack>, [">= 1.5.2"])
93
+ s.add_runtime_dependency(%q<therubyracer>, [">= 0.12.0"])
94
+ s.add_runtime_dependency(%q<less>, [">= 2.6.0"])
95
+ s.add_runtime_dependency(%q<coffee-script>, [">= 2.3.0"])
96
+ s.add_runtime_dependency(%q<rb-fsevent>, [">= 0.9.3"])
97
+ s.add_runtime_dependency(%q<yui-compressor>, [">= 0.12.0"])
98
+ s.add_development_dependency(%q<rspec>, [">= 0"])
99
+ s.add_development_dependency(%q<cucumber>, [">= 0"])
100
+ s.add_development_dependency(%q<aruba>, [">= 0"])
101
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
102
+ else
103
+ s.add_dependency(%q<thor>, [">= 0.18.1"])
104
+ s.add_dependency(%q<guard>, [">= 2.2.1"])
105
+ s.add_dependency(%q<guard-livereload>, [">= 2.0.0"])
106
+ s.add_dependency(%q<sprockets>, [">= 2.12.0"])
107
+ s.add_dependency(%q<rubyzip>, [">= 1.0.0"])
108
+ s.add_dependency(%q<json>, [">= 1.8.0"])
109
+ s.add_dependency(%q<sass>, [">= 3.3.0"])
110
+ s.add_dependency(%q<sprockets-sass>, [">= 1.2.0"])
111
+ s.add_dependency(%q<compass>, [">= 1.0.0.alpha.21"])
112
+ s.add_dependency(%q<rack>, [">= 1.5.2"])
113
+ s.add_dependency(%q<therubyracer>, [">= 0.12.0"])
114
+ s.add_dependency(%q<less>, [">= 2.6.0"])
115
+ s.add_dependency(%q<coffee-script>, [">= 2.3.0"])
116
+ s.add_dependency(%q<rb-fsevent>, [">= 0.9.3"])
117
+ s.add_dependency(%q<yui-compressor>, [">= 0.12.0"])
118
+ s.add_dependency(%q<rspec>, [">= 0"])
119
+ s.add_dependency(%q<cucumber>, [">= 0"])
120
+ s.add_dependency(%q<aruba>, [">= 0"])
121
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
122
+ end
123
+ else
124
+ s.add_dependency(%q<thor>, [">= 0.18.1"])
125
+ s.add_dependency(%q<guard>, [">= 2.2.1"])
126
+ s.add_dependency(%q<guard-livereload>, [">= 2.0.0"])
127
+ s.add_dependency(%q<sprockets>, [">= 2.12.0"])
128
+ s.add_dependency(%q<rubyzip>, [">= 1.0.0"])
129
+ s.add_dependency(%q<json>, [">= 1.8.0"])
130
+ s.add_dependency(%q<sass>, [">= 3.3.0"])
131
+ s.add_dependency(%q<sprockets-sass>, [">= 1.2.0"])
132
+ s.add_dependency(%q<compass>, [">= 1.0.0.alpha.21"])
133
+ s.add_dependency(%q<rack>, [">= 1.5.2"])
134
+ s.add_dependency(%q<therubyracer>, [">= 0.12.0"])
135
+ s.add_dependency(%q<less>, [">= 2.6.0"])
136
+ s.add_dependency(%q<coffee-script>, [">= 2.3.0"])
137
+ s.add_dependency(%q<rb-fsevent>, [">= 0.9.3"])
138
+ s.add_dependency(%q<yui-compressor>, [">= 0.12.0"])
139
+ s.add_dependency(%q<rspec>, [">= 0"])
140
+ s.add_dependency(%q<cucumber>, [">= 0"])
141
+ s.add_dependency(%q<aruba>, [">= 0"])
142
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
143
+ end
144
+ end
145
+