buho 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in buho.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Diego Saint Esteben
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.
@@ -0,0 +1,34 @@
1
+ # Buho
2
+
3
+ HAML Watcher like SASS and CoffeScript
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'buho'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install buho
18
+
19
+ ## Usage
20
+
21
+ buho [options]
22
+
23
+ -i, --input Set input directory. <required>
24
+ -o, --output Set output directory.
25
+ If omit this option, input path has been used instead
26
+ -h, --help Show help info.
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'buho/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'buho'
8
+ gem.version = Buho::VERSION
9
+ gem.author = 'Diego Saint Esteben'
10
+ gem.email = 'diego@saintesteben.me'
11
+ gem.description = %q{HAML Watcher like SASS or CoffeeScript}
12
+ gem.summary = %q{HAML Watcher like SASS or CoffeeScript}
13
+ gem.homepage = 'http://github.com/dii3g0/Buho'
14
+
15
+ gem.files = Dir['lib/*.rb'] + Dir['lib/*/*.rb']
16
+ gem.files += `git ls-files`.split($/)
17
+ gem.executables = ['buho']
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ['lib']
20
+
21
+ gem.add_dependency "haml"
22
+ gem.add_dependency "wdm"
23
+ gem.add_dependency "listen"
24
+ end
25
+
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "buho/version"
4
+
5
+ require 'rubygems'
6
+ require 'optparse'
7
+ require 'listen'
8
+ require 'haml'
9
+
10
+ ##
11
+ # Buho module
12
+ #
13
+ module Buho
14
+
15
+ ##
16
+ # Watcher class
17
+ #
18
+ class Watcher
19
+
20
+ ##
21
+ # Watch changes, compile and save it
22
+ #
23
+ def watch
24
+
25
+ # Input dir
26
+ @input = nil
27
+
28
+ # Output dir
29
+ @output = nil
30
+
31
+ # Compiled HTML
32
+ @compiled = nil
33
+
34
+ # Gem name
35
+ puts "\n","-" * 41
36
+ puts " Buho #{Buho::VERSION}"
37
+ puts " Copyright (c) 2013 Diego Saint Esteben"
38
+ puts "-" * 41, "\n"
39
+
40
+ # Options
41
+ self.opts
42
+
43
+ # Print input/output paths
44
+ puts "Input dir: #{@input}"
45
+ puts "Output dir: #{@output}"
46
+
47
+ # Ready to watch..
48
+ puts "\nReady to watch...\n\n"
49
+
50
+ # Listen
51
+ Listen.to(@input, :filter => /\.haml$/, :relative_paths => true) do |modified, added, removed|
52
+
53
+ # Walk into modified files
54
+ modified.each do |path|
55
+
56
+ # Paths
57
+ input = File.join(@input, path)
58
+ output = File.join(@output, path).gsub!('.haml', '.html')
59
+
60
+ # Watching message
61
+ puts ">> Watching #{input}"
62
+
63
+ # Compile HAML file and save in @compiled
64
+ self.compile input
65
+
66
+ # Write HTML into output path
67
+ self.write output
68
+
69
+ # Compilation successfully
70
+ puts ">> Compiling #{input} into #{output}"
71
+ end
72
+ end
73
+ end
74
+
75
+ ##
76
+ # Configure CLI options
77
+ #
78
+ def opts
79
+
80
+ # Handle CLI options
81
+ OptionParser.new do |opts|
82
+
83
+ # Set separator
84
+ opts.separator nil
85
+
86
+ # Option to set input directory or raise a exception if not exists
87
+ opts.on('-i', '--input [dir]', String, 'Set input directory.', 'If omit this option, input path has been used instead') do |i|
88
+ begin
89
+ @input = File.join('.', i)
90
+ raise IOError unless File.exists? @input
91
+ rescue IOError
92
+ puts ">> Error: Input directory not found\n\n"
93
+ exit
94
+ end
95
+ end
96
+
97
+ # Option to set output directory or raise a exception if not exists
98
+ opts.on('-o', '--output [dir]', String, 'Set output directory.') do |o|
99
+ @output = File.join('.', o)
100
+ end
101
+
102
+ # Show help info
103
+ opts.on('-h', '--help', 'Show help info.') do
104
+ puts opts;
105
+ exit
106
+ end
107
+
108
+ # Parse!
109
+ opts.parse!
110
+ end
111
+
112
+ begin
113
+ raise OptionParser::MissingArgument if @input == nil
114
+ rescue OptionParser::MissingArgument
115
+ puts ">> Error: Missing argument --input\n\n"
116
+ exit
117
+ end
118
+
119
+ # If output dir has not been defined, use input dir instead
120
+ @output ||= @input
121
+ end
122
+
123
+ ##
124
+ # Compile HAML
125
+ #
126
+ def compile(path)
127
+ begin
128
+ # Read HAML and compile it
129
+ haml = File.open(path).read
130
+ @compiled = Haml::Engine.new(haml).render
131
+ rescue Haml::Error => e
132
+ #Error compiling message
133
+ puts ">> Error: \"#{e.message}\" at line #{e.line}"
134
+ end
135
+ end
136
+
137
+ ##
138
+ # Write compiled HTML into HTML file
139
+ #
140
+ def write(path)
141
+
142
+ # Create directory tree
143
+ dirname = File.dirname(path)
144
+ FileUtils.mkdir_p(dirname)
145
+
146
+ # Save compiled HTML into file
147
+ File.open(path, 'w') do |f|
148
+ f << @compiled
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,3 @@
1
+ module Buho
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,13 @@
1
+ !!! 5
2
+ %html
3
+ %head
4
+ %title
5
+ %body
6
+ %header
7
+ %h1
8
+ %nav
9
+ %ul
10
+ %li
11
+ %a
12
+ %section
13
+ %footer
@@ -0,0 +1,20 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title></title>
5
+ </head>
6
+ <body>
7
+ <header>
8
+ <h1></h1>
9
+ <nav>
10
+ <ul>
11
+ <li>
12
+ <a></a>
13
+ </li>
14
+ </ul>
15
+ </nav>
16
+ </header>
17
+ <section></section>
18
+ <footer></footer>
19
+ </body>
20
+ </html>
metadata CHANGED
@@ -1,12 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buho
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Diego Saint Esteben
9
- - Spardr
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
@@ -61,16 +60,24 @@ dependencies:
61
60
  - !ruby/object:Gem::Version
62
61
  version: '0'
63
62
  description: HAML Watcher like SASS or CoffeeScript
64
- email:
65
- - diego@spardr.com
66
- - hello@spardr.com
63
+ email: diego@saintesteben.me
67
64
  executables:
68
65
  - buho
69
66
  extensions: []
70
67
  extra_rdoc_files: []
71
68
  files:
69
+ - lib/buho.rb
70
+ - lib/buho/version.rb
71
+ - .gitignore
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
72
76
  - bin/buho
73
- homepage: http://spardr.com/
77
+ - buho.gemspec
78
+ - test/haml/index.haml
79
+ - test/html/index.html
80
+ homepage: http://github.com/dii3g0/Buho
74
81
  licenses: []
75
82
  post_install_message:
76
83
  rdoc_options: []
@@ -94,4 +101,6 @@ rubygems_version: 1.8.24
94
101
  signing_key:
95
102
  specification_version: 3
96
103
  summary: HAML Watcher like SASS or CoffeeScript
97
- test_files: []
104
+ test_files:
105
+ - test/haml/index.haml
106
+ - test/html/index.html