html_skeleton 0.5.3 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e29dd94798168a8ab8267eed2aaf79df55206eebdc08529fa4d3105959761a7c
4
- data.tar.gz: e42c7b766fd842f825e8c53b2e32652c8535728e9a67360de5b0deffafb9d364
3
+ metadata.gz: b1fcfd9e44c12bac333c9063ab0f7a73e9479deb47a1bc7b588b2f2073cb3cbe
4
+ data.tar.gz: 912e2ebf34fbcfed8ff035eab9478e68f963843b45902fe329db869ea4eeae93
5
5
  SHA512:
6
- metadata.gz: f1866ed93d9c6e5c2a8bb055c9a8a1529bb7117429ee8ffa57adf371902e7e373306c2ef30968f9f57a7e5e18056c0c5f5b79f36f822e69e2544f94e75769d1b
7
- data.tar.gz: 8bb4b6fd8ca2d34f18af0fe5850a5ab9cab30b03a0792aa94a11c637fe45265f2df9216dd2686d11a98f368fc6d9b16ef4bf1c3d8c21185f0e1bf42fddf5f622
6
+ metadata.gz: 0bd5471ae4b9322f59b9d88f0157c4167c7d465e4a08c6e82a155eddaf4b6acf7d8c5b75e0eb8fa04e7bcda8f8827b1dff7bc1aede12f7a1459f7114c4299431
7
+ data.tar.gz: d8ae07ff06777a2d60910a62ebc1b69932aced4c358fa7d437acb92cf5744b9a8cfe8ac2f8b69caa509d9d2c645ae2f40adec8144d8be4356f10de8db79ef227
data/MIT-LICENSE CHANGED
@@ -1,4 +1,6 @@
1
- Copyright 2012-2021 Dittmar Krall - www.matique.com
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2012-2023 Dittmar Krall (www.matiq.com)
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- HtmlSkeleton
2
- ============
1
+ # HtmlSkeleton
2
+
3
3
  [![Gem Version](https://badge.fury.io/rb/html_skeleton.png)](http://badge.fury.io/rb/html_skeleton)
4
4
 
5
5
  HtmlSkeleton provides the frame for a calendar or a table,
@@ -8,16 +8,16 @@ Filling the skeleton is done via parameters and, in particular,
8
8
  with procs (Proc.new, lambda).
9
9
  See below Default Options.
10
10
 
11
- Install
12
- -------
13
-
14
- gem 'html_skeleton'
11
+ ## Installation
15
12
 
16
- rake # for testing
13
+ As usual:
14
+ ``` ruby
15
+ # Gemfile
16
+ gem "html_skeleton"
17
+ ```
18
+ and run "bundle install".
17
19
 
18
-
19
- Calendar
20
- ========
20
+ ## Calendar
21
21
 
22
22
  A simple helper for creating an HTML calendar.
23
23
  The "calendar" method will be available to your view templates.
@@ -26,31 +26,34 @@ Procs may be supplied to generate
26
26
  particular HTML-code for a day or the year.
27
27
  In the example below clicking a day triggers an action.
28
28
 
29
- Examples
30
- --------
31
- HtmlSkeleton.new.calendar # calendar for current year
32
- HtmlSkeleton.new.calendar year: 2012 # calendar for year 2012
33
- HtmlSkeleton.new.calendar year: 2012, month: 8 # calendar for August 2012
34
-
35
- HtmlSkeleton.new.calendar {|date|
36
- link ="/#{controller_name}/toggle/#{@resource.id}?date=#{date}"
37
- style = @resource.holidays.include?(date.to_s) ?
38
- 'font-weight:bold; color:red' : ''
39
- %Q{ <a style="#{style}" href="#{link}"> #{date.day.to_s} </a>}
40
- }
41
-
42
- Default Options
43
- ---------------
44
- year: DateTime.now.year,
45
- title: DateTime.now.year,
46
- rows: 3,
47
- calendar_class: 'skeleton',
48
- day_names: Date::DAYNAMES.dup,
49
- month_names: Date::MONTHNAMES,
50
- abbrev: (0..1),
51
- cell_proc: block || ->(d) { d.day.to_s},
52
- first_day_of_week: 1
53
-
29
+ ### Examples
30
+
31
+ ``` ruby
32
+ HtmlSkeleton.new.calendar # calendar for current year
33
+ HtmlSkeleton.new.calendar year: 2012 # calendar for year 2012
34
+ HtmlSkeleton.new.calendar year: 2012, month: 8 # calendar for August 2012
35
+
36
+ HtmlSkeleton.new.calendar {|date|
37
+ link = "/#{controller_name}/toggle/#{@resource.id}?date=#{date}"
38
+ style = @resource.holidays.include?(date.to_s) ?
39
+ 'font-weight:bold; color:red' : ''
40
+ %Q{ <a style="#{style}" href="#{link}"> #{date.day.to_s} </a>}
41
+ }
42
+ ```
43
+
44
+ ### Default Options
45
+
46
+ ``` ruby
47
+ year: DateTime.now.year,
48
+ title: DateTime.now.year,
49
+ rows: 3,
50
+ calendar_class: 'skeleton',
51
+ day_names: Date::DAYNAMES.dup,
52
+ month_names: Date::MONTHNAMES,
53
+ abbrev: (0..1),
54
+ cell_proc: block || ->(d) { d.day.to_s},
55
+ first_day_of_week: 1
56
+ ```
54
57
 
55
58
  Inspired by calendar_helper:
56
59
 
@@ -58,56 +61,64 @@ Inspired by calendar_helper:
58
61
  * Geoffrey Grosenbach -- http://nubyonrails.com
59
62
 
60
63
 
61
- Table
62
- =====
64
+ ## Table
63
65
 
64
66
  A simple helper for creating an HTML table.
65
67
 
66
68
  Table only takes care of the HTML tags and expects lambdas/strings to
67
69
  be supplied by the user.
68
70
 
69
- Examples
70
- --------
71
- rows = %w{a bb ccc}
72
- cols = %w{1 22}
73
- HtmlSkeleton.new.table(rows, cols) {|row, col|
74
- col == '1' ? '<td>bingo</td>' : '<td></td>'
75
- }
76
-
77
- HtmlSkeleton.new.table(@users, %w{email address},
78
- th_attribute: lambda { |col| col.name },
79
- legend: 'Users') { |row, col|
80
- "<td>#{ row.send(col) }</td>"
81
- }
82
-
83
- stripes = %w{odd even}
84
- proc = ->(row) { k = stripes.shift; stripes << k; %Q{class="#{k}"} }
85
- HtmlSkeleton.new.table(@users, %w{email address},
86
- tr_attribute: proc,
87
- legend: 'Users') { |row, col|
88
- "<td>#{ row.send(col) }</td>"
89
- }
90
-
91
- Default Options
92
- ---------------
93
- legend: nil,
94
- col_legend: ->(x) { x.to_s },
95
- row_legend: ->(x) { x.id },
96
- th_attribute: ->(col) { nil },
97
- tr_attribute: ->(row) { nil },
98
- table_class: 'skeleton',
99
- cell_proc: block || ->(row, col) { "<td>#{row} #{col}</td>"}
100
-
101
-
102
- Curious?
103
- --------
104
-
105
- github.com/cthulhu666/easy_table
106
- github.com/giniedp/fancygrid
107
- github.com/hunterae/table-for
108
- github.com/jgdavey/tabletastic
109
- github.com/lunich/table_for
110
- github.com/watu/table_builder
111
- ruby-toolbox.com/projects/tableasy
112
-
113
- Copyright (c) 2012-2019 [Dittmar Krall], released under the MIT license.
71
+ ### Examples
72
+
73
+ ``` ruby
74
+ rows = %w{a bb ccc}
75
+ cols = %w{1 22}
76
+ HtmlSkeleton.new.table(rows, cols) {|row, col|
77
+ col == '1' ? '<td>bingo</td>' : '<td></td>'
78
+ }
79
+ ```
80
+
81
+ ``` ruby
82
+ HtmlSkeleton.new.table(@users, %w{email address},
83
+ th_attribute: lambda { |col| col.name },
84
+ legend: 'Users') { |row, col| "<td>#{ row.send(col) }</td>" }
85
+ ```
86
+
87
+ ``` ruby
88
+ stripes = %w{odd even}
89
+ proc = ->(row) { k = stripes.shift; stripes << k; %Q{class="#{k}"} }
90
+ HtmlSkeleton.new.table(@users, %w{email address},
91
+ tr_attribute: proc,
92
+ legend: 'Users') { |row, col|
93
+ "<td>#{ row.send(col) }</td>"
94
+ }
95
+ ```
96
+
97
+ ### Default Options
98
+
99
+ ``` ruby
100
+ legend: nil,
101
+ col_legend: ->(x) { x.to_s },
102
+ row_legend: ->(x) { x.id },
103
+ th_attribute: ->(col) { nil },
104
+ tr_attribute: ->(row) { nil },
105
+ table_class: 'skeleton',
106
+ cell_proc: block || ->(row, col) { "<td>#{row} #{col}</td>"}
107
+ ```
108
+
109
+ ## Curious?
110
+
111
+ - github.com/cthulhu666/easy_table
112
+ - github.com/giniedp/fancygrid
113
+ - github.com/hunterae/table-for
114
+ - github.com/jgdavey/tabletastic
115
+ - github.com/lunich/table_for
116
+ - github.com/watu/table_builder
117
+ - ruby-toolbox.com/projects/tableasy
118
+
119
+ ## Miscellaneous
120
+
121
+ Copyright (c) 2012-2023 Dittmar Krall (www.matiq.com),
122
+ released under the MIT license:
123
+
124
+ * https://opensource.org/licenses/MIT
data/lib/html_skeleton.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'date'
4
- require 'html_skeleton_calendar'
5
- require 'html_skeleton_table'
3
+ require "date"
4
+ require "html_skeleton_calendar"
5
+ require "html_skeleton_table"
6
6
 
7
7
  class HtmlSkeleton
8
8
  attr_reader :options
@@ -10,8 +10,8 @@ class HtmlSkeleton
10
10
  def calendar(options = {}, &block)
11
11
  set_calendar_options(options, &block)
12
12
  month = @options[:month]
13
- frame = month ? 'div' : 'table'
14
- body = month ? a_month(@options[:year], month) : a_year(@options[:year])
13
+ frame = month ? "div" : "table"
14
+ body = month ? a_month(@options[:year], month) : a_year(@options[:year])
15
15
  %(<#{frame} class="#{@options[:calendar_class]}"> #{body} </#{frame}>)
16
16
  end
17
17
 
@@ -25,14 +25,15 @@ class HtmlSkeleton
25
25
  TABLE
26
26
  end
27
27
 
28
- protected
28
+ protected
29
+
29
30
  def set_calendar_options(options, &block)
30
31
  year = DateTime.now.year
31
32
  @options = {
32
33
  year: year,
33
34
  title: year,
34
35
  rows: 3,
35
- calendar_class: 'skeleton',
36
+ calendar_class: "skeleton",
36
37
  month_names: Date::MONTHNAMES,
37
38
  abbrev: (0..1),
38
39
  cell_proc: block || ->(d) { d.day.to_s },
@@ -44,7 +45,7 @@ class HtmlSkeleton
44
45
 
45
46
  @day_header = names.collect { |day|
46
47
  abbr = day[@options[:abbrev]]
47
- str = abbr == day ? day : %(<abbr title="#{day}">#{abbr}</abbr>)
48
+ str = (abbr == day) ? day : %(<abbr title="#{day}">#{abbr}</abbr>)
48
49
  %(<th scope="col">#{str}</th>)
49
50
  }.join
50
51
  end
@@ -57,7 +58,7 @@ class HtmlSkeleton
57
58
  th_attribute: ->(_col) {},
58
59
  tr_attribute: ->(_row) {},
59
60
 
60
- table_class: 'skeleton',
61
+ table_class: "skeleton",
61
62
  cell_proc: block || ->(row, col) { "<td>#{row} #{col}</td>" }
62
63
  }.merge options
63
64
  end
@@ -1,16 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'date'
3
+ require "date"
4
4
 
5
5
  # calendar methods ###################################################
6
6
  class HtmlSkeleton
7
7
  attr_reader :day_header
8
8
 
9
- protected
9
+ protected
10
+
10
11
  def a_year(year)
11
12
  rows = @options[:rows]
12
13
  cols = 12 / rows
13
- raise 'html_skeleton_calendar: invalid option <rows>' unless rows * cols == 12
14
+ raise "html_skeleton_calendar: invalid option <rows>" unless rows * cols == 12
14
15
 
15
16
  body = (0..rows - 1).collect { |y|
16
17
  str = (1..cols).collect { |x| "<td>#{a_month(year, y * cols + x)}</td>" }
@@ -35,28 +36,28 @@ class HtmlSkeleton
35
36
 
36
37
  def days_of_month(year, month)
37
38
  first_weekday = @options[:first_day_of_week]
38
- last_weekday = first_weekday.positive? ? first_weekday - 1 : 6
39
+ last_weekday = first_weekday.positive? ? first_weekday - 1 : 6
39
40
  cell_proc = @options[:cell_proc]
40
41
  bool = Time.respond_to?(:zone) && !(zone = Time.zone).nil?
41
42
  today = bool ? zone.now.to_date : Date.today
42
43
 
43
44
  first = Date.civil(year, month, 1)
44
- last = Date.civil(year, month, -1)
45
+ last = Date.civil(year, month, -1)
45
46
 
46
- cal = +'<tr>'
47
- cal << '<td></td>' * days_between(first_weekday, first.wday)
47
+ cal = +"<tr>"
48
+ cal << "<td></td>" * days_between(first_weekday, first.wday)
48
49
  first.upto(last) { |cur|
49
50
  cal << a_day(cur, today, cell_proc)
50
- cal << '</tr> <tr>' if cur.wday == last_weekday
51
+ cal << "</tr> <tr>" if cur.wday == last_weekday
51
52
  }
52
- cal << '<td></td>' * days_between((last + 1).wday, first_weekday + 7)
53
- cal << '</tr>'
53
+ cal << "<td></td>" * days_between((last + 1).wday, first_weekday + 7)
54
+ cal << "</tr>"
54
55
  end
55
56
 
56
57
  def a_day(date, today, block)
57
- attrs = 'day'
58
- attrs += ' weekendDay' if weekend?(date)
59
- attrs += ' today' if date == today
58
+ attrs = "day"
59
+ attrs += " weekendDay" if weekend?(date)
60
+ attrs += " today" if date == today
60
61
  "<td class=\"#{attrs}\">#{block.call(date)}</td>"
61
62
  end
62
63
 
@@ -65,6 +66,6 @@ class HtmlSkeleton
65
66
  end
66
67
 
67
68
  def days_between(first, second)
68
- first > second ? second + (7 - first) : second - first
69
+ (first > second) ? second + (7 - first) : second - first
69
70
  end
70
71
  end
@@ -1,14 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'date'
3
+ require "date"
4
4
 
5
5
  # table methods ######################################################
6
6
  class HtmlSkeleton
7
7
  protected
8
+
8
9
  def table_header(cols)
9
- legend = @options[:legend]
10
+ legend = @options[:legend]
10
11
  th_attribute = @options[:th_attribute]
11
- return '' unless legend
12
+ return "" unless legend
12
13
 
13
14
  proc = @options[:col_legend]
14
15
  col_header = cols.collect { |col|
@@ -18,11 +19,11 @@ class HtmlSkeleton
18
19
  end
19
20
 
20
21
  def table_body(rows, cols)
21
- legend = @options[:legend]
22
- row_legend = @options[:row_legend]
22
+ legend = @options[:legend]
23
+ row_legend = @options[:row_legend]
23
24
  tr_attribute = @options[:tr_attribute]
24
25
  rows.collect { |row|
25
- rlegend = ''
26
+ rlegend = ""
26
27
  rlegend = %(<td class="legend">#{row_legend.call(row)}</td>) if legend
27
28
  cells = table_row(row, cols)
28
29
  %(<tr #{tr_attribute.call(row)}>#{rlegend}#{cells}</tr>)
@@ -31,6 +32,6 @@ class HtmlSkeleton
31
32
 
32
33
  def table_row(row, cols)
33
34
  cell_proc = @options[:cell_proc]
34
- cols.collect { |col| cell_proc.call(row, col) }.join
35
+ cols.collect { |col| cell_proc.call(row, col) }.join
35
36
  end
36
37
  end
metadata CHANGED
@@ -1,43 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_skeleton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dittmar Krall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-22 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
11
+ date: 2023-04-24 00:00:00.000000000 Z
12
+ dependencies: []
41
13
  description: |2
42
14
  A simple helper for creating HTML calendars and tables.
43
15
 
@@ -45,7 +17,7 @@ description: |2
45
17
 
46
18
  The calendar/table may be embelished by user supplied lambda's,
47
19
  e.g. for inserting link_to.
48
- email: dittmar.krall@matique.de
20
+ email: dittmar.krall@matiq.com
49
21
  executables: []
50
22
  extensions: []
51
23
  extra_rdoc_files: []
@@ -55,7 +27,7 @@ files:
55
27
  - lib/html_skeleton.rb
56
28
  - lib/html_skeleton_calendar.rb
57
29
  - lib/html_skeleton_table.rb
58
- homepage: http://matique.de
30
+ homepage: http://matiq.com
59
31
  licenses:
60
32
  - MIT
61
33
  metadata:
@@ -75,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
47
  - !ruby/object:Gem::Version
76
48
  version: '0'
77
49
  requirements: []
78
- rubygems_version: 3.2.6
50
+ rubygems_version: 3.4.10
79
51
  signing_key:
80
52
  specification_version: 4
81
53
  summary: A simple helper for creating HTML calendars and tables