Class: PrintableCalendar::View
- Inherits:
-
Fortitude::Widget
- Object
- Fortitude::Widget
- PrintableCalendar::View
- Defined in:
- lib/printable_calendar/view.rb
Instance Method Summary collapse
- #bootstrap ⇒ Object
- #content ⇒ Object
- #format_date(date_time, show_day) ⇒ Object
- #format_time(date_time) ⇒ Object
-
#initialize(settings, starts, ends, data) ⇒ View
constructor
A new instance of View.
- #overrides ⇒ Object
- #title_text ⇒ Object
Constructor Details
#initialize(settings, starts, ends, data) ⇒ View
Returns a new instance of View.
9 10 11 12 13 14 |
# File 'lib/printable_calendar/view.rb', line 9 def initialize(settings, starts, ends, data) @settings = settings @starts = starts @ends = ends @data = data end |
Instance Method Details
#bootstrap ⇒ Object
52 53 54 |
# File 'lib/printable_calendar/view.rb', line 52 def bootstrap File.read(File.("../../../vendor/bootstrap.min.css", __FILE__)) end |
#content ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/printable_calendar/view.rb', line 16 def content grouped = @data.group_by{|e| e.start_time.to_date} html { head { (charset: "UTF-8") title(title_text) style(bootstrap) style(overrides) } body { div(class: "container"){ h1(title_text) table(class: "table"){ tbody { grouped.map { |starts, es| tr { td(format_date(starts, true), rowspan: es.count) td("#{format_time(es.first.start_time)} – #{format_time(es.first.end_time)}") td(es.first.title) } es.drop(1).map { |e| tr { td(style: "display: none") td("#{format_time(e.start_time)} – #{format_time(e.end_time)}") td(e.title) } } } } } } } } end |
#format_date(date_time, show_day) ⇒ Object
82 83 84 85 |
# File 'lib/printable_calendar/view.rb', line 82 def format_date(date_time, show_day) date_time = Date.iso8601(date_time) if date_time.is_a?(String) date_time.strftime(show_day ? "%A, %b %d" : "%b %d") end |
#format_time(date_time) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/printable_calendar/view.rb', line 75 def format_time(date_time) zone = Time.now.getlocal.zone date_time = DateTime.iso8601(date_time) if date_time.is_a?(String) date_time = date_time.in_time_zone(zone) date_time.strftime("%I:%M%P") end |
#overrides ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/printable_calendar/view.rb', line 56 def overrides " tr {padding-bottom: 35px;}\n tr:nth-child(odd) {\n background-color: #eceeef !important;\n -webkit-print-color-adjust: exact !important;\n }\n tr:nth-child(odd) td[rowspan]{\n background-color: white !important;\n -webkit-print-color-adjust: exact !important;\n }\n eos\nend\n" |
#title_text ⇒ Object
70 71 72 73 |
# File 'lib/printable_calendar/view.rb', line 70 def title_text t = @settings[:title] || "Calendar" "#{t} for #{format_date(@starts, false)} – #{format_date(@ends, false)}" end |