Module: Schnitzelpress::Helpers
- Defined in:
- lib/schnitzelpress/helpers.rb
Instance Method Summary collapse
- #admin_logged_in? ⇒ Boolean
- #admin_only! ⇒ Object
- #base_url ⇒ Object
- #config ⇒ Object
- #find_template(views, name, engine, &block) ⇒ Object
- #form_field(object, attribute, options = {}) ⇒ Object
- #h(*args) ⇒ Object
- #icon(name) ⇒ Object
- #link_to(title, target = "", options = {}) ⇒ Object
- #link_to_delete_post(title, post) ⇒ Object
- #partial(thing, locals = {}) ⇒ Object
- #production? ⇒ Boolean
- #set_page_title(title) ⇒ Object
- #show_disqus? ⇒ Boolean
- #url_for(thing, options = {}) ⇒ Object
- #user_logged_in? ⇒ Boolean
Instance Method Details
#admin_logged_in? ⇒ Boolean
50 51 52 |
# File 'lib/schnitzelpress/helpers.rb', line 50 def admin_logged_in? user_logged_in? && (session[:auth][:uid] == ENV['SCHNITZELPRESS_OWNER']) end |
#admin_only! ⇒ Object
54 55 56 |
# File 'lib/schnitzelpress/helpers.rb', line 54 def admin_only! redirect '/login' unless admin_logged_in? end |
#base_url ⇒ Object
11 12 13 |
# File 'lib/schnitzelpress/helpers.rb', line 11 def base_url "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}/" end |
#config ⇒ Object
24 25 26 |
# File 'lib/schnitzelpress/helpers.rb', line 24 def config Schnitzelpress::Config.instance end |
#find_template(views, name, engine, &block) ⇒ Object
7 8 9 |
# File 'lib/schnitzelpress/helpers.rb', line 7 def find_template(views, name, engine, &block) Array(views).each { |v| super(v, name, engine, &block) } end |
#form_field(object, attribute, options = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/schnitzelpress/helpers.rb', line 58 def form_field(object, attribute, = {}) = { :label => attribute.to_s.humanize.titleize, :value => object.send(attribute), :errors => object.errors[attribute.to_sym], :class_name => object.class.to_s.demodulize.underscore }.merge() [:name] ||= "#{[:class_name]}[#{attribute}]" [:id] ||= object.new_record? ? "new_#{[:class_name]}_#{attribute}" : "#{[:class_name]}_#{object.id}_#{attribute}" [:class] ||= "#{[:class_name]}_#{attribute}" [:type] ||= case [:value] when DateTime, Time, Date then :datetime when Boolean, FalseClass, TrueClass then :boolean else :text end partial 'form_field', :object => object, :attribute => attribute, :options => end |
#h(*args) ⇒ Object
3 4 5 |
# File 'lib/schnitzelpress/helpers.rb', line 3 def h(*args) escape_html(*args) end |
#icon(name) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/schnitzelpress/helpers.rb', line 81 def icon(name) map = { 'glass' => 'f000', 'music' => 'f001', 'search' => 'f002', 'envelope' => 'f003', 'heart' => 'f004', 'star' => 'f005', 'star-empty' => 'f006', 'user' => 'f007', 'film' => 'f008', 'th-large' => 'f009', 'th' => 'f00a', 'th-list' => 'f00b', 'ok' => 'f00c', 'remove' => 'f00d', 'zoom-in' => 'f00e', 'zoom-out' => 'f010', 'off' => 'f011', 'signal' => 'f012', 'cog' => 'f013', 'trash' => 'f014', 'home' => 'f015', 'file' => 'f016', 'time' => 'f017', 'road' => 'f018', 'download-alt' => 'f019', 'download' => 'f01a', 'upload' => 'f01b', 'inbox' => 'f01c', 'play-circle' => 'f01d', 'repeat' => 'f01e', 'refresh' => 'f021', 'list-alt' => 'f022', 'lock' => 'f023', 'flag' => 'f024', 'headphones' => 'f025', 'volume-off' => 'f026', 'volume-down' => 'f027', 'volume-up' => 'f028', 'qrcode' => 'f029', 'barcode' => 'f02a', 'tag' => 'f02b', 'tags' => 'f02c', 'book' => 'f02d', 'bookmark' => 'f02e', 'print' => 'f02f', 'camera' => 'f030', 'font' => 'f031', 'bold' => 'f032', 'italic' => 'f033', 'text-height' => 'f034', 'text-width' => 'f035', 'align-left' => 'f036', 'align-center' => 'f037', 'align-right' => 'f038', 'align-justify' => 'f039', 'list' => 'f03a', 'indent-left' => 'f03b', 'indent-right' => 'f03c', 'facetime-video' => 'f03d', 'picture' => 'f03e', 'pencil' => 'f040', 'map-marker' => 'f041', 'adjust' => 'f042', 'tint' => 'f043', 'edit' => 'f044', 'share' => 'f045', 'check' => 'f046', 'move' => 'f047', 'step-backward' => 'f048', 'fast-backward' => 'f049', 'backward' => 'f04a', 'play' => 'f04b', 'pause' => 'f04c', 'stop' => 'f04d', 'forward' => 'f04e', 'fast-forward' => 'f050', 'step-forward' => 'f051', 'eject' => 'f052', 'chevron-left' => 'f053', 'chevron-right' => 'f054', 'plus-sign' => 'f055', 'minus-sign' => 'f056', 'remove-sign' => 'f057', 'ok-sign' => 'f058', 'question-sign' => 'f059', 'info-sign' => 'f05a', 'screenshot' => 'f05b', 'remove-circle' => 'f05c', 'ok-circle' => 'f05d', 'ban-circle' => 'f05e', 'arrow-left' => 'f060', 'arrow-right' => 'f061', 'arrow-up' => 'f062', 'arrow-down' => 'f063', 'share-alt' => 'f064', 'resize-full' => 'f065', 'resize-small' => 'f066', 'plus' => 'f067', 'minus' => 'f068', 'asterisk' => 'f069', 'exclamation-sign' => 'f06a', 'gift' => 'f06b', 'leaf' => 'f06c', 'fire' => 'f06d', 'eye-open' => 'f06e', 'eye-close' => 'f070', 'warning-sign' => 'f071', 'plane' => 'f072', 'calendar' => 'f073', 'random' => 'f074', 'comment' => 'f075', 'magnet' => 'f076', 'chevron-up' => 'f077', 'chevron-down' => 'f078', 'retweet' => 'f079', 'shopping-cart' => 'f07a', 'folder-close' => 'f07b', 'folder-open' => 'f07c', 'resize-vertical' => 'f07d', 'resize-horizontal' => 'f07e', 'bar-chart' => 'f080', 'twitter-sign' => 'f081', 'facebook-sign' => 'f082', 'camera-retro' => 'f083', 'key' => 'f084', 'cogs' => 'f085', 'comments' => 'f086', 'thumbs-up' => 'f087', 'thumbs-down' => 'f088', 'star-half' => 'f089', 'heart-empty' => 'f08a', 'signout' => 'f08b', 'linkedin-sign' => 'f08c', 'pushpin' => 'f08d', 'external-link' => 'f08e', 'signin' => 'f090', 'trophy' => 'f091', 'github-sign' => 'f092', 'upload-alt' => 'f093', 'lemon' => 'f094' } char = map[name.to_s] || 'f06a' "<span class=\"font-awesome\">&#x#{char};</span>" end |
#link_to(title, target = "", options = {}) ⇒ Object
230 231 232 233 234 235 |
# File 'lib/schnitzelpress/helpers.rb', line 230 def link_to(title, target = "", = {}) [:href] = target.respond_to?(:to_url) ? target.to_url : target [:data] ||= {} [:method, :confirm].each { |a| [:data][a] = .delete(a) } haml "%a#{} #{title}" end |
#link_to_delete_post(title, post) ⇒ Object
237 238 239 |
# File 'lib/schnitzelpress/helpers.rb', line 237 def link_to_delete_post(title, post) link_to title, "/admin/edit/#{post.id}", :method => :delete, :confirm => "Are you sure? This can not be undone." end |
#partial(thing, locals = {}) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/schnitzelpress/helpers.rb', line 15 def partial(thing, locals = {}) name = case thing when String then thing else thing.class.to_s.demodulize.underscore end haml :"partials/_#{name}", :locals => { name.to_sym => thing }.merge(locals) end |
#production? ⇒ Boolean
42 43 44 |
# File 'lib/schnitzelpress/helpers.rb', line 42 def production? settings.environment.to_sym == :production end |
#set_page_title(title) ⇒ Object
28 29 30 |
# File 'lib/schnitzelpress/helpers.rb', line 28 def set_page_title(title) @page_title = title end |
#show_disqus? ⇒ Boolean
38 39 40 |
# File 'lib/schnitzelpress/helpers.rb', line 38 def show_disqus? config.disqus_id.present? end |
#url_for(thing, options = {}) ⇒ Object
32 33 34 35 36 |
# File 'lib/schnitzelpress/helpers.rb', line 32 def url_for(thing, = {}) url = thing.respond_to?(:to_url) ? thing.to_url : thing.to_s url = "#{base_url.sub(/\/$/, '')}#{url}" if [:absolute] url end |
#user_logged_in? ⇒ Boolean
46 47 48 |
# File 'lib/schnitzelpress/helpers.rb', line 46 def user_logged_in? session[:auth].present? end |