midwife 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +8 -1
- data/lib/midwife/tasks.rb +51 -58
- data/lib/midwife/version.rb +1 -1
- data/midwife.gemspec +1 -0
- metadata +19 -3
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
midwife (0.0.
|
4
|
+
midwife (0.0.7)
|
5
5
|
haml (= 3.1.7)
|
6
6
|
listen (= 0.5.3)
|
7
7
|
rack (= 1.4.1)
|
@@ -9,18 +9,25 @@ PATH
|
|
9
9
|
rake (= 0.9.2.2)
|
10
10
|
rb-fsevent (~> 0.9.1)
|
11
11
|
sass (= 3.2.1)
|
12
|
+
uglifier (= 1.3.0)
|
12
13
|
|
13
14
|
GEM
|
14
15
|
remote: https://rubygems.org/
|
15
16
|
specs:
|
17
|
+
execjs (1.4.0)
|
18
|
+
multi_json (~> 1.0)
|
16
19
|
haml (3.1.7)
|
17
20
|
listen (0.5.3)
|
21
|
+
multi_json (1.3.6)
|
18
22
|
rack (1.4.1)
|
19
23
|
rack-contrib (1.1.0)
|
20
24
|
rack (>= 0.9.1)
|
21
25
|
rake (0.9.2.2)
|
22
26
|
rb-fsevent (0.9.2)
|
23
27
|
sass (3.2.1)
|
28
|
+
uglifier (1.3.0)
|
29
|
+
execjs (>= 0.3.0)
|
30
|
+
multi_json (~> 1.0, >= 1.0.2)
|
24
31
|
|
25
32
|
PLATFORMS
|
26
33
|
ruby
|
data/lib/midwife/tasks.rb
CHANGED
@@ -1,61 +1,56 @@
|
|
1
1
|
require 'haml'
|
2
2
|
require 'listen'
|
3
3
|
require 'sass'
|
4
|
+
require 'uglifier'
|
4
5
|
|
5
6
|
module Midwife
|
6
7
|
class Tasks
|
7
|
-
HAML = FileList['**/*.haml']
|
8
|
-
HTML = HAML.ext('html')
|
9
|
-
SCSS = FileList['**/*.scss']
|
10
|
-
CSS = SCSS.ext('css')
|
11
|
-
|
12
8
|
ASSETS = 'assets'
|
13
9
|
PUBLIC = 'public'
|
14
10
|
CONFIG = "config.ru"
|
15
11
|
GEMFILE = "Gemfile"
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
task :setup do
|
21
|
-
setup
|
22
|
-
end
|
13
|
+
HAML = FileList[ASSETS + '/**/*.haml']
|
14
|
+
SCSS = FileList[ASSETS + '/**/*.scss']
|
15
|
+
JS = FileList[ASSETS + '/**/*.js']
|
23
16
|
|
24
|
-
|
25
|
-
|
17
|
+
EXT_SYNTAX = {
|
18
|
+
'.haml' => { :ext => 'html', :syntax => :haml },
|
19
|
+
'.scss' => { :ext => 'css', :syntax => :scss },
|
20
|
+
'.js' => { :ext => 'js', :syntax => :js }
|
21
|
+
}
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
class << self
|
24
|
+
def build
|
25
|
+
desc 'Care for your haml/scss/js'
|
26
|
+
task(:care) { care }
|
31
27
|
|
32
|
-
desc '
|
33
|
-
task
|
34
|
-
serve
|
35
|
-
end
|
28
|
+
desc 'Listen to your haml/scss/js'
|
29
|
+
task(:listen) { listen }
|
36
30
|
|
37
|
-
|
38
|
-
|
39
|
-
end
|
31
|
+
desc 'Setup your environment'
|
32
|
+
task(:setup) { setup }
|
40
33
|
|
41
|
-
|
42
|
-
|
43
|
-
end
|
34
|
+
desc 'Serve your haml/scss/js'
|
35
|
+
task(:serve) { serve }
|
44
36
|
end
|
45
37
|
|
46
|
-
def render(
|
38
|
+
def render(source)
|
47
39
|
return if source.split("/").last.match(/^\_/)
|
48
40
|
|
49
|
-
|
50
|
-
|
41
|
+
extension = File.extname(source)
|
42
|
+
ext_syntax = EXT_SYNTAX[extension]
|
43
|
+
syntax = ext_syntax[:syntax]
|
44
|
+
destination = source.ext(ext_syntax[:ext]).gsub(ASSETS, PUBLIC)
|
51
45
|
FileUtils.mkdir_p(File.dirname(destination))
|
52
|
-
template = File.read(source)
|
53
46
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
47
|
+
helpers = Helpers.new(File.dirname(source))
|
48
|
+
template = File.read(source)
|
49
|
+
output = case syntax
|
50
|
+
when :haml; Haml::Engine.new(template, {:format => :html5, :ugly => true}).render(helpers)
|
51
|
+
when :scss; Sass::Engine.new(template, {:syntax => syntax, :style => :compressed}).render
|
52
|
+
when :js; Uglifier.compile(template)
|
53
|
+
end
|
59
54
|
|
60
55
|
File.open(destination, 'w') do |file|
|
61
56
|
file.write(output)
|
@@ -68,14 +63,10 @@ module Midwife
|
|
68
63
|
puts e.backtrace.first
|
69
64
|
end
|
70
65
|
|
71
|
-
def
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
current_dir = File.expand_path(File.dirname(__FILE__))
|
76
|
-
|
77
|
-
FileUtils.cp("#{current_dir}/templates/#{CONFIG}", CONFIG) unless File.exists?(CONFIG)
|
78
|
-
FileUtils.cp("#{current_dir}/templates/#{GEMFILE}", GEMFILE) unless File.exists?(GEMFILE)
|
66
|
+
def care
|
67
|
+
(HAML + SCSS + JS).each do |source|
|
68
|
+
render(source)
|
69
|
+
end
|
79
70
|
end
|
80
71
|
|
81
72
|
def listen
|
@@ -83,29 +74,31 @@ module Midwife
|
|
83
74
|
|
84
75
|
Listen.to(ASSETS) do |modified, added, removed|
|
85
76
|
(modified + added).each do |source|
|
86
|
-
|
87
|
-
|
88
|
-
if extension == '.haml'
|
89
|
-
target = source.ext('html')
|
90
|
-
render(:haml, source, target)
|
91
|
-
elsif extension == '.scss'
|
92
|
-
target = source.ext('css')
|
93
|
-
render(:scss, source, target)
|
94
|
-
end
|
77
|
+
render(source)
|
95
78
|
end
|
96
79
|
|
97
80
|
removed.each do |source|
|
98
81
|
extension = File.extname(source)
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
82
|
+
destination = case extension
|
83
|
+
when '.haml'; source.gsub(ASSETS, PUBLIC).ext('html')
|
84
|
+
when '.scss'; source.gsub(ASSETS, PUBLIC).ext('css')
|
85
|
+
when '.js'; source.gsub(ASSETS, PUBLIC)
|
86
|
+
end
|
104
87
|
File.delete(destination)
|
105
88
|
end
|
106
89
|
end
|
107
90
|
end
|
108
91
|
|
92
|
+
def setup
|
93
|
+
FileUtils.mkdir_p(ASSETS) unless File.exists?(ASSETS)
|
94
|
+
FileUtils.mkdir_p(PUBLIC) unless File.exists?(PUBLIC)
|
95
|
+
|
96
|
+
current_dir = File.expand_path(File.dirname(__FILE__))
|
97
|
+
|
98
|
+
FileUtils.cp("#{current_dir}/templates/#{CONFIG}", CONFIG) unless File.exists?(CONFIG)
|
99
|
+
FileUtils.cp("#{current_dir}/templates/#{GEMFILE}", GEMFILE) unless File.exists?(GEMFILE)
|
100
|
+
end
|
101
|
+
|
109
102
|
def serve
|
110
103
|
fork { listen }
|
111
104
|
`rackup`
|
data/lib/midwife/version.rb
CHANGED
data/midwife.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: midwife
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -123,6 +123,22 @@ dependencies:
|
|
123
123
|
- - '='
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: 1.1.0
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: uglifier
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - '='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 1.3.0
|
134
|
+
type: :runtime
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - '='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: 1.3.0
|
126
142
|
description: ''
|
127
143
|
email:
|
128
144
|
- lihsuan@8thlight.com
|
@@ -156,7 +172,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
156
172
|
version: '0'
|
157
173
|
segments:
|
158
174
|
- 0
|
159
|
-
hash:
|
175
|
+
hash: -4454890038817568293
|
160
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
177
|
none: false
|
162
178
|
requirements:
|
@@ -165,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
181
|
version: '0'
|
166
182
|
segments:
|
167
183
|
- 0
|
168
|
-
hash:
|
184
|
+
hash: -4454890038817568293
|
169
185
|
requirements: []
|
170
186
|
rubyforge_project:
|
171
187
|
rubygems_version: 1.8.24
|