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 +1 -1
- data/lib/middleman.rb +3 -0
- data/lib/middleman/helpers.rb +49 -37
- data/middleman.gemspec +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
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
|
data/lib/middleman/helpers.rb
CHANGED
@@ -1,41 +1,53 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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