midwife 0.0.7 → 0.0.8

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.
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- midwife (0.0.7)
4
+ midwife (0.0.8)
5
+ chunky_png (= 1.2.6)
5
6
  haml (= 3.1.7)
6
7
  listen (= 0.5.3)
7
8
  rack (= 1.4.1)
@@ -14,6 +15,7 @@ PATH
14
15
  GEM
15
16
  remote: https://rubygems.org/
16
17
  specs:
18
+ chunky_png (1.2.6)
17
19
  execjs (1.4.0)
18
20
  multi_json (~> 1.0)
19
21
  haml (3.1.7)
data/README.md CHANGED
@@ -19,14 +19,20 @@ The rest:
19
19
 
20
20
  ## Usage
21
21
 
22
- rake care # Care for your haml/scss
23
- rake listen # Listen to your haml/scss
24
- rake serve # Serve your haml/scss
22
+ rake care # Care for your haml/scss/js
23
+ rake listen # Listen to your haml/scss/js
24
+ rake serve # Serve your haml/scss/js
25
25
  rake setup # Setup your environment
26
26
 
27
27
  ---
28
28
 
29
- Make an `assets` folder, and drop your haml and scss files in there. Running `rake care` will compile haml and scss files once and drop the artifacts into the `public` fodler. Run `rake listen` will compile each time you touch the files. Run `rake serve` to start a web server running on [localhost:9292](http://localhost:9292).
29
+ Make an `assets` folder, and drop your haml, scss and js files in there. Running `rake care` will process haml, scss and js files once, and drop the artifacts into the `public` fodler. Run `rake listen` will process each time you touch the files. Run `rake serve` to start a web server running on [localhost:9292](http://localhost:9292) that listens to every change you make.
30
+
31
+ ## Helpers
32
+
33
+ ```haml
34
+ = render "partial" # file name must be prefixed with an underscore, ie. _partial.haml.
35
+ ```
30
36
 
31
37
  ## Deploy to Heroku
32
38
 
@@ -8,7 +8,6 @@ module Midwife
8
8
  partial_file = "#{@current}/_#{partial}.haml"
9
9
  template = File.read(partial_file)
10
10
  output = Haml::Engine.new(template).render(Helpers.new(@current))
11
- puts "haml: convert #{partial_file}."
12
11
  return output
13
12
  rescue Exception => e
14
13
  puts "haml: failed to convert #{partial_file}."
@@ -2,6 +2,8 @@ require 'haml'
2
2
  require 'listen'
3
3
  require 'sass'
4
4
  require 'uglifier'
5
+ require 'chunky_png'
6
+ require 'ostruct'
5
7
 
6
8
  module Midwife
7
9
  class Tasks
@@ -13,6 +15,7 @@ module Midwife
13
15
  HAML = FileList[ASSETS + '/**/*.haml']
14
16
  SCSS = FileList[ASSETS + '/**/*.scss']
15
17
  JS = FileList[ASSETS + '/**/*.js']
18
+ PNG = FileList[ASSETS + '/**/*.png']
16
19
 
17
20
  EXT_SYNTAX = {
18
21
  '.haml' => { :ext => 'html', :syntax => :haml },
@@ -22,17 +25,20 @@ module Midwife
22
25
 
23
26
  class << self
24
27
  def build
25
- desc 'Care for your haml/scss/js'
28
+ desc 'Care for your haml, scss, and js'
26
29
  task(:care) { care }
27
30
 
28
- desc 'Listen to your haml/scss/js'
31
+ desc 'Listen to your haml, scss, and js'
29
32
  task(:listen) { listen }
30
33
 
31
34
  desc 'Setup your environment'
32
35
  task(:setup) { setup }
33
36
 
34
- desc 'Serve your haml/scss/js'
37
+ desc 'Serve your haml, scss and js'
35
38
  task(:serve) { serve }
39
+
40
+ desc 'Stitch your png'
41
+ task(:stitch) { stitch }
36
42
  end
37
43
 
38
44
  def render(source)
@@ -42,13 +48,14 @@ module Midwife
42
48
  ext_syntax = EXT_SYNTAX[extension]
43
49
  syntax = ext_syntax[:syntax]
44
50
  destination = source.ext(ext_syntax[:ext]).gsub(ASSETS, PUBLIC)
51
+ source_dir = File.dirname(source)
45
52
  FileUtils.mkdir_p(File.dirname(destination))
46
53
 
47
- helpers = Helpers.new(File.dirname(source))
54
+ helpers = Helpers.new(source_dir)
48
55
  template = File.read(source)
49
56
  output = case syntax
50
57
  when :haml; Haml::Engine.new(template, {:format => :html5, :ugly => true}).render(helpers)
51
- when :scss; Sass::Engine.new(template, {:syntax => syntax, :style => :compressed}).render
58
+ when :scss; Sass::Engine.new(template, {:syntax => syntax, :style => :compressed, :load_paths => [source_dir]}).render
52
59
  when :js; Uglifier.compile(template)
53
60
  end
54
61
 
@@ -92,6 +99,10 @@ module Midwife
92
99
  def setup
93
100
  FileUtils.mkdir_p(ASSETS) unless File.exists?(ASSETS)
94
101
  FileUtils.mkdir_p(PUBLIC) unless File.exists?(PUBLIC)
102
+ FileUtils.mkdir_p(ASSETS + '/images') unless File.exists?(ASSETS + '/images')
103
+ FileUtils.mkdir_p(ASSETS + '/stylesheets') unless File.exists?(ASSETS + '/stylesheets')
104
+ FileUtils.mkdir_p(PUBLIC + '/images') unless File.exists?(PUBLIC + '/images')
105
+ FileUtils.mkdir_p(PUBLIC + '/stylesheets') unless File.exists?(PUBLIC + '/images')
95
106
 
96
107
  current_dir = File.expand_path(File.dirname(__FILE__))
97
108
 
@@ -103,6 +114,41 @@ module Midwife
103
114
  fork { listen }
104
115
  `rackup`
105
116
  end
117
+
118
+ def stitch
119
+ offset_height = 0
120
+
121
+ sprites = PNG.collect do |file|
122
+ image = ChunkyPNG::Image.from_file(file)
123
+ sprite = OpenStruct.new
124
+ sprite.name = File.basename(file, '.png')
125
+ sprite.image = image
126
+ sprite.min_width = 0
127
+ sprite.max_width = image.width
128
+ sprite.min_height = offset_height
129
+ sprite.max_height = offset_height + image.height
130
+ offset_height = sprite.max_height
131
+ sprite
132
+ end
133
+
134
+ max_width = sprites.collect(&:max_width).max
135
+ max_height = sprites.last.max_height
136
+ target = ChunkyPNG::Image.new(max_width, max_height, ChunkyPNG::Color::TRANSPARENT)
137
+
138
+ css = ''
139
+ sprites.each do |sprite|
140
+ css = css + '.' + sprite.name + "-image { background:url(../images/application.png) 0 #{-1 * sprite.min_height}px; }\n"
141
+ target.compose!(sprite.image, 0, sprite.min_height)
142
+ puts "png: stitch #{sprite.name} to application.png"
143
+ end
144
+
145
+ File.open(ASSETS + '/stylesheets/_sprites.scss', 'w') do |file|
146
+ puts "scss: create assets/stylesheets/_sprites.scss"
147
+ file.write(css)
148
+ end
149
+
150
+ target.save(PUBLIC + '/images/application.png')
151
+ end
106
152
  end
107
153
  end
108
154
  end
@@ -1,3 +1,3 @@
1
1
  module Midwife
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_dependency "rack", "1.4.1"
20
20
  s.add_dependency "rack-contrib", "1.1.0"
21
21
  s.add_dependency "uglifier", "1.3.0"
22
+ s.add_dependency "chunky_png", "1.2.6"
22
23
 
23
24
  s.files = `git ls-files`.split("\n")
24
25
  s.require_paths = ["lib"]
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.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-14 00:00:00.000000000 Z
12
+ date: 2012-10-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -139,6 +139,22 @@ dependencies:
139
139
  - - '='
140
140
  - !ruby/object:Gem::Version
141
141
  version: 1.3.0
142
+ - !ruby/object:Gem::Dependency
143
+ name: chunky_png
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - '='
148
+ - !ruby/object:Gem::Version
149
+ version: 1.2.6
150
+ type: :runtime
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - '='
156
+ - !ruby/object:Gem::Version
157
+ version: 1.2.6
142
158
  description: ''
143
159
  email:
144
160
  - lihsuan@8thlight.com
@@ -172,7 +188,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
172
188
  version: '0'
173
189
  segments:
174
190
  - 0
175
- hash: -4454890038817568293
191
+ hash: 2694047856860377402
176
192
  required_rubygems_version: !ruby/object:Gem::Requirement
177
193
  none: false
178
194
  requirements:
@@ -181,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
197
  version: '0'
182
198
  segments:
183
199
  - 0
184
- hash: -4454890038817568293
200
+ hash: 2694047856860377402
185
201
  requirements: []
186
202
  rubyforge_project:
187
203
  rubygems_version: 1.8.24