merb_viewfu 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/lib/view_fu/tag_helper.rb +53 -19
  3. metadata +2 -2
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'merb-core'
5
5
  require 'merb-core/tasks/merb'
6
6
 
7
7
  GEM_NAME = "merb_viewfu"
8
- GEM_VERSION = "0.3.2"
8
+ GEM_VERSION = "0.3.3"
9
9
  AUTHOR = "Jacques Crocker"
10
10
  EMAIL = "merbjedi@gmail.com"
11
11
  HOMEPAGE = "http://merbjedi.com/"
@@ -114,42 +114,76 @@ module ViewFu
114
114
  def lorem
115
115
  "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
116
116
  end
117
-
118
- # Return a hidden attribute hash (useful in Haml tags - %div{hidden})
119
- def hidden
120
- {:style => "display:none"}
121
- end
122
117
 
123
- def add_class_if(css_class, condition)
124
- if condition
118
+ # provides a slick way to add classes inside haml attribute collections
119
+ #
120
+ # examples:
121
+ # %div{add_class("current")}
122
+ # #=> adds the "current" class to the div
123
+ #
124
+ # %div{add_class("current", :if => current?)}
125
+ # #=> adds the "current" class to the div if current? method
126
+ #
127
+ # %div{add_class("highlight", :unless => logged_in?)}
128
+ # #=> adds the "highlight" class to the div unless logged_in? method returns true
129
+ def add_class(css_class, options = {})
130
+ return {} unless css_class
131
+
132
+ unless options[:unless].nil?
133
+ if options[:unless]
134
+ return {}
135
+ end
136
+ end
137
+
138
+ unless options[:if].nil?
139
+ if options[:if]
140
+ return {:class => css_class}
141
+ end
142
+ end
143
+
144
+ if options[:if].nil? and options[:unless].nil?
125
145
  {:class => css_class}
126
146
  else
127
147
  {}
128
148
  end
129
149
  end
150
+
151
+ def add_class_if(css_class, condition)
152
+ add_class(css_class, :if => condition)
153
+ end
130
154
 
131
155
  def add_class_unless(css_class, condition)
132
- add_class_if(css_class, !condition)
156
+ add_class(css_class, :unless => condition)
133
157
  end
134
158
 
159
+ # Return a hidden attribute hash (useful in Haml tags - %div{hidden})
160
+ def hide(options = {})
161
+ unless options[:unless].nil?
162
+ if options[:unless]
163
+ return {}
164
+ end
165
+ end
166
+
167
+ unless options[:if].nil?
168
+ unless options[:if]
169
+ return {}
170
+ end
171
+ end
172
+
173
+ {:style => "display:none"}
174
+ end
175
+ alias :hidden :hide
176
+
135
177
  # Return a hidden attribute hash if a condition evaluates to true
136
178
  def hide_if(condition)
137
- if condition
138
- hidden
139
- else
140
- {}
141
- end
179
+ hide(:if => condition)
142
180
  end
143
181
  alias :hidden_if :hide_if
144
182
  alias :show_unless :hide_if
145
183
 
146
184
  # Return a hidden attribute hash if a condition evaluates to false
147
185
  def hide_unless(condition)
148
- if !condition
149
- hidden
150
- else
151
- {}
152
- end
186
+ hide(:unless => condition)
153
187
  end
154
188
  alias :hidden_unless :hide_unless
155
189
  alias :show_if :hide_unless
@@ -169,7 +203,7 @@ module ViewFu
169
203
 
170
204
  # Check if we're on production environment
171
205
  def production?
172
- Merb.env == "production"
206
+ Merb.env?(:production)
173
207
  end
174
208
 
175
209
  # Display will_paginate paging links
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merb_viewfu
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
  - Jacques Crocker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-17 00:00:00 -08:00
12
+ date: 2009-03-19 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency