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
337 338 339 340 341 |
# File 'lib/snails/app.rb', line 337 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
343 344 345 |
# File 'lib/snails/app.rb', line 343 def action request.path_info.gsub('/','').blank? ? 'home' : request.path_info.gsub('/',' ') end |
#get_page(counter) ⇒ Object
pagination
368 369 370 371 372 373 374 |
# File 'lib/snails/app.rb', line 368 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
347 348 349 350 |
# File 'lib/snails/app.rb', line 347 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
357 358 359 |
# File 'lib/snails/app.rb', line 357 def show_date(date) date ? date.strftime("%d de %b, %Y") : '' end |
#show_pager(array, path, per_page = 50) ⇒ Object
376 377 378 379 380 381 382 383 384 385 |
# File 'lib/snails/app.rb', line 376 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
361 362 363 |
# File 'lib/snails/app.rb', line 361 def show_time(time) time ? time.strftime("%d de %b, %Y a las %H:%M") : '' end |
#view(view_name, opts = {}) ⇒ Object
352 353 354 355 |
# File 'lib/snails/app.rb', line 352 def view(view_name, opts = {}) layout = request.xhr? ? false : true erb(view_name.to_sym, { layout: layout }.merge(opts)) end |