Sha256: 647f69e4e96dc2e592082213d43304ed7bddae432a611a3bbae43ad6f60fe193
Contents?: true
Size: 1.65 KB
Versions: 1
Compression:
Stored size: 1.65 KB
Contents
require 'date' require 'html_skeleton_calendar' require 'html_skeleton_table' class HtmlSkeleton attr_reader :options def calendar(options = {}, &block) set_calendar_options(options, &block) month = @options[:month] frame = month ? 'div' : 'table' body = month ? a_month(@options[:year], month) : a_year(@options[:year]) %(<#{frame} class="#{@options[:calendar_class]}"> #{body} </#{frame}>) end def table(rows, cols, options = {}, &block) set_table_options(options, &block) <<~TABLE <table class="#{@options[:table_class]}"> #{table_header(cols)} #{table_body(rows, cols)} </table> TABLE end protected def set_calendar_options(options, &block) year = DateTime.now.year @options = { year: year, title: year, rows: 3, calendar_class: 'skeleton', month_names: Date::MONTHNAMES, abbrev: (0..1), cell_proc: block || ->(d) { d.day.to_s }, first_day_of_week: 1 }.merge options names = options[:day_names] || Date::DAYNAMES.dup @options[:first_day_of_week].times { names.push(names.shift) } @day_header = names.collect { |day| abbr = day[@options[:abbrev]] str = abbr == day ? day : %(<abbr title="#{day}">#{abbr}</abbr>) %(<th scope="col">#{str}</th>) }.join('') end def set_table_options(options, &block) @options = { legend: nil, col_legend: lambda(&:to_s), row_legend: lambda(&:id), th_attribute: ->(_col) { nil }, tr_attribute: ->(_row) { nil }, table_class: 'skeleton', cell_proc: block || ->(row, col) { "<td>#{row} #{col}</td>" } }.merge options end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
html_skeleton-0.5.0 | lib/html_skeleton.rb |