jsmenubuilder 0.1.0
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 +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/jsmenubuilder.rb +159 -0
- metadata +90 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c2d779db609c99fd6d02286ce9a4d3219b31abd8354695942ed0b08940d76f76
|
4
|
+
data.tar.gz: 906184a64d92b74b605271b8092e95d89c59caf749be5d617ec3704d10bb7bc9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c0d55d91b7d8b2c3cb7d63545f02cd92e37d3b23c0eca25b48b2f66a4707c8d644eed58cd9022fdd2f1455a9c613154844878d1da0401718550fb524f67206d2
|
7
|
+
data.tar.gz: 6a676ecfca13e8839498ccbb75a45d2f531dd69f98616db45a40bd1c78b8c6e9990904249443d01d0924c071cca36c816aad9e974482a6239f3a0bd7055299eb
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
@@ -0,0 +1,159 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: jsmenubuilder.rb
|
4
|
+
|
5
|
+
require 'rexle'
|
6
|
+
require 'rexle-builder'
|
7
|
+
|
8
|
+
class JsMenuBuilder
|
9
|
+
|
10
|
+
TABS_CSS =<<EOF
|
11
|
+
/* Style the tab */
|
12
|
+
.tab {
|
13
|
+
overflow: hidden;
|
14
|
+
border: 1px solid #ccc;
|
15
|
+
background-color: #f1f1f1;
|
16
|
+
}
|
17
|
+
|
18
|
+
/* Style the buttons that are used to open the tab content */
|
19
|
+
.tab button {
|
20
|
+
background-color: inherit;
|
21
|
+
float: left;
|
22
|
+
border: none;
|
23
|
+
outline: none;
|
24
|
+
cursor: pointer;
|
25
|
+
padding: 14px 16px;
|
26
|
+
transition: 0.3s;
|
27
|
+
}
|
28
|
+
|
29
|
+
/* Change background color of buttons on hover */
|
30
|
+
.tab button:hover {
|
31
|
+
background-color: #ddd;
|
32
|
+
}
|
33
|
+
|
34
|
+
/* Create an active/current tablink class */
|
35
|
+
.tab button.active {
|
36
|
+
background-color: #ccc;
|
37
|
+
}
|
38
|
+
|
39
|
+
/* Style the tab content */
|
40
|
+
.tabcontent {
|
41
|
+
display: none;
|
42
|
+
padding: 6px 12px;
|
43
|
+
border: 1px solid #ccc;
|
44
|
+
border-top: none;
|
45
|
+
}
|
46
|
+
EOF
|
47
|
+
|
48
|
+
TABS_JS =<<EOF
|
49
|
+
function openTab(evt, tabName) {
|
50
|
+
// Declare all variables
|
51
|
+
var i, tabcontent, tablinks;
|
52
|
+
|
53
|
+
// Get all elements with class="tabcontent" and hide them
|
54
|
+
tabcontent = document.getElementsByClassName("tabcontent");
|
55
|
+
for (i = 0; i < tabcontent.length; i++) {
|
56
|
+
tabcontent[i].style.display = "none";
|
57
|
+
}
|
58
|
+
|
59
|
+
// Get all elements with class="tablinks" and remove the class "active"
|
60
|
+
tablinks = document.getElementsByClassName("tablinks");
|
61
|
+
for (i = 0; i < tablinks.length; i++) {
|
62
|
+
tablinks[i].className = tablinks[i].className.replace(" active", "");
|
63
|
+
}
|
64
|
+
|
65
|
+
// Show the current tab, and add an "active" class to the button that opened the tab
|
66
|
+
document.getElementById(tabName).style.display = "block";
|
67
|
+
evt.currentTarget.className += " active";
|
68
|
+
}
|
69
|
+
|
70
|
+
EOF
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
attr_reader :html, :css, :js
|
75
|
+
|
76
|
+
def initialize(type, options={})
|
77
|
+
|
78
|
+
@type = type
|
79
|
+
types = %i(tabs)
|
80
|
+
method(type.to_sym).call(options) if types.include? type
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
def to_css()
|
85
|
+
@css
|
86
|
+
end
|
87
|
+
|
88
|
+
def to_html()
|
89
|
+
@html
|
90
|
+
end
|
91
|
+
|
92
|
+
def to_js()
|
93
|
+
@js
|
94
|
+
end
|
95
|
+
|
96
|
+
def to_webpage()
|
97
|
+
|
98
|
+
a = RexleBuilder.build do |xml|
|
99
|
+
xml.html do
|
100
|
+
xml.head do
|
101
|
+
xml.meta name: "viewport", content: \
|
102
|
+
"width=device-width, initial-scale=1"
|
103
|
+
xml.style "\nbody {font-family: Arial;}\n\n" + @css
|
104
|
+
end
|
105
|
+
xml.body
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
doc = Rexle.new(a)
|
110
|
+
e = Rexle.new("<html>%s</html>" % @html).root
|
111
|
+
|
112
|
+
e.children.each {|child| doc.root.element('body').add child }
|
113
|
+
|
114
|
+
doc.root.element('body').add \
|
115
|
+
Rexle::Element.new('script').add_text "\n" +
|
116
|
+
@js.gsub(/^ +\/\/[^\n]+\n/,'')
|
117
|
+
|
118
|
+
"<!DOCTYPE html>\n" + doc.xml(pretty: true, declaration: false)\
|
119
|
+
.gsub(/<\/div>/,'\0' + "\n").gsub(/\n *<!--[^>]+>/,'')
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
def tabs(options={})
|
126
|
+
|
127
|
+
## build the HTML
|
128
|
+
|
129
|
+
a = RexleBuilder.build do |xml|
|
130
|
+
xml.html do
|
131
|
+
|
132
|
+
xml.comment!(' Tab links ')
|
133
|
+
xml.div(class: 'tab' ) do
|
134
|
+
options[:headings].each do |heading|
|
135
|
+
xml.button({class:'tablinks',
|
136
|
+
onclick: %Q(openTab(event, "#{heading}"))}, heading)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
xml.comment!(' Tab content ')
|
141
|
+
|
142
|
+
options[:headings].each do |heading|
|
143
|
+
xml.div(id: heading, class: 'tabcontent' ) do
|
144
|
+
xml.h3 heading
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
@html = Rexle.new(a).xml(pretty: true, declaration: false)\
|
151
|
+
.gsub(/<\/div>/,'\0' + "\n").strip.lines[1..-2]\
|
152
|
+
.map {|x| x.sub(/^ /,'') }.join
|
153
|
+
|
154
|
+
@css = Object.const_get 'JsMenuBuilder::' + @type.to_s.upcase + '_CSS'
|
155
|
+
@js = Object.const_get 'JsMenuBuilder::' + @type.to_s.upcase + '_JS'
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jsmenubuilder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTkwNzEwMjIyNTAxWhcN
|
15
|
+
MjAwNzA5MjIyNTAxWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQCsiwlw
|
17
|
+
p3DM4VpbJzWbQbeMzzYfJtfLQ2Mfo96Dj/DKL03wCenhOaiYlLUtsI2zudQtIS6U
|
18
|
+
Rkf2wXnxHR8hSG7euQXXq0GEqoHPufrcr2Ih/vsm2CgBCpYFqJtjOK/T//+Cdy6e
|
19
|
+
hXsQ82b0LOJ+IU/I7h5eIcjLa1JMAvtRt8aLFNK0PfIWeFQRs2t0cCYltmgKoyyk
|
20
|
+
sfGEE4wBLEz5T21KzkRR6EDLWsF72qUju3LFL0mr+FJ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Yk/5LgCv9jxxzQcSS20C8O9MWRVvYfIr47ak7
|
36
|
+
yXrDPmRvbJLTNjDv6Tkg3vU6
|
37
|
+
-----END CERTIFICATE-----
|
38
|
+
date: 2019-07-10 00:00:00.000000000 Z
|
39
|
+
dependencies:
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: rexle
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.5'
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.5.1
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '1.5'
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 1.5.1
|
60
|
+
description:
|
61
|
+
email: james@jamesrobertson.eu
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- lib/jsmenubuilder.rb
|
67
|
+
homepage: https://github.com/jrobertson/jsmenubuilder
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubygems_version: 3.0.1
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: Generates HTML based tabs using HTML, CSS, and JavaScript.
|
90
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|