hamlize 0.0.3
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 +4 -0
- data/Gemfile +2 -0
- data/README.md +11 -0
- data/Rakefile +1 -0
- data/bin/hamlize +4 -0
- data/hamlize.gemspec +26 -0
- data/lib/hamlize.rb +5 -0
- data/lib/hamlize/cli.rb +59 -0
- data/lib/hamlize/converter.rb +41 -0
- data/lib/hamlize/guard.rb +14 -0
- data/lib/hamlize/version.rb +3 -0
- data/spec/hamlize_spec.rb +47 -0
- data/spec/sandbox/files/index.haml +3 -0
- data/spec/sandbox/files/pages/toc.haml +7 -0
- data/spec/sandbox/source/index.haml +5 -0
- data/spec/sandbox/source/pages/toc.haml +7 -0
- data/spec/spec_helper.rb +2 -0
- metadata +135 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Hamlize!!!!!!
|
2
|
+
|
3
|
+
Usage: hamlize [OPTIONS]
|
4
|
+
|
5
|
+
Description:
|
6
|
+
Converts a directory of HAML files.
|
7
|
+
|
8
|
+
Options:
|
9
|
+
-a, --auto Automatically convert file when they change.
|
10
|
+
-s, --source DIRECTORY Source directory of HAML files
|
11
|
+
-o, --output DIRECTORY Destination of the compiled files
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/hamlize
ADDED
data/hamlize.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "hamlize/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "hamlize"
|
7
|
+
s.version = Hamlize::VERSION
|
8
|
+
s.authors = ["Matte Noble"]
|
9
|
+
s.email = ["me@mattenoble.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Convert a directory of HAML into HTML.}
|
12
|
+
s.description = %q{Convert a directory of HAML into HTML.}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.executables = ["hamlize"]
|
19
|
+
|
20
|
+
s.add_development_dependency "rspec", "~> 2.7.0"
|
21
|
+
s.add_dependency "haml"
|
22
|
+
s.add_dependency "guard-haml"
|
23
|
+
s.add_dependency "rb-fsevent"
|
24
|
+
s.add_dependency "rb-inotify"
|
25
|
+
s.add_dependency "rb-fchange"
|
26
|
+
end
|
data/lib/hamlize.rb
ADDED
data/lib/hamlize/cli.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
module Hamlize
|
2
|
+
class CLI
|
3
|
+
attr_reader :options
|
4
|
+
|
5
|
+
def initialize(args=[])
|
6
|
+
@args = args
|
7
|
+
@options = default_options
|
8
|
+
end
|
9
|
+
|
10
|
+
def start!
|
11
|
+
OptionParser.new(&method(:set_opts)).parse!(@args)
|
12
|
+
@options[:auto] ? auto! : default!
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def default!
|
18
|
+
Converter.new(@options).start!
|
19
|
+
end
|
20
|
+
|
21
|
+
def auto!
|
22
|
+
require "guard"
|
23
|
+
::Guard.start(:watchdir => @options[:source], :guardfile_contents => %{
|
24
|
+
require "hamlize/guard"
|
25
|
+
|
26
|
+
guard "hamlize", :source => "#{@options[:source]}", :output => "#{@options[:output]}" do
|
27
|
+
watch %r(^.+\.haml$)
|
28
|
+
end
|
29
|
+
})
|
30
|
+
end
|
31
|
+
|
32
|
+
def default_options
|
33
|
+
{ auto: false, source: Dir.pwd, output: File.join(Dir.pwd, "compiled") }
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_opts(opts)
|
37
|
+
opts.banner = <<-END
|
38
|
+
Usage: hamlize [OPTIONS]
|
39
|
+
|
40
|
+
Description:
|
41
|
+
Converts a directory of HAML files.
|
42
|
+
|
43
|
+
Options:
|
44
|
+
END
|
45
|
+
|
46
|
+
opts.on("-a", "--auto", "Automatically convert file when they change.") do
|
47
|
+
@options[:auto] = true
|
48
|
+
end
|
49
|
+
|
50
|
+
opts.on("-s", "--source DIRECTORY", "Source directory of HAML files") do |dir|
|
51
|
+
@options[:source] = File.expand_path(dir)
|
52
|
+
end
|
53
|
+
|
54
|
+
opts.on("-o", "--output DIRECTORY", "Destination of the compiled files") do |dir|
|
55
|
+
@options[:output] = File.expand_path(dir)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Hamlize
|
2
|
+
class Converter
|
3
|
+
def initialize(opts={})
|
4
|
+
@opts = opts
|
5
|
+
end
|
6
|
+
|
7
|
+
def start!
|
8
|
+
Pathname.glob(haml).each do |path|
|
9
|
+
destination(path).open("w+") { |f| f.write convert(path) }
|
10
|
+
puts "[#{Time.now}] #{path} => #{destination(path)}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def convert(path)
|
17
|
+
::Haml::Engine.new(path.read).to_html
|
18
|
+
end
|
19
|
+
|
20
|
+
def destination(path)
|
21
|
+
expand(path).tap { |p| p.dirname.mkpath }
|
22
|
+
end
|
23
|
+
|
24
|
+
def expand(path)
|
25
|
+
path = path.to_s.gsub(/^#{source}/, "").gsub(".haml", ".html")
|
26
|
+
Pathname.new(File.join(output, path))
|
27
|
+
end
|
28
|
+
|
29
|
+
def source
|
30
|
+
@opts[:source]
|
31
|
+
end
|
32
|
+
|
33
|
+
def output
|
34
|
+
@opts[:output]
|
35
|
+
end
|
36
|
+
|
37
|
+
def haml
|
38
|
+
"#{source}/**/*.haml"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "rbconfig"
|
2
|
+
require "guard/guard"
|
3
|
+
|
4
|
+
case RbConfig::CONFIG["host_os"]
|
5
|
+
when /darwin/ then require "rb-fsevent"
|
6
|
+
when /linux/ then require "rb-inotify"
|
7
|
+
when /mswin|mingw/ then require "rb-fchange"
|
8
|
+
end
|
9
|
+
|
10
|
+
class Guard::Hamlize < Guard::Guard
|
11
|
+
def run_on_change(paths)
|
12
|
+
Hamlize::Converter.new(options).start!
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Hamlize" do
|
4
|
+
let(:source) { File.dirname(__FILE__) + "/sandbox/source" }
|
5
|
+
let(:dest) { File.dirname(__FILE__) + "/sandbox/source/compiled" }
|
6
|
+
let(:files) { File.dirname(__FILE__) + "/sandbox/files" }
|
7
|
+
let(:site) { File.dirname(__FILE__) + "/sandbox/source/site" }
|
8
|
+
let(:sand) { File.dirname(__FILE__) + "/sandbox/sand" }
|
9
|
+
|
10
|
+
after(:all) do
|
11
|
+
Pathname.new(dest).rmtree rescue nil
|
12
|
+
Pathname.new(site).rmtree rescue nil
|
13
|
+
Pathname.new(sand).rmtree rescue nil
|
14
|
+
end
|
15
|
+
|
16
|
+
before do
|
17
|
+
Dir.stub(:pwd).and_return(source)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "compiles a directory of HAML" do
|
21
|
+
Hamlize::CLI.new.start!
|
22
|
+
output_matches(dest).should be_true
|
23
|
+
end
|
24
|
+
|
25
|
+
it "supports specifying a destination" do
|
26
|
+
Hamlize::CLI.new(["-o", site]).start!
|
27
|
+
output_matches(site).should be_true
|
28
|
+
end
|
29
|
+
|
30
|
+
it "supports a destination that is above the source" do
|
31
|
+
# File.expand_path is in C, so we can't stub where it gets `pwd` from.
|
32
|
+
converter = Hamlize::Converter.new(source: source, output: sand)
|
33
|
+
Hamlize::Converter.stub(:new).and_return(converter)
|
34
|
+
Hamlize::CLI.new(["-o", "../sand"]).start!
|
35
|
+
output_matches(sand).should be_true
|
36
|
+
end
|
37
|
+
|
38
|
+
it "supports specifying a source directory" do
|
39
|
+
Hamlize::CLI.new(["-s", files]).start!
|
40
|
+
output_matches(dest).should be_true
|
41
|
+
end
|
42
|
+
|
43
|
+
def output_matches(dest)
|
44
|
+
files = Pathname.glob("#{dest}/**/*.html").map(&:to_s)
|
45
|
+
files == ["#{dest}/index.html", "#{dest}/pages/toc.html"]
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hamlize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matte Noble
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-24 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70122351706000 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.7.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70122351706000
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: haml
|
27
|
+
requirement: &70122351705160 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70122351705160
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: guard-haml
|
38
|
+
requirement: &70122351704140 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70122351704140
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rb-fsevent
|
49
|
+
requirement: &70122351703360 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70122351703360
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rb-inotify
|
60
|
+
requirement: &70122351690540 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70122351690540
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rb-fchange
|
71
|
+
requirement: &70122351689460 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70122351689460
|
80
|
+
description: Convert a directory of HAML into HTML.
|
81
|
+
email:
|
82
|
+
- me@mattenoble.com
|
83
|
+
executables:
|
84
|
+
- hamlize
|
85
|
+
extensions: []
|
86
|
+
extra_rdoc_files: []
|
87
|
+
files:
|
88
|
+
- .gitignore
|
89
|
+
- Gemfile
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- bin/hamlize
|
93
|
+
- hamlize.gemspec
|
94
|
+
- lib/hamlize.rb
|
95
|
+
- lib/hamlize/cli.rb
|
96
|
+
- lib/hamlize/converter.rb
|
97
|
+
- lib/hamlize/guard.rb
|
98
|
+
- lib/hamlize/version.rb
|
99
|
+
- spec/hamlize_spec.rb
|
100
|
+
- spec/sandbox/files/index.haml
|
101
|
+
- spec/sandbox/files/pages/toc.haml
|
102
|
+
- spec/sandbox/source/index.haml
|
103
|
+
- spec/sandbox/source/pages/toc.haml
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
homepage: ''
|
106
|
+
licenses: []
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 1.8.10
|
126
|
+
signing_key:
|
127
|
+
specification_version: 3
|
128
|
+
summary: Convert a directory of HAML into HTML.
|
129
|
+
test_files:
|
130
|
+
- spec/hamlize_spec.rb
|
131
|
+
- spec/sandbox/files/index.haml
|
132
|
+
- spec/sandbox/files/pages/toc.haml
|
133
|
+
- spec/sandbox/source/index.haml
|
134
|
+
- spec/sandbox/source/pages/toc.haml
|
135
|
+
- spec/spec_helper.rb
|