lab42_tag_cloud 0.1.0 → 0.1.1

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: f436800624ff7f6586968f55090f6001d0c4e90edcc686f9657217c9b46ff7bd
4
- data.tar.gz: f79aec9fd036b91ca147d6a6f04be3a2058b3f39627f7fae59f05a9376156149
3
+ metadata.gz: 2ea0085aded203077c7de770ddcde0f730c993a9ce98cb630320151a0ff74c61
4
+ data.tar.gz: b0338da22dc8e6355a4e59681f2d4386407956dfc4df4f4e3905b020f9edcc48
5
5
  SHA512:
6
- metadata.gz: 5bd224ec924a387260b50fe80fad583bcc6d9c95ea296bb6f395701a2d490299a221107b0c0faf781af75c3371bc1aa5b24f9048edfe50b921e8e488d73e8c52
7
- data.tar.gz: d549bc5db2f6c04aa7a5c9140d8972d5baea353f458cb2fed98cb9067f2d6f845e4aa5bd935afe3be03537e7cb79a8de88737e120b19bb38f87bd5ed8c961b37
6
+ metadata.gz: ec0f9d03bf726fe530b03a476e4b7de74370228f79a1de8ccd9b432537e07f22f7a3766b46e6cf61e8836bdbd10f32109c22748fb12bca89b4376506ce9eb8ea
7
+ data.tar.gz: aaaf153f719b1a56cbe043c3fcd1b2a9536559490d6066dae1f0c138f178bbb8647ceabbbcfa19e3856bb0e0783df31cc6bf219b49d1cef2a2fe74d3e61a1ff0
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  [![Issue Count](https://codeclimate.com/github/RobertDober/lab42_tag_cloud/badges/issue_count.svg)](https://codeclimate.com/github/RobertDober/lab42_tag_cloud)
2
- [![Gem Version](http://img.shields.io/gem/v/lab42_lab42_tag_cloud.svg)](https://rubygems.org/gems/lab42_lab42_tag_cloud)
3
2
  [![CI](https://github.com/robertdober/lab42_tag_cloud/workflows/CI/badge.svg)](https://github.com/robertdober/lab42_tag_cloud/actions)
4
3
  [![Coverage Status](https://coveralls.io/repos/github/RobertDober/lab42_tag_cloud/badge.svg?branch=main)](https://coveralls.io/github/RobertDober/lab42_tag_cloud?branch=main)
5
-
4
+ [![Gem Version](http://img.shields.io/gem/v/lab42_tag_cloud.svg)](https://rubygems.org/gems/lab42_tag_cloud)
5
+ [![Gem Downloads](https://img.shields.io/gem/dt/lab42_tag_cloud.svg)](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 style="color: #ff7171; font-size: 1.2em;">Ruby</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" style="color: #0000ff; font-size: 1.5em; font-weight: 800;">Elixir</div>})
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>&nbsp;<span#{elixir_style}>Elixir</span>}
138
+
139
+ expect(two.map {tag_from_object(_1)}.join("&nbsp;"))
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>&nbsp;-&nbsp;<li#{elixir_style}><i>Elixir</i></li>}
149
+
150
+ expect(tags_from_collection(two, tag: :li, before: "<i>", after: "</i>", join: "&nbsp;-&nbsp;"))
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Lab42
4
4
  module TagCloud
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
8
8
  # SPDX-License-Identifier: Apache-2.0
@@ -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.0
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-03 00:00:00.000000000 Z
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.