guard_boilerplate 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 0.1.0 (Mar 19, 2011)
2
+
3
+ Initial release.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in guard_boilerplate.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,146 @@
1
+ # WTF?
2
+
3
+ In the vein of the [HTML5 Boilerplate](http://html5boilerplate.com) project, this is a simple script that allows you to run [Guard](http://github.com/guard/guard) to refresh your web browser and optionally recompile [Sass](http://sass-lang.com/) files to CSS and/or [Haml](http://haml-lang.com/) files to HTML. Just install it, run`gbp start` in your project directory root and you're off to the races. A Guardfile gets created which you can customize to your tastes.
4
+
5
+ # tl;dr
6
+
7
+ Impatient? Have Ruby installed and understand what a gem is? Use the Boilerplates? Rocking Sass and Haml? Great!
8
+
9
+ 1. Install the [LiveReload](https://github.com/mockko/livereload#readme) extension in your browser
10
+ 2. Install guard_boilerplate and start a new project:
11
+ gem install guard_boilerplate
12
+ mkdir my_site && cd my_site
13
+ curl -L 'https://github.com/paulirish/html5-boilerplate/tarball/v1.0rc' | tar -xzf - --strip-components 1
14
+ gbp hamlize && gbp sassify
15
+ gbp start
16
+ 3. Hit the LiveReload **LR** button in your browser
17
+ 4. Edit!
18
+
19
+ Confused? Read on...
20
+
21
+ # Before!
22
+
23
+ ## Ruby
24
+
25
+ You will need to have Ruby already installed on your system, but chances are you do already.
26
+
27
+ ### Mac OS X And Linux (RVM)
28
+
29
+ If you are on Mac OS X or Linux, then [RVM](http://rvm.beginrescueend.com/) to the rescue:
30
+
31
+ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
32
+ source "$HOME/.rvm/scripts/rvm"
33
+ cat <<BASHRC >> "$HOME/.bash_profile"
34
+
35
+ [[ -s "\$HOME/.rvm/scripts/rvm" ]] && . "\$HOME/.rvm/scripts/rvm"
36
+ BASHRC
37
+ rvm 1.9.2 install && rvm 1.9.2 --default
38
+
39
+ ### Windows (Rails Installer)
40
+
41
+ This is slighty more than you'll need, but do yourself a favor and use the [Rails Installer](http://railsinstaller.org/) for Windows. It's fast, painless and as a bonus you'll be ready to crank out a [Ruby on Rails](http://rubyonrails.org/) or [Sinatra](http://www.sinatrarb.com/) web application in 5 minutes flat. \[*pause...*\] See, wasn't that easy?
42
+
43
+ ## LiveReload Browser Extension
44
+
45
+ Secondly, you will need to install the LiveReload browser extension into your browser-du-jour ([Chrome Chrome Chome!](http://google.com/chrome)). For more detailed instructions, see the LiveReload's [github README](https://github.com/mockko/livereload) and look for the extension installation section.
46
+
47
+ # Install!
48
+
49
+ Are you ready?
50
+
51
+ gem install guard_boilerplate
52
+
53
+ Now give yourself a slap on the back.
54
+
55
+ # Use!
56
+
57
+ ## Refresh Automatically
58
+
59
+ Change directory into your new web-wonder project directory, and start the listener:
60
+
61
+ cd my_site
62
+ gbp start
63
+
64
+ Using the bassass [HTML5 Boilerplate](http://html5boilerplate.com/) as your base? I thought
65
+ so. Try this one out, my Mac and Linux pals:
66
+
67
+ mkdir my_site && cd my_site
68
+ curl -L 'https://github.com/paulirish/html5-boilerplate/tarball/v1.0rc' | tar -xzf - --strip-components 1
69
+ gbp start
70
+
71
+ LiveReload needs to refresh an `http://` URL (rather than a `file://`), so an embedded HTTP server will fire up by default on port 3000 thanks to the [WEBrick guard](https://github.com/fnichol/guard-webrick).
72
+
73
+ Finally, if you're sitting there with your browser page open, don't forget to activate the LiveReload extension. Otherwise, it's going to get pretty darn boring. Open your `my_site` project in your text editor, update `index.html`, save, and marvel ;)
74
+
75
+ ## Sass Up Your Stylesheets
76
+
77
+ Would you rather author Sass stylesheets? Migrate your `*.css` files to `*.scss` files automatically:
78
+
79
+ gbp sassify
80
+
81
+ Your CSS files will be generated back into `css/` on save. Sweet.
82
+
83
+ ## Haml Your Markup
84
+
85
+ If Haml is your bag, then you can also convert your `*.html` files to `*.haml` with a quick round of:
86
+
87
+ gbp hamlize
88
+
89
+ ## Minify Your Haml And SASS Output
90
+
91
+ To compress your HTML and CSS output (suitable for production):
92
+
93
+ gbp minify
94
+
95
+ ## Prettify Your Haml And Sass Output
96
+
97
+ To generate all your HTML and CSS output (suitable for development):
98
+
99
+ gbp prettify
100
+
101
+ # Customize!
102
+
103
+ The file that controls "what happens when" is your `Guardfile` which is pretty straight forward. The `'livereload'` block has a bundle of `watch` listeners that are file patterns. Whenever any of these files change, any attached web browsers will be reloaded with LiveReload.
104
+
105
+ If your images directory was actually `images/` and could contain gifs, then you could modify the `Guardfile` line from:
106
+
107
+ watch(%r{img/.+\.(png|jpeg|jpg)})
108
+
109
+ to:
110
+
111
+ watch(%r{images/.+\.(gif|png|jpeg|jpg)})
112
+
113
+ If you need the HTTP server to run on another port, update the `'webrick'` block to:
114
+
115
+ guard 'webrick', :port => 8080 do
116
+ end
117
+
118
+ Don't worry, your web browser will keep up.
119
+
120
+ # Profit!
121
+
122
+ Just fill in your [Step 2](http://www.youtube.com/watch?v=y-eak9Jz3_k) and you're on your way.
123
+
124
+ # Development
125
+
126
+ * Source hosted at [GitHub](http://github.com/fnichol/guard_boilerplate).
127
+ * Report Issues/Questions/Feature requests on [GitHub Issues](http://github.com/fnichol/guard_boilerplate/issues).
128
+
129
+ Pull requests are very welcome!
130
+
131
+ # Authors
132
+
133
+ * [Fletcher Nichol](http://github.com/fnichol) ([@fnichol](http://twitter.com/fnichol))
134
+
135
+ Special credit to [Natasha Nunn](http://github.com/nnunn) ([@nnunny](http://twitter.com/nnunny)) for giving me the lunch hour power project idea
136
+
137
+ # References
138
+
139
+ * [Guard](https://github.com/guard/guard)
140
+ * [Guard-LiveReload plugin](https://github.com/guard/guard-livereload)
141
+ * [Guard-Sass plugin](https://github.com/guard/guard-sass)
142
+ * [Guard-WEBrick plugin](https://github.com/fnichol/guard-webrick)
143
+ * [LiveReload](https://github.com/mockko/livereload)
144
+ * [Sass](http://sass-lang.com/)
145
+ * [RVM](http://rvm.beginrescueend.com/)
146
+ * [Rails Installer](http://railsinstaller.org)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/gbp ADDED
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'thor'
5
+ require 'guard'
6
+ require 'fileutils'
7
+ require 'sass'
8
+ require 'haml/html'
9
+
10
+ class GuardBoilerPlate < Thor
11
+ include Thor::Actions
12
+
13
+ desc "start", "Starts a guard process for development"
14
+ def start
15
+ unless File.exists?(File.expand_path(File.join(Dir::pwd, 'Guardfile')))
16
+ say "\nYou don't have a Guardfile in this directory, let's make it!", :green
17
+ invoke :init
18
+ end
19
+ load File.join(Gem.loaded_specs['guard'].full_gem_path, 'bin', 'guard')
20
+ end
21
+
22
+ desc "init", "Generates a Guardfile in the current working directory"
23
+ def init
24
+ copy_file( File.join(%w{templates Guardfile}), "Guardfile")
25
+ copy_file( File.join(%w{README.md}), "HOWTOUSE.md")
26
+ end
27
+
28
+ desc "sassify", "Migrates CSS files to SCSS files"
29
+ def sassify
30
+ if File.directory? "sass"
31
+ say "\nA sass/ directory already exists, so skipping\n", :red
32
+ else
33
+ say "Copying CSS files to SCSS...", :green
34
+ FileUtils.mkdir_p "sass", :verbose => true
35
+ Dir["css/**/*.css"].each do |css_file|
36
+ scss_file = css_file.sub(/^css/, 'sass').sub(/\.css$/, '.scss')
37
+ FileUtils.mkdir_p(File.dirname(scss_file))
38
+ FileUtils.cp css_file, scss_file, :verbose => true
39
+ say "Generated #{scss_file} from #{css_file} (straight copy)", :green
40
+ end
41
+ end
42
+ end
43
+
44
+ desc "hamlize", "Migrates your HTML files to Haml files"
45
+ def hamlize
46
+ if File.directory? "haml"
47
+ say "\nA haml/ directory already exists, so skipping\n", :red
48
+ else
49
+ say "Converting HTML files to Haml...", :green
50
+ FileUtils.mkdir_p "haml", :verbose => true
51
+ Dir["**/*.html"].each { |html_file| html_to_haml(html_file) }
52
+ end
53
+ end
54
+
55
+ desc "minify", "Compresses your HTML files from Haml and CSS files from SCSS"
56
+ def minify
57
+ if File.directory? "haml"
58
+ say "\nMinifying HTML from Haml...", :green
59
+ Dir["haml/**/*.haml"].each do |haml_file|
60
+ haml_to_html(haml_file, :ugly => true)
61
+ end
62
+ end
63
+ if File.directory? "sass"
64
+ say "\nMinifying CSS from SCSS...", :green
65
+ Dir["sass/**/*.scss"].each do |scss_file|
66
+ scss_to_css(scss_file, :style => :compressed)
67
+ end
68
+ end
69
+ end
70
+
71
+ desc "prettify", "Pretties your HTML files from Haml and CSS files from SCSS"
72
+ def prettify
73
+ if File.directory? "haml"
74
+ say "\nPrettifying HTML from Haml...", :green
75
+ Dir["haml/**/*.haml"].each do |haml_file|
76
+ haml_to_html(haml_file)
77
+ end
78
+ end
79
+ if File.directory? "sass"
80
+ say "\nPrettifying CSS from SCSS...", :green
81
+ Dir["sass/**/*.scss"].each do |scss_file|
82
+ scss_to_css(scss_file)
83
+ end
84
+ end
85
+ end
86
+
87
+ def self.source_root
88
+ File.expand_path(File.join(File.dirname(__FILE__), '..'))
89
+ end
90
+
91
+ private
92
+
93
+ def html_to_haml(html_file)
94
+ haml_file = File.join('haml', html_file.sub(/\.html?$/, '.haml'))
95
+
96
+ template = File.open(html_file, 'rb') { |f| f.read }
97
+ output = Haml::HTML.new(template).render
98
+ FileUtils.mkdir_p(File.dirname(haml_file))
99
+ File.open(haml_file, 'w') {|f| f.write(output) }
100
+ say "Generated #{haml_file} from #{html_file}", :green
101
+ end
102
+
103
+ def haml_to_html(haml_file, options = {})
104
+ options = { :format => :html5 }.update(options)
105
+ html_file = haml_file.sub(/^haml\//, '').sub(/\.haml$/, '.html')
106
+
107
+ template = File.open(haml_file, 'rb') { |f| f.read }
108
+ output = Haml::Engine.new(template, options).render
109
+ File.open(html_file, 'w') {|f| f.write(output) }
110
+ say "Generated #{html_file} from #{haml_file}", :green
111
+ end
112
+
113
+ def scss_to_css(scss_file, options = {})
114
+ options = { :syntax => :scss, :style => :expanded }.update(options)
115
+ css_file = scss_file.sub(/^sass/, 'css').sub(/\.scss$/, '.css')
116
+
117
+ template = File.open(scss_file, 'rb') { |f| f.read }
118
+ output = Sass::Engine.new(template, options).render
119
+ File.open(css_file, 'w') {|f| f.write(output) }
120
+ say "Generated #{css_file} from #{scss_file}", :green
121
+ end
122
+ end
123
+
124
+ GuardBoilerPlate.start
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "guard_boilerplate"
7
+ s.version = GuardBoilerPlate::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Fletcher Nichol"]
10
+ s.email = ["fnichol@nichol.ca"]
11
+ s.homepage = "http://rubygems.org/gems/guard_boilerplate"
12
+ s.summary = %q{A simple script that allows you to run Guard to refresh your web browser and optionally recompile Sass/Haml files}
13
+ s.description = %q{A simple script that allows you to run Guard to refresh your web browser and optionally recompile Sass/Haml files}
14
+
15
+ s.required_rubygems_version = '>= 1.3.6'
16
+ s.rubyforge_project = "guard_boilerplate"
17
+
18
+ s.add_dependency 'thor', '~> 0.14.6'
19
+ s.add_dependency 'growl', '~> 1.0.3'
20
+ s.add_dependency 'guard', '~> 0.3.0'
21
+ s.add_dependency 'guard-livereload', '~> 0.1.9'
22
+ s.add_dependency 'guard-sass', '~> 0.0.6'
23
+ s.add_dependency 'guard-shell', '~> 0.1.1'
24
+ s.add_dependency 'guard-webrick', '~> 0.1.0'
25
+ s.add_dependency 'hpricot', '~> 0.8.4'
26
+
27
+ s.files = `git ls-files`.split("\n")
28
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
29
+ s.require_paths = ["lib"]
30
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module GuardBoilerPlate
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ # More info at https://github.com/guard/guard#readme
2
+
3
+ guard 'sass' do
4
+ watch(%r{sass/.+\.(scss|sass)})
5
+ end
6
+
7
+ guard 'shell' do
8
+ watch(%r{haml/(.+)\.haml}) do |m|
9
+ `haml -f html5 #{File.join("haml", m[1])}.haml #{m[1]}.html`
10
+ puts "Rebuilt #{m[1]}.html"
11
+ end
12
+ end
13
+
14
+ guard 'webrick', :port => 3000 do
15
+ end
16
+
17
+ guard 'livereload' do
18
+ watch(%r{.+\.(html|htm)})
19
+ watch(%r{css/.+\.(css)})
20
+ watch(%r{sass/.+\.(scss|sass)})
21
+ watch(%r{img/.+\.(png|jpeg|jpg)})
22
+ watch(%r{js/.+\.(js)})
23
+ end
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard_boilerplate
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Fletcher Nichol
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-19 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thor
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 43
30
+ segments:
31
+ - 0
32
+ - 14
33
+ - 6
34
+ version: 0.14.6
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: growl
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 17
46
+ segments:
47
+ - 1
48
+ - 0
49
+ - 3
50
+ version: 1.0.3
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: guard
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 19
62
+ segments:
63
+ - 0
64
+ - 3
65
+ - 0
66
+ version: 0.3.0
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-livereload
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ hash: 9
78
+ segments:
79
+ - 0
80
+ - 1
81
+ - 9
82
+ version: 0.1.9
83
+ type: :runtime
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: guard-sass
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ hash: 19
94
+ segments:
95
+ - 0
96
+ - 0
97
+ - 6
98
+ version: 0.0.6
99
+ type: :runtime
100
+ version_requirements: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ name: guard-shell
103
+ prerelease: false
104
+ requirement: &id006 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ hash: 25
110
+ segments:
111
+ - 0
112
+ - 1
113
+ - 1
114
+ version: 0.1.1
115
+ type: :runtime
116
+ version_requirements: *id006
117
+ - !ruby/object:Gem::Dependency
118
+ name: guard-webrick
119
+ prerelease: false
120
+ requirement: &id007 !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ hash: 27
126
+ segments:
127
+ - 0
128
+ - 1
129
+ - 0
130
+ version: 0.1.0
131
+ type: :runtime
132
+ version_requirements: *id007
133
+ - !ruby/object:Gem::Dependency
134
+ name: hpricot
135
+ prerelease: false
136
+ requirement: &id008 !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ hash: 55
142
+ segments:
143
+ - 0
144
+ - 8
145
+ - 4
146
+ version: 0.8.4
147
+ type: :runtime
148
+ version_requirements: *id008
149
+ description: A simple script that allows you to run Guard to refresh your web browser and optionally recompile Sass/Haml files
150
+ email:
151
+ - fnichol@nichol.ca
152
+ executables:
153
+ - gbp
154
+ extensions: []
155
+
156
+ extra_rdoc_files: []
157
+
158
+ files:
159
+ - .gitignore
160
+ - CHANGELOG.md
161
+ - Gemfile
162
+ - README.md
163
+ - Rakefile
164
+ - bin/gbp
165
+ - guard_boilerplate.gemspec
166
+ - lib/version.rb
167
+ - templates/Guardfile
168
+ has_rdoc: true
169
+ homepage: http://rubygems.org/gems/guard_boilerplate
170
+ licenses: []
171
+
172
+ post_install_message:
173
+ rdoc_options: []
174
+
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ none: false
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ hash: 3
183
+ segments:
184
+ - 0
185
+ version: "0"
186
+ required_rubygems_version: !ruby/object:Gem::Requirement
187
+ none: false
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ hash: 23
192
+ segments:
193
+ - 1
194
+ - 3
195
+ - 6
196
+ version: 1.3.6
197
+ requirements: []
198
+
199
+ rubyforge_project: guard_boilerplate
200
+ rubygems_version: 1.6.2
201
+ signing_key:
202
+ specification_version: 3
203
+ summary: A simple script that allows you to run Guard to refresh your web browser and optionally recompile Sass/Haml files
204
+ test_files: []
205
+