Module: Snails::ViewHelpers
- Defined in:
- lib/snails/app.rb
Class Method Summary collapse
Instance Method Summary collapse
- #action ⇒ Object
-
#get_page(counter) ⇒ Object
pagination.
- #partial(name, opts = {}) ⇒ Object
- #show_date(date) ⇒ Object
- #show_pager(array, path, per_page = 50) ⇒ Object
- #show_time(time) ⇒ Object
- #view(view_name, opts = {}) ⇒ Object
Class Method Details
.included(base) ⇒ Object
336 337 338 339 340 |
# File 'lib/snails/app.rb', line 336 def self.included(base) Time.include(RelativeTime) unless Time.instance_methods.include?(:relative) base.include(FormHelpers) base.include(SimpleFormat) end |
Instance Method Details
#action ⇒ Object
342 343 344 |
# File 'lib/snails/app.rb', line 342 def action request.path_info.gsub('/','').blank? ? 'home' : request.path_info.gsub('/',' ') end |
#get_page(counter) ⇒ Object
pagination
367 368 369 370 371 372 373 |
# File 'lib/snails/app.rb', line 367 def get_page(counter) curr = params[:page].to_i i = (curr == 0 && counter == 1) ? 2 : (curr == 2 && counter == -1) ? 0 : curr + counter i == 0 ? "" : "/page/#{i}" end |
#partial(name, opts = {}) ⇒ Object
346 347 348 349 |
# File 'lib/snails/app.rb', line 346 def partial(name, opts = {}) partial_name = name.to_s["/"] ? name.to_s.reverse.sub("/", "_/").reverse : "_#{name}" erb(partial_name.to_sym, { layout: false }.merge(opts)) end |
#show_date(date) ⇒ Object
356 357 358 |
# File 'lib/snails/app.rb', line 356 def show_date(date) date ? date.strftime("%d de %b, %Y") : '' end |
#show_pager(array, path, per_page = 50) ⇒ Object
375 376 377 378 379 380 381 382 383 384 |
# File 'lib/snails/app.rb', line 375 def show_pager(array, path, per_page = 50) # remove page from path path = (env['SCRIPT_NAME'] + path.gsub(/[?|&|\/]page[=|\/]\d+/,'')) prevlink = "<li><a href='#{path}#{get_page(-1)}'>← Prev</a></li>" nextlink = array.size != per_page ? "" : "<li><a href='#{path}#{get_page(1)}'>Next →</a></li>" str = params[:page] ? prevlink + nextlink : nextlink str != "" ? "<ul class='pager'>" + str + "</ul>" : '' end |
#show_time(time) ⇒ Object
360 361 362 |
# File 'lib/snails/app.rb', line 360 def show_time(time) time ? time.strftime("%d de %b, %Y a las %H:%M") : '' end |
#view(view_name, opts = {}) ⇒ Object
351 352 353 354 |
# File 'lib/snails/app.rb', line 351 def view(view_name, opts = {}) layout = request.xhr? ? false : true erb(view_name.to_sym, { layout: layout }.merge(opts)) end |