middleman 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.3.3
data/lib/middleman.rb CHANGED
@@ -55,6 +55,9 @@ class Middleman < Sinatra::Base
55
55
  end
56
56
  end
57
57
 
58
+ # include helpers
59
+ class_eval File.read(File.join(File.dirname(__FILE__), 'middleman', 'helpers.rb'))
60
+
58
61
  # Check for local config
59
62
  local_config = File.join(self.root, "init.rb")
60
63
  if File.exists? local_config
@@ -1,41 +1,53 @@
1
- Middleman.helpers do
2
- def link_to(title, url="#", params={})
3
- params.merge!(:href => url)
4
- params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ')
5
- %Q{<a #{params}>#{title}</a>}
6
- end
7
-
8
- def page_classes(*additional)
9
- classes = []
10
- parts = @full_request_path.split('.')[0].split('/')
11
- parts.each_with_index { |path, i| classes << parts.first(i+1).join('_') }
12
-
13
- classes << "index" if classes.empty?
14
- classes += additional unless additional.empty?
15
- classes.join(' ')
16
- end
17
-
18
- def asset_url(path)
19
- path.include?("://") ? path : "/#{path}"
20
- end
21
-
22
- def image_tag(path, options={})
23
- options[:alt] ||= ""
24
- capture_haml do
25
- haml_tag :img, options.merge(:src => asset_url(path))
26
- end
1
+ def link_to(title, url="#", params={})
2
+ params.merge!(:href => url)
3
+ params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ')
4
+ %Q{<a #{params}>#{title}</a>}
5
+ end
6
+
7
+ def page_classes(*additional)
8
+ classes = []
9
+ parts = @full_request_path.split('.')[0].split('/')
10
+ parts.each_with_index { |path, i| classes << parts.first(i+1).join('_') }
11
+
12
+ classes << "index" if classes.empty?
13
+ classes += additional unless additional.empty?
14
+ classes.join(' ')
15
+ end
16
+
17
+ def haml_partial(name, options = {})
18
+ item_name = name.to_sym
19
+ counter_name = "#{name}_counter".to_sym
20
+ if collection = options.delete(:collection)
21
+ collection.enum_for(:each_with_index).collect do |item,index|
22
+ haml_partial name, options.merge(:locals => {item_name => item, counter_name => index+1})
23
+ end.join
24
+ elsif object = options.delete(:object)
25
+ haml_partial name, options.merge(:locals => {item_name => object, counter_name => nil})
26
+ else
27
+ haml "_#{name}".to_sym, options.merge(:layout => false)
27
28
  end
28
-
29
- def javascript_include_tag(path, options={})
30
- capture_haml do
31
- haml_tag :script, options.merge(:src => asset_url(path), :type => "text/javascript")
32
- end
29
+ end
30
+
31
+ def asset_url(path)
32
+ path.include?("://") ? path : "/#{path}"
33
+ end
34
+
35
+ def image_tag(path, options={})
36
+ options[:alt] ||= ""
37
+ capture_haml do
38
+ haml_tag :img, options.merge(:src => asset_url(path))
33
39
  end
34
-
35
- def stylesheet_link_tag(path, options={})
36
- options[:rel] ||= "stylesheet"
37
- capture_haml do
38
- haml_tag :link, options.merge(:href => asset_url(path), :type => "text/css")
39
- end
40
+ end
41
+
42
+ def javascript_include_tag(path, options={})
43
+ capture_haml do
44
+ haml_tag :script, options.merge(:src => asset_url(path), :type => "text/javascript")
40
45
  end
41
46
  end
47
+
48
+ def stylesheet_link_tag(path, options={})
49
+ options[:rel] ||= "stylesheet"
50
+ capture_haml do
51
+ haml_tag :link, options.merge(:href => asset_url(path), :type => "text/css")
52
+ end
53
+ end
data/middleman.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{middleman}
5
- s.version = "0.3.2"
5
+ s.version = "0.3.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Thomas Reynolds"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Reynolds