lab42_tag_cloud 0.1.0 → 0.1.1
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/README.md +28 -5
- data/lib/lab42/tag_cloud/version.rb +1 -1
- data/lib/lab42/tag_cloud.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ea0085aded203077c7de770ddcde0f730c993a9ce98cb630320151a0ff74c61
|
4
|
+
data.tar.gz: b0338da22dc8e6355a4e59681f2d4386407956dfc4df4f4e3905b020f9edcc48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec0f9d03bf726fe530b03a476e4b7de74370228f79a1de8ccd9b432537e07f22f7a3766b46e6cf61e8836bdbd10f32109c22748fb12bca89b4376506ce9eb8ea
|
7
|
+
data.tar.gz: aaaf153f719b1a56cbe043c3fcd1b2a9536559490d6066dae1f0c138f178bbb8647ceabbbcfa19e3856bb0e0783df31cc6bf219b49d1cef2a2fe74d3e61a1ff0
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
[](https://codeclimate.com/github/RobertDober/lab42_tag_cloud)
|
2
|
-
[](https://rubygems.org/gems/lab42_lab42_tag_cloud)
|
3
2
|
[](https://github.com/robertdober/lab42_tag_cloud/actions)
|
4
3
|
[](https://coveralls.io/github/RobertDober/lab42_tag_cloud?branch=main)
|
5
|
-
|
4
|
+
[](https://rubygems.org/gems/lab42_tag_cloud)
|
5
|
+
[](https://rubygems.org/gems/lab42_tag_cloud)
|
6
6
|
|
7
7
|
# Lab42::TagCloud
|
8
8
|
|
@@ -113,19 +113,42 @@ then we could do very nice things like
|
|
113
113
|
|
114
114
|
would that not be great?
|
115
115
|
|
116
|
-
Well guess what it _is_ _great_, and the helper is called `tag_from_object` indeed
|
116
|
+
Well guess what, it _is_ _great_, and the helper is called `tag_from_object` indeed
|
117
117
|
|
118
118
|
Given an `OpenStruct` and a `Hash` instance of the required format
|
119
119
|
```ruby
|
120
120
|
let(:ostruct) { OpenStruct.new(tag: "Ruby", dsl: "10/red 1.2em") }
|
121
121
|
let(:hash) { {tag: "Elixir", dsl: "blue 1.5em 800"} }
|
122
|
+
let(:elixir_style) { %{ style="color: #0000ff; font-size: 1.5em; font-weight: 800;"} }
|
123
|
+
let(:ruby_style) { %{ style="color: #ff7171; font-size: 1.2em;"} }
|
124
|
+
let(:two) { [ostruct, hash] }
|
122
125
|
```
|
123
126
|
|
124
127
|
Then we can obtain tags from these objects
|
125
128
|
```ruby
|
126
|
-
expect(tag_from_object(ostruct)).to eq(%{<span
|
129
|
+
expect(tag_from_object(ostruct)).to eq(%{<span#{ruby_style}>Ruby</span>})
|
127
130
|
expect(tag_from_object(hash, tag: :div, class: "some-class"))
|
128
|
-
.to eq(%{<div class="some-class"
|
131
|
+
.to eq(%{<div class="some-class"#{elixir_style}>Elixir</div>})
|
132
|
+
```
|
133
|
+
|
134
|
+
And we can map them together
|
135
|
+
```ruby
|
136
|
+
expected =
|
137
|
+
%{<span#{ruby_style}>Ruby</span> <span#{elixir_style}>Elixir</span>}
|
138
|
+
|
139
|
+
expect(two.map {tag_from_object(_1)}.join(" "))
|
140
|
+
.to eq(expected)
|
141
|
+
```
|
142
|
+
|
143
|
+
But that is cumbersome and we want a more flexible approach: Enter `tags_from_collction`
|
144
|
+
|
145
|
+
Then with this we can do things like:
|
146
|
+
```ruby
|
147
|
+
expected =
|
148
|
+
%{<li#{ruby_style}><i>Ruby</i></li> - <li#{elixir_style}><i>Elixir</i></li>}
|
149
|
+
|
150
|
+
expect(tags_from_collection(two, tag: :li, before: "<i>", after: "</i>", join: " - "))
|
151
|
+
.to eq(expected)
|
129
152
|
```
|
130
153
|
|
131
154
|
Typically such tag clouds can than be easily constructed from external data sources like JSON or YAML
|
data/lib/lab42/tag_cloud.rb
CHANGED
@@ -12,6 +12,12 @@ module Lab42
|
|
12
12
|
Compiler.tag_from_object(object, **atts)
|
13
13
|
end
|
14
14
|
|
15
|
+
def tags_from_collection(collection, before: "", after: "", join: "", **atts)
|
16
|
+
collection
|
17
|
+
.map { tag_from_object({ dsl: _1[:dsl], tag: [before, _1[:tag], after].join }, **atts) }
|
18
|
+
.join(join)
|
19
|
+
end
|
20
|
+
|
15
21
|
def to_style(dsl_string)
|
16
22
|
Compiler.make_css_attributes(*dsl_string.split)
|
17
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lab42_tag_cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
Creating Tag Clouds with gamma correct color values and styles from a simple DSL.
|