hamler 0.1.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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +59 -0
- data/Rakefile +1 -0
- data/bin/hamler +5 -0
- data/dtest/a_haml_file.html +1 -0
- data/dtest/subdir1/a_haml_file.html +1 -0
- data/hamler.gemspec +23 -0
- data/lib/hamler/version.rb +3 -0
- data/lib/hamler.rb +138 -0
- data/lib/template.erb +1 -0
- data/test/a.sass +0 -0
- data/test/a_haml_file.haml +8 -0
- data/test/a_haml_file.haml.html +11 -0
- data/test/a_haml_filehtml +1 -0
- data/test/subdir1/a_haml_file.haml +8 -0
- data/test/subdir2/a.js +1 -0
- data/test/subdir2/b.sass +2 -0
- metadata +120 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Wang Guan
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Hamler
|
2
|
+
|
3
|
+
one-line haml/sass/scss compiler
|
4
|
+
|
5
|
+
simply compiles each haml/sass/scss files, and output coresponding html/css files in place, or to another directory.
|
6
|
+
|
7
|
+
I would recommend `nanoc` for a more functional (non-1-on-1 assocation of files, layouts, etc) content compiler.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
$ gem install hamler
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
`hamler` without option prints
|
16
|
+
|
17
|
+
-i, --input-folder FOLDER folder of source files, MUST be given
|
18
|
+
-o, --output-folder FOLDER folder for output files, default to be the same with input-folder
|
19
|
+
-d, --dry-run dry run without actually modify or delete files
|
20
|
+
-p, --purge purge filenames that would be generated
|
21
|
+
-h, --help show this usage
|
22
|
+
|
23
|
+
invoke with `-i` and `-o` gives
|
24
|
+
|
25
|
+
$ hamler -i test -o /tmp
|
26
|
+
compile test/a.sass
|
27
|
+
create /tmp/a.css
|
28
|
+
compile test/a_haml_file.haml
|
29
|
+
create /tmp/a_haml_file.html
|
30
|
+
compile test/subdir1/a_haml_file.haml
|
31
|
+
create /tmp/subdir1/a_haml_file.html
|
32
|
+
compile test/subdir2/b.sass
|
33
|
+
create /tmp/subdir2/b.css
|
34
|
+
|
35
|
+
`-p` purge those files. empty folders remains
|
36
|
+
|
37
|
+
$ hamler -i test -o /tmp -p
|
38
|
+
remove /tmp/a.css
|
39
|
+
remove /tmp/a_haml_file.html
|
40
|
+
...
|
41
|
+
|
42
|
+
`-p -d` do not really purge those files
|
43
|
+
|
44
|
+
$ hamler -i test -o /tmp -p -d
|
45
|
+
would_remove /tmp/a.css
|
46
|
+
would_remove /tmp/a_haml_file.html
|
47
|
+
...
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create new Pull Request
|
56
|
+
|
57
|
+
## License
|
58
|
+
|
59
|
+
do-whatever-you-want-but-i-am-not-responsible-for-consequences 1.0
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/hamler
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
aaa
|
@@ -0,0 +1 @@
|
|
1
|
+
aaa
|
data/hamler.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hamler/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "hamler"
|
8
|
+
gem.version = Hamler::VERSION
|
9
|
+
gem.authors = ["Wang Guan"]
|
10
|
+
gem.email = ["momocraft@gmail.com"]
|
11
|
+
gem.description = %q{one-line haml/sass/scss compiler}
|
12
|
+
gem.summary = %q{compile haml/sass/scss files in one command}
|
13
|
+
gem.homepage = "https://github.com/jokester/hamler"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency "thor"
|
21
|
+
gem.add_runtime_dependency "haml"
|
22
|
+
gem.add_runtime_dependency "sass"
|
23
|
+
end
|
data/lib/hamler.rb
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
require "hamler/version"
|
2
|
+
require 'thor'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
def available? gemname
|
6
|
+
require gemname
|
7
|
+
rescue LoadError
|
8
|
+
false
|
9
|
+
else
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
module Hamler
|
14
|
+
class Hamler < ::Thor
|
15
|
+
include ::Thor::Actions
|
16
|
+
source_root File.dirname( __FILE__ )
|
17
|
+
no_tasks do
|
18
|
+
|
19
|
+
@@template = File.join( File.dirname( __FILE__ ), "template.erb" )
|
20
|
+
|
21
|
+
def source_root
|
22
|
+
options[:input_folder]
|
23
|
+
end
|
24
|
+
|
25
|
+
def output_folder
|
26
|
+
if not @output_folder
|
27
|
+
@output_folder = Pathname.new options[:output_folder]
|
28
|
+
end
|
29
|
+
@output_folder
|
30
|
+
end
|
31
|
+
|
32
|
+
def compile file, new_name
|
33
|
+
source = file.binread
|
34
|
+
@in_template =
|
35
|
+
case file.extname.downcase
|
36
|
+
when ".haml"
|
37
|
+
::Haml::Engine.new( source ).render
|
38
|
+
when '.sass'
|
39
|
+
::Sass::Engine.new( source, :syntax => :sass).render
|
40
|
+
when '.scss'
|
41
|
+
::Sass::Engine.new( source, :syntax => :scss).render
|
42
|
+
end
|
43
|
+
template @@template, new_name
|
44
|
+
end
|
45
|
+
|
46
|
+
def copy filename,ext,main
|
47
|
+
new_name = new_name( filename )
|
48
|
+
#copy_file filename, new_name
|
49
|
+
end
|
50
|
+
|
51
|
+
def input_folder
|
52
|
+
@input_folder ||= Pathname.new options[:input_folder]
|
53
|
+
end
|
54
|
+
|
55
|
+
def output_folder
|
56
|
+
@output_folder ||= Pathname.new( options[:output_folder] || options[:input_folder] )
|
57
|
+
end
|
58
|
+
|
59
|
+
def handle file
|
60
|
+
return unless file.file? and ['.haml','.sass','.scss'].include? file.extname
|
61
|
+
new_file = new_name file
|
62
|
+
if options[ :dry_run ] and options[ :purge ]
|
63
|
+
say_status :would_remove, new_file
|
64
|
+
elsif options[ :purge ]
|
65
|
+
remove_file new_file
|
66
|
+
elsif options[ :dry_run ]
|
67
|
+
say_status "would compile", file
|
68
|
+
say_status "and create", new_file
|
69
|
+
else
|
70
|
+
say_status :compile, file
|
71
|
+
compile file, new_file
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def new_name old_name
|
76
|
+
output_folder + old_name.relative_path_from( input_folder ).sub_ext( new_ext old_name )
|
77
|
+
rescue
|
78
|
+
output_folder + old_name.relative_path_from( input_folder )
|
79
|
+
end
|
80
|
+
|
81
|
+
def new_ext old_name
|
82
|
+
case old_name.extname
|
83
|
+
when '.sass', '.scss'
|
84
|
+
'.css'
|
85
|
+
when '.haml'
|
86
|
+
'.html'
|
87
|
+
else
|
88
|
+
raise "do not what to do with #{old_ext}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def root_task
|
93
|
+
Pathname.new( source_root ).find \
|
94
|
+
{|f| handle f }
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.with( argv )
|
101
|
+
options = {
|
102
|
+
:haml_available => available?("haml"),
|
103
|
+
:sass_available => available?("sass"),
|
104
|
+
:output_folder => false,
|
105
|
+
:input_folder => false,
|
106
|
+
:dry_run => false,
|
107
|
+
:purge => false,
|
108
|
+
}
|
109
|
+
o = OptionParser.new do |opts|
|
110
|
+
opts.banner = "Usage: hamler [options]"
|
111
|
+
opts.separator ''
|
112
|
+
opts.separator 'options:'
|
113
|
+
|
114
|
+
opts.on('-i FOLDER',
|
115
|
+
'--input-folder FOLDER',
|
116
|
+
'folder of source files, MUST be given') \
|
117
|
+
{|val| options[ :input_folder ] = val }
|
118
|
+
|
119
|
+
opts.on('-o', '--output-folder FOLDER', 'folder for output files, default to be the same with input-folder') \
|
120
|
+
{|val| options[ :output_folder ] = val }
|
121
|
+
opts.on('-d', '--dry-run', 'dry run without actually modify files') \
|
122
|
+
{|val| options[ :dry_run ] = val }
|
123
|
+
|
124
|
+
opts.on('-p', '--purge', 'purge filenames that would be generated') \
|
125
|
+
{|val| options[ :purge ] = val }
|
126
|
+
|
127
|
+
opts.on_tail('-h', '--help', 'show this usage') {puts opts}
|
128
|
+
end
|
129
|
+
o.parse( argv )
|
130
|
+
|
131
|
+
if options[ :input_folder ]
|
132
|
+
Hamler.new([],options).root_task
|
133
|
+
else
|
134
|
+
puts o
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
data/lib/template.erb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<%= @in_template %>
|
data/test/a.sass
ADDED
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
aaa
|
data/test/subdir2/a.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
alert();
|
data/test/subdir2/b.sass
ADDED
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hamler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Wang Guan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: thor
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: haml
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: sass
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: one-line haml/sass/scss compiler
|
63
|
+
email:
|
64
|
+
- momocraft@gmail.com
|
65
|
+
executables:
|
66
|
+
- hamler
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- bin/hamler
|
76
|
+
- dtest/a_haml_file.html
|
77
|
+
- dtest/subdir1/a_haml_file.html
|
78
|
+
- hamler.gemspec
|
79
|
+
- lib/hamler.rb
|
80
|
+
- lib/hamler/version.rb
|
81
|
+
- lib/template.erb
|
82
|
+
- test/a.sass
|
83
|
+
- test/a_haml_file.haml
|
84
|
+
- test/a_haml_file.haml.html
|
85
|
+
- test/a_haml_filehtml
|
86
|
+
- test/subdir1/a_haml_file.haml
|
87
|
+
- test/subdir2/a.js
|
88
|
+
- test/subdir2/b.sass
|
89
|
+
homepage: https://github.com/jokester/hamler
|
90
|
+
licenses: []
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 1.8.23
|
110
|
+
signing_key:
|
111
|
+
specification_version: 3
|
112
|
+
summary: compile haml/sass/scss files in one command
|
113
|
+
test_files:
|
114
|
+
- test/a.sass
|
115
|
+
- test/a_haml_file.haml
|
116
|
+
- test/a_haml_file.haml.html
|
117
|
+
- test/a_haml_filehtml
|
118
|
+
- test/subdir1/a_haml_file.haml
|
119
|
+
- test/subdir2/a.js
|
120
|
+
- test/subdir2/b.sass
|