html_skeleton 0.5.3 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/MIT-LICENSE +3 -1
- data/README.md +93 -82
- data/lib/html_skeleton.rb +10 -9
- data/lib/html_skeleton_calendar.rb +15 -14
- data/lib/html_skeleton_table.rb +8 -7
- metadata +6 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1fcfd9e44c12bac333c9063ab0f7a73e9479deb47a1bc7b588b2f2073cb3cbe
|
4
|
+
data.tar.gz: 912e2ebf34fbcfed8ff035eab9478e68f963843b45902fe329db869ea4eeae93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bd5471ae4b9322f59b9d88f0157c4167c7d465e4a08c6e82a155eddaf4b6acf7d8c5b75e0eb8fa04e7bcda8f8827b1dff7bc1aede12f7a1459f7114c4299431
|
7
|
+
data.tar.gz: d8ae07ff06777a2d60910a62ebc1b69932aced4c358fa7d437acb92cf5744b9a8cfe8ac2f8b69caa509d9d2c645ae2f40adec8144d8be4356f10de8db79ef227
|
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
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
|
[](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
|
-
|
12
|
-
-------
|
13
|
-
|
14
|
-
gem 'html_skeleton'
|
11
|
+
## Installation
|
15
12
|
|
16
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
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
|
4
|
-
require
|
5
|
-
require
|
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 ?
|
14
|
-
body
|
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
|
-
|
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:
|
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:
|
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
|
3
|
+
require "date"
|
4
4
|
|
5
5
|
# calendar methods ###################################################
|
6
6
|
class HtmlSkeleton
|
7
7
|
attr_reader :day_header
|
8
8
|
|
9
|
-
|
9
|
+
protected
|
10
|
+
|
10
11
|
def a_year(year)
|
11
12
|
rows = @options[:rows]
|
12
13
|
cols = 12 / rows
|
13
|
-
raise
|
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
|
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
|
45
|
+
last = Date.civil(year, month, -1)
|
45
46
|
|
46
|
-
cal = +
|
47
|
-
cal <<
|
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 <<
|
51
|
+
cal << "</tr> <tr>" if cur.wday == last_weekday
|
51
52
|
}
|
52
|
-
cal <<
|
53
|
-
cal <<
|
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 =
|
58
|
-
attrs +=
|
59
|
-
attrs +=
|
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
|
data/lib/html_skeleton_table.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
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
|
10
|
+
legend = @options[:legend]
|
10
11
|
th_attribute = @options[:th_attribute]
|
11
|
-
return
|
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
|
22
|
-
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|
|
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.
|
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:
|
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@
|
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://
|
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.
|
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
|