markdown_titles_to_svg 0.1.1 → 0.1.7

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: 04730d2d939be49a169d9b99eb05af099968131245401fc9a87bc4c791ce8806
4
- data.tar.gz: 398032d4a02f9b254c40be22966672e6b3bcf811e02702f5386620d849202180
3
+ metadata.gz: 5c77f3af5e524ce88627f23c2d5853b236cd069320b785e4b14050c9b9e06378
4
+ data.tar.gz: c662e79b267cf3ec1e132ee10d9f732f03c16fbdfe5673e766b326e0201055c9
5
5
  SHA512:
6
- metadata.gz: 30d457f7ad4932c2fad26fc4e5e5aae7c173d2a7762a226d7041a68f8a61ddcc1eb28411c2ec1f456e17a7c30a4454ee21f6ead4f7e38c0998c143697fec177e
7
- data.tar.gz: 547e57eef58726527b3102718c1507b7c39c8bd14b11a88e42a595215ad51d78104c4fff22c1982b3fba24382cad4c6e9e1b8eeb120f2fdf798e43f08885a490
6
+ metadata.gz: b13d54f1f65209676deec9cca6b40484e826e940fc7c0be82aada3dabc5cc6e24feebbaa5b0e521f13028ed45cc5d9e8b64b2ff2af410b6e7e31177e1d852ce4
7
+ data.tar.gz: 26d3fe2ed3f6bb9dc3c90895d2f5d51c45a0701cb374f795b0f65572399d97fef02391b9c870a74ea88694a9e460372a338d75cc0785e3aa99282793e43132b7
data/CHANGELOG.md CHANGED
@@ -3,3 +3,8 @@
3
3
  ## [0.1.0] - 2021-06-17
4
4
 
5
5
  - Initial release
6
+
7
+ ## [0.1.3] - 2021-06-17
8
+
9
+ - Google Fonts Feature
10
+ - Multiple Headline types
data/README.md CHANGED
@@ -1,10 +1,104 @@
1
- # MarkdownHeadlinesToSvg
1
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/headlines/titles.svg" height="55px" alt="# Markdown Titles to .svg for Ruby">
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/markdown_headlines_to_svg`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Headline Generator for ```Github Markdown``` File to generate beautiful ```Google Fonts``` Headlines.
4
+ <br>
5
+ <br>
6
+ <br>
7
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/headlines/examples.svg" height="55px" alt="Examples">
4
8
 
5
- TODO: Delete this and the text above, and describe your gem
9
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/examples/20.svg" height="45px">
10
+
11
+ ```ruby
12
+ { font__google_fonts__h1__name: "Permanent Marker" }
13
+ ```
14
+
15
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/examples/21.svg" height="45px">
16
+
17
+ ```ruby
18
+ { font__google_fonts__h1__name: "Playfair Display" }
19
+ ```
20
+
21
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/examples/22.svg" height="45px">
22
+
23
+ ```ruby
24
+ { font__google_fonts__h1__name: "Roboto Condensed" }
25
+ ```
26
+
27
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/examples/23.svg" height="45px">
28
+
29
+ ```ruby
30
+ { font__google_fonts__h1__name: "Sarina" }
31
+ ```
32
+
33
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/examples/24.svg" height="45px">
34
+
35
+ ```ruby
36
+ { font__google_fonts__h1__name: "Sonsie One" }
37
+ ```
38
+
39
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/examples/25.svg" height="45px">
40
+
41
+ ```ruby
42
+ { font__google_fonts__h1__name: "Trocchi" }
43
+ ```
44
+
45
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/examples/26.svg" height="45px">
46
+
47
+ ```ruby
48
+ { font__google_fonts__h1__name: "UnifrakturMaguntia" }
49
+ ```
50
+
51
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/examples/27.svg" height="45px">
52
+
53
+ ```ruby
54
+ { font__google_fonts__h1__name: "Zilla Slab Highlight" }
55
+ ```
56
+ <br>
57
+ <br>
58
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/headlines/quickstart.svg" height="55px" alt="Quickstart">
59
+
60
+ ### Single Title
61
+ ```ruby
62
+ require 'markdown_titles_to_svg'
63
+
64
+ svg = MarkdownTitlesToSvg.single(
65
+ 'headline',
66
+ :h1,
67
+ {}
68
+ )
69
+ ```
70
+
71
+
72
+ ### Generate from Github Markdown
73
+ ```ruby
74
+ require 'markdown_titles_to_svg'
75
+
76
+ markdowns = [
77
+ 'https://raw.githubusercontent.com/a6b8/a6b8/main/templates/readme.md'
78
+ ]
79
+
80
+ MarkdownTitlesToSvg.generate(
81
+ markdowns,
82
+ 'a6b8',
83
+ {}
84
+ )
85
+ ```
86
+ <br>
87
+ <br>
88
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/headlines/demo.svg" height="55px" alt="Demo">
89
+
90
+ **A. Implementation**
91
+ > https://raw.githubusercontent.com/a6b8/a6b8/main/README.md
6
92
 
7
- ## Installation
93
+
94
+ **B. Execution**
95
+ > https://github.com/a6b8/a6b8/blob/main/titles.sh
96
+
97
+
98
+
99
+ <br>
100
+ <br>
101
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/headlines/setup.svg" height="55px" alt="Setup">
8
102
 
9
103
  Add this line to your application's Gemfile:
10
104
 
@@ -19,25 +113,214 @@ And then execute:
19
113
  Or install it yourself as:
20
114
 
21
115
  $ gem install markdown_headlines_to_svg
116
+ <br>
117
+ <br>
118
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/headlines/process.svg" height="55px" alt="Process">
22
119
 
23
- ## Usage
120
+ 1. Run Command
121
+ ```txt
122
+ mds = [ PATH_FILE1, PATH_FILE2 ]
123
+ markdown_headlines_to_svg.generate(
124
+ mds,
125
+ "github_profile_name",
126
+ options = {}
127
+ )
24
128
 
25
- TODO: Write usage instructions here
129
+ ```
26
130
 
27
- ## Development
131
+ 2. Prepare (Import) Font
132
+ ``` txt
133
+ :h1 :default
134
+ | |
135
+ | mode | mode
136
+ ---------- ----------
137
+ | | | |
138
+ v v v v
139
+ Local Google Fonts Local
140
+ ```
28
141
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
142
+ 3. Scrape Titles
143
+ ``` txt
30
144
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
145
+ MD_FILE_ 1 QUEUE
146
+ ------------------------------------------------------
147
+ | img src="../a/c/d/1.svg" alt="# Headline 1" ------|------> [ 0 ]
148
+ | |
149
+ | MD_FILE_2 |
150
+ | -----------------------------------------------------
151
+ | | img src="../b/c/d/1.svg" alt="# Headline 2" -----|-> [ 1 ]
152
+ |----| ... |
153
+ | img src="../c/d/e/2.svg" alt="Title 1" ----------|-> [ 2 ]
154
+ | ... |
32
155
 
33
- ## Contributing
156
+ [ 0 ] { text: 'Headline 1', type: :h1, output: '../a/c/d/1.svg' }
157
+ [ 1 ] { text: 'Headline 2', type: :h1, output: '../b/c/d/1.svg' }
158
+ [ 2 ] { text: 'Title 1', type: :default, output: '../c/d/e/2.svg' }
159
+ ```
34
160
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/markdown_headlines_to_svg. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/markdown_headlines_to_svg/blob/master/CODE_OF_CONDUCT.md).
161
+ 4. Add Style and Font Options
36
162
 
37
- ## License
163
+ ``` txt
164
+ default
165
+ + user options
166
+ { |
167
+ type: :h1, ---------------------|------------------
168
+ text: 'Headline 1', | |
169
+ output: '../a/c/d/1.svg', V V
170
+ style: <-------------------- options[ :style ][ :h1 ]
171
+ font: <---------------------- options[ :font ][ :h1 ]
172
+ },
173
+ { ...
38
174
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
175
+ ```
176
+ <br>
177
+ <br>
178
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/headlines/functions.svg" height="55px" alt="Functions">
179
+
180
+ ### .get_options()
181
+ Output all Parameter
182
+ ```ruby
183
+ MarkdownTitlesToSvg.get_options()
184
+
185
+ # => { github: { profile: nil, ...
186
+ ```
187
+
188
+ ### .generate( [], '', {} )
189
+ Generate and store of Titles in all Files
190
+ ```ruby
191
+ MarkdownTitlesToSvg.generate(
192
+ markdowns,
193
+ 'a6b8',
194
+ {}
195
+ )
196
+ ```
197
+
198
+ | **Type** | **Required** | **Description** | **Example** | **Description** |
199
+ |------:|:------|:------|:------|:------|
200
+ | **markdowns** | ```Array (of String)``` | Yes | ```[ '/markdown-titles-to-svg/main/README.md' ]``` | Define List of Markup |
201
+ | **github user name** | ```String``` | Yes | ```'a6b8'``` | Set Github User Name |
202
+ | **options** | ```Hash``` | No | ```'a6b8'``` | Change default options, see "options" for more Information. |
203
+
204
+ ### .single( [], '', {} )
205
+ Generate a single Title and outputs a svg string.
206
+ ```ruby
207
+ svg = MarkdownTitlesToSvg.single(
208
+ 'headline',
209
+ :h1,
210
+ {}
211
+ )
212
+
213
+ # => <svg ...
214
+ ```
40
215
 
41
- ## Code of Conduct
216
+ | **Type** | **Required** | **Description** | **Example** | **Description** |
217
+ |------:|:------|:------|:------|:------|
218
+ | **headline** | ```String``` | Yes | ```'headline'``` | Define List of Markup |
219
+ | **style** | ```Symbol``` | Yes | ```:h1``` | |
220
+ | **options** | ```Hash``` | No | ```{}``` | Change default options, see "options" for more Information. |
42
221
 
43
- Everyone interacting in the MarkdownHeadlinesToSvg project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/markdown_headlines_to_svg/blob/master/CODE_OF_CONDUCT.md).
222
+ <br>
223
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/headlines/options.svg" height="55px" alt="Options">
224
+
225
+ ### Github
226
+ | Nr | Name | Key | Default | Type | Description |
227
+ | :-- | :-- | :-- | :-- | :-- | :-- |
228
+ | A.1. | Source |:github__source | `"https://raw.githubusercontent.com/"` | String | |
229
+
230
+
231
+ ### Font
232
+ | Nr | Name | Key | Default | Type | Description |
233
+ | :-- | :-- | :-- | :-- | :-- | :-- |
234
+ | B.1. | Text_align |:font__text_align | `left` | Symbol | Set aligment of text |
235
+ | B.2. | Bold |:font__bold | `false` | Boolean | Set format of font. If you use Google Fonts try "variant first" |
236
+ | B.3. | Mode H1 |:font__mode__h1 | `:google_fonts` | Symbol | Set mode for Headlines. Choose between :h1 and :google_fonts |
237
+ | B.4. | Mode Default |:font__mode__default | `:google_fonts` | Symbol | Set mode for Titles. Choose between :h1 and :google_font |
238
+
239
+
240
+ #### Import from Local
241
+ | Nr | Name | Key | Default | Type | Description |
242
+ | :-- | :-- | :-- | :-- | :-- | :-- |
243
+ | B.5. | H1 |:font__local__h1 | `"/Library/Fonts/Microsoft/Corbel Bold.ttf"` | String | Set local font for Headline if necessary |
244
+ | B.6. | Default |:font__local__default | `"/Library/Fonts/Microsoft/Consolas.ttf"` | String | String | Set local font for Titles if necessary |
245
+
246
+
247
+ #### Import from "Google Fonts"
248
+ | Nr | Name | Key | Default | Type | Description |
249
+ | :-- | :-- | :-- | :-- | :-- | :-- |
250
+ | B.7. | H1 Name |:font__google_fonts__h1__name | `"Oswald"` | String | Set Google Fonts font name for Headline |
251
+ | B.8. | H1 Variant |:font__google_fonts__h1__variant | `"regular"` | String | Set Google Fonts variant type for headlines |
252
+ | B.9. | H1 Subset |:font__google_fonts__h1__subset | `"latin"` | String | Set Google Fonts subset type for headlines |
253
+ | B.10. | Default Name |:font__google_fonts__default__name | `"Amatic SC"` | String | Set Google Fonts font name for Titles |
254
+ | B.11. | Default Variant |:font__google_fonts__default__variant | `"regular"` | String | Set Google Fonts variant type for titles |
255
+ | B.12. | Default Subset |:font__google_fonts__default__subset | `"latin"` | String | Set Google Fonts subset type for titles |
256
+
257
+ Please use https://google-webfonts-helper.herokuapp.com/fonts to find your favorite Font.
258
+
259
+ ### View
260
+ | Nr | Name | Key | Default | Type | Description |
261
+ | :-- | :-- | :-- | :-- | :-- | :-- |
262
+ | C.1. | Offset Height |:view__offset__height | `0` | Integer | Experimental: Set change View Box height |
263
+ | C.2. | Offset Widht |:view__offset__widht | `0` | Integer | Experimental: Set change View Box width |
264
+
265
+ ### Style
266
+
267
+ #### Headlines
268
+ | Nr | Name | Key | Default | Type | Description |
269
+ | :-- | :-- | :-- | :-- | :-- | :-- |
270
+ | D.1. | Color Opacity |:style__h1__color__opacity | `1.0` | Float | Change Headline color opacity |
271
+ | D.2. | Color Default |:style__h1__color__default | `"#A5834B"` | String | Change Headline fill color |
272
+ | D.3. | Color Palette |:style__h1__color__palette | `[]` | Array | Experimental: Set for each character in headline an other color |
273
+ | D.4. | Stroke Color |:style__h1__stroke__color | `"none"` | String | Change headline fill color of stroke |
274
+ | D.5. | Stroke Width |:style__h1__stroke__width | `"0"` | String | Change headline stroke width |
275
+ | D.6. | Stroke Opacity |:style__h1__stroke__opacity | `1.0` | Float | Change headline stroke opacity |
276
+ | D.7. | Stroke Linecap |:style__h1__stroke__linecap | `"butt"` | String | Change headline stroke width |
277
+
278
+ #### Default
279
+ | Nr | Name | Key | Default | Type | Description |
280
+ | :-- | :-- | :-- | :-- | :-- | :-- |
281
+ | D.8. | Color Opacity |:style__default__color__opacity | `1.0` | Float | Change Title color opacity |
282
+ | D.9. | Color Default |:style__default__color__default | `"#A5834B"` | String | Change Title fill color |
283
+ | D.10. | Color Palette |:style__default__color__palette | `[]` | Array | Experimental: Set for each character in titles an other color |
284
+ | D.11. | Stroke Color |:style__default__stroke__color | `"none"` | String | Change title fill color of stroke |
285
+ | D.12. | Stroke Width |:style__default__stroke__width | `"0"` | String | Change title stroke width |
286
+ | D.13. | Stroke Opacity |:style__default__stroke__opacity | `1.0` | Float | Change title stroke opacity |
287
+ | D.14. | Stroke Linecap |:style__default__stroke__linecap | `"butt"` | String | Change title stroke width |
288
+
289
+ You can find more Information about ```svg``` format here: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/path
290
+
291
+
292
+ ### Other
293
+ | Nr | Name | Key | Default | Type | Description |
294
+ | :-- | :-- | :-- | :-- | :-- | :-- |
295
+ | E.1. | Silent | :silent | `false` | Boolean | Controll console output. |
296
+
297
+ <br>
298
+ <br>
299
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/headlines/limitations.svg" height="55px" alt="Limitations">
300
+
301
+ - Font Types are limited to '.ttf' and '.otf'.
302
+ - Read only Markdown Files from Github.
303
+ <br>
304
+ <br>
305
+
306
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/headlines/contributing.svg" height="55px" alt="Contributing">
307
+
308
+ Bug reports and pull requests are welcome on GitHub at https://github.com/a6b8/statosio-for-wordpress. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/a6b8/statosio/blob/master/CODE_OF_CONDUCT.md).
309
+ <br>
310
+ <br>
311
+ <br>
312
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/headlines/license.svg" height="55px" alt="License">
313
+
314
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
315
+ <br>
316
+ <br>
317
+ <br>
318
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/headlines/code-of-conduct.svg" height="55px" alt="Code of Conduct">
319
+
320
+ Everyone interacting in the Statosio project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/a6b8/markdown-titles-to-svg-for-ruby/blob/master/CODE_OF_CONDUCT.md).
321
+ <br>
322
+ <br>
323
+ <br>
324
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/markdown-titles-to-svg-for-ruby/readme/headlines/support-my-work.svg" height="55px" alt="Support my Work">
325
+
326
+ Donate by [https://www.paypal.com](https://www.paypal.com/donate?hosted_button_id=XKYLQ9FBGC4RG)
@@ -20,37 +20,67 @@ module MarkdownTitlesToSvg
20
20
  },
21
21
  font: {
22
22
  text_align: :left,
23
- bold: true,
24
- local: false,
25
- source: {
26
- local_path: '',
27
- google_fonts: {
28
- name: 'Amatic SC',
23
+ bold: false,
24
+ mode: {
25
+ h1: :google_fonts,
26
+ default: :google_fonts
27
+ },
28
+ local: {
29
+ h1: '/Library/Fonts/Microsoft/Corbel Bold.ttf',
30
+ default: '/Library/Fonts/Microsoft/Consolas.ttf'
31
+ },
32
+ google_fonts: {
33
+ h1: {
34
+ name: 'Oswald',
29
35
  variant: 'regular',
30
- subset: 'latin'
36
+ subset: 'latin'
31
37
  },
32
- current: nil,
38
+ default: {
39
+ name: 'Amatic SC',
40
+ variant: 'regular',
41
+ subset: 'latin'
42
+ }
43
+ },
44
+ current: {
45
+ h1: nil,
46
+ default: nil
33
47
  }
34
48
  },
35
49
  view: {
36
50
  offset: {
37
- height: -800,
51
+ height: 0,
38
52
  widht: 0
39
53
  }
40
54
  },
41
55
  style: {
42
- color: {
43
- opacity: 1.0,
44
- default: '#A5834B',
45
- palette: []
56
+ h1: {
57
+ color: {
58
+ opacity: 1.0,
59
+ default: '#CAD1D8',
60
+ palette: []
61
+ },
62
+ stroke: {
63
+ color: 'none',
64
+ width: '0',
65
+ opacity: 1.0,
66
+ linecap: 'butt'
67
+ }
46
68
  },
47
- stroke: {
48
- color: 'none',
49
- width: '10px',
50
- opacity: 1.0,
51
- linecap: 'butt'
69
+ default: {
70
+ color: {
71
+ opacity: 1.0,
72
+ default: '#CAD1D8',
73
+ palette: []
74
+ },
75
+ stroke: {
76
+ color: 'none',
77
+ width: '0',
78
+ opacity: 1.0,
79
+ linecap: 'butt'
80
+ }
52
81
  }
53
- }
82
+ },
83
+ silent: false
54
84
  }
55
85
 
56
86
 
@@ -59,39 +89,57 @@ module MarkdownTitlesToSvg
59
89
  end
60
90
 
61
91
 
62
- def self.generate( markdowns, gh_name, options = {} )
63
- if self.validate( markdowns, gh_name, options, @TEMPLATE )
92
+ def self.single( headline, type, options = {})
93
+ svg = nil
94
+ if self.validate_single( headline, type, options, @TEMPLATE )
64
95
  obj = self.options_update( options, @TEMPLATE, 'set_options' )
65
- obj[:github][:profile] = gh_name
96
+ obj = self.set_fonts( obj )
66
97
 
67
- if obj[:font][:source][:user].nil?
68
- obj[:font][:source][:current] = obj[:font][:source][:default]
69
- else
70
- obj[:font][:source][:current] = obj[:font][:source][:user]
71
- end
98
+ cmd = {}
99
+ cmd[:headline] = headline
100
+ cmd[:type] = type
101
+ svg = self.svg_generate( cmd, obj )
102
+ end
72
103
 
73
- if obj[:font][:local]
74
- obj[:font][:source][:current] = obj[:font][:source][:local_path]
75
- else
76
- obj[:font][:source][:current] = "./tmp-#{Time.now.getutc.to_i}.ttf"
77
- google_font_download(
78
- obj[:font][:source][:google_fonts][:name],
79
- obj[:font][:source][:google_fonts][:variant],
80
- obj[:font][:source][:google_fonts][:subset],
81
- obj[:font][:source][:current]
82
- )
104
+ obj[:font][:mode].keys.each do | key |
105
+ if obj[:font][:mode][ key ] == :google_fonts
106
+ if ( Time.now.getutc.to_i - obj[:font][:current][ key ].split( '-' )[ 1 ].to_i ) < 30
107
+ if File.basename( obj[:font][:current][ key ] ) .start_with?( key.to_s )
108
+ File.delete( obj[:font][:current][ key ] )
109
+ end
110
+ end
83
111
  end
112
+ end
113
+ return svg
114
+ end
115
+
116
+
117
+ def self.generate( markdowns, gh_name, options = {} )
118
+ if self.validate_generate( markdowns, gh_name, options, @TEMPLATE )
119
+ obj = self.options_update( options, @TEMPLATE, 'set_options' )
120
+ obj[:github][:profile] = gh_name
121
+ obj = self.set_fonts( obj )
84
122
 
85
123
  cmds = self.markdowns_read( markdowns, obj )
124
+
86
125
  root = './'
87
126
  cmds.each do | cmd |
88
- svg = self.svg_generate( cmd[:headline], obj )
127
+ puts cmd
128
+ svg = self.svg_generate( cmd, obj )
89
129
  FileUtils.mkdir_p ( File.dirname( cmd[:path] ) )
90
- File.open( cmd[:path], "w" ) { | f | f.write( svg ) }
130
+ File.open( cmd[:path], 'w' ) { | f | f.write( svg ) }
91
131
  end
92
- end
93
132
 
94
- !obj[:font][:local] ? File.delete( obj[:font][:source][:current] ) : ''
133
+ obj[:font][:mode].keys.each do | key |
134
+ if obj[:font][:mode][ key ] == :google_fonts
135
+ if ( Time.now.getutc.to_i - obj[:font][:current][ key ].split( '-' )[ 1 ].to_i ) < 30
136
+ if File.basename( obj[:font][:current][ key ] ) .start_with?( key.to_s )
137
+ File.delete( obj[:font][:current][ key ] )
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
95
143
 
96
144
  return true
97
145
  end
@@ -100,6 +148,37 @@ module MarkdownTitlesToSvg
100
148
  private
101
149
 
102
150
 
151
+ def self.set_fonts( obj )
152
+ types = obj[:font][:mode].keys
153
+ behaviours = types.map { | key | obj[:font][:mode][ key ] }
154
+
155
+ !obj[:silent] ? puts( 'Used Fonts: ' ) : ''
156
+ behaviours.each.with_index do | behaviour, index |
157
+ t = types[ index ].to_s.length < 3 ? "\t\t" : "\t"
158
+ !obj[:silent] ? print( " :#{types[ index ].to_s}#{t}> " ) : ''
159
+ case behaviour
160
+ when :local
161
+ obj[:font][:current][ types[ index ] ] = obj[:font][:local][ types[ index ] ]
162
+ tmp = File.basename( obj[:font][:current][ types[ index ] ] )
163
+ !obj[:silent] ? print( "#{tmp} (Local)" ) : ''
164
+ when :google_fonts
165
+ obj[:font][:current][ types[ index ] ] = "./#{types[ index ].to_s}-#{Time.now.getutc.to_i}.ttf"
166
+ self.google_font_download(
167
+ obj[:font][:google_fonts][ types[ index ] ][:name],
168
+ obj[:font][:google_fonts][ types[ index ] ][:variant],
169
+ obj[:font][:google_fonts][ types[ index ] ][:subset],
170
+ obj[:font][:current][ types[ index ] ],
171
+ types[ index ],
172
+ obj[:silent]
173
+ )
174
+ end
175
+ !obj[:silent] ? puts : ''
176
+ end
177
+
178
+ return obj
179
+ end
180
+
181
+
103
182
  def self.str_difference( a, b )
104
183
  a = a.to_s.downcase.split( '_' ).join( '' )
105
184
  b = b.to_s.downcase.split( '_' ).join( '' )
@@ -113,7 +192,7 @@ module MarkdownTitlesToSvg
113
192
  end
114
193
 
115
194
 
116
- def self.google_font_download( font, style, subset, file_name )
195
+ def self.google_font_download( font, style, subset, file_name, type, silent )
117
196
  def self.unzip_file( file, destination, file_name )
118
197
  Zip::ZipFile.open( file ) do | zip_file |
119
198
  zip_file.each do | f |
@@ -138,13 +217,13 @@ module MarkdownTitlesToSvg
138
217
  .min_by { | h | h[:score] }
139
218
 
140
219
  font = fonts_subset
141
- .find { | a | a["id"].eql? id[:name] }
220
+ .find { | a | a["id"].eql?( id[:name] ) }
142
221
 
143
222
  variant = font['variants']
144
223
  .map { | a | { name: a, score: self.str_difference( style.to_s, a.to_s ) } }
145
224
  .min_by { | h | h[:score] }
146
225
 
147
- puts "Font: #{font["id"]} #{variant[:name]} (#{subset})"
226
+ !silent ? print( "#{font["id"]} #{variant[:name]} #{subset} (Google Fonts)" ) : ''
148
227
 
149
228
  url = ''
150
229
  url += server
@@ -162,7 +241,53 @@ module MarkdownTitlesToSvg
162
241
  end
163
242
 
164
243
 
165
- def self.validate( markdowns, gh_name, vars, template )
244
+ def self.validate_single( headline, type, vars, template )
245
+ messages = {
246
+ headline:[],
247
+ type:[],
248
+ options:[]
249
+ }
250
+ if headline.class.to_s.eql?( 'String' )
251
+ else
252
+ messages[:headline].push( 'Is not Type "String"')
253
+ end
254
+
255
+ if type.class.to_s.eql?( 'Symbol' )
256
+ if [ :h1, :default ].include? type
257
+ else
258
+ messages[:type].push( 'Input is not :h1 or :default' )
259
+ end
260
+ else
261
+ messages[:type].push( 'Is not Type "Symbol"' )
262
+ end
263
+
264
+ if vars.class.to_s == 'Hash'
265
+ messages[:options] = self.options_update( vars, template, 'check_options' )
266
+ else
267
+ messages[:options].push( 'Is not Type "Hash".')
268
+ end
269
+
270
+
271
+ valid = messages.keys.map { | key | messages[ key ].length }.sum == 0
272
+
273
+ if !valid
274
+ puts 'Following errors occured:'
275
+ messages.keys.each do | key |
276
+ if messages[ key ].length != 0
277
+
278
+ puts " #{key[ 0, 1 ].upcase}#{key[ 1, key.length ]}"
279
+ messages[ key ].each do | m |
280
+ puts " - #{m}"
281
+ end
282
+ end
283
+ end
284
+ end
285
+
286
+ return valid
287
+ end
288
+
289
+
290
+ def self.validate_generate( markdowns, gh_name, vars, template )
166
291
  messages = {
167
292
  markdowns: [],
168
293
  github: [],
@@ -170,8 +295,8 @@ module MarkdownTitlesToSvg
170
295
  other: []
171
296
  }
172
297
 
173
- begin
174
- if markdowns.class.to_s.eql? 'Array'
298
+ #begin
299
+ if markdowns.class.to_s.eql?( 'Array' )
175
300
  if markdowns.map { | a | a.start_with?( template[:github][:source] ) }.all?
176
301
  if markdowns.map { | a | a.end_with?( '.md' ) }.all?
177
302
 
@@ -185,8 +310,8 @@ module MarkdownTitlesToSvg
185
310
  messages[:markdowns].push( 'Is not Type "Array" or "String".' )
186
311
  end
187
312
 
188
- if gh_name.class.to_s.eql? 'String'
189
- if !gh_name.eql? ''
313
+ if gh_name.class.to_s.eql?( 'String' )
314
+ if !gh_name.eql?( '' )
190
315
 
191
316
  else
192
317
  messages[:github].push( "Github Name is required." )
@@ -196,14 +321,14 @@ module MarkdownTitlesToSvg
196
321
  end
197
322
 
198
323
  if vars.class.to_s == 'Hash'
199
- messages[:options] = self.options_update( vars, template, 'options_valid?' )
324
+ messages[:options] = self.options_update( vars, template, 'check_options' )
200
325
  else
201
326
  messages[:options].push( 'Is not Type "Hash".')
202
327
  end
203
328
 
204
- rescue
205
- messages[:other].push( "Undefined error occured.")
206
- end
329
+ #rescue
330
+ #messages[:other].push( "Undefined error occured.")
331
+ #end
207
332
 
208
333
  valid = messages.keys.map { | key | messages[ key ].length }.sum == 0
209
334
 
@@ -225,23 +350,34 @@ module MarkdownTitlesToSvg
225
350
 
226
351
 
227
352
  def self.options_update( vars, template, mode )
228
- allow_list = [
353
+ allow_list = [
354
+ :github__source,
229
355
  :font__text_align,
230
356
  :font__bold,
231
- :font__local,
232
- :font__source__local_path,
233
- :font__source__google_fonts__name,
234
- :font__source__google_fonts__variant,
235
- :font__source__google_fonts__subset,
357
+ :font__mode__h1,
358
+ :font__mode__default,
359
+ :font__google_fonts__h1__name,
360
+ :font__google_fonts__h1__variant,
361
+ :font__google_fonts__h1__subset,
362
+ :font__google_fonts__default__name,
363
+ :font__google_fonts__default__variant,
364
+ :font__google_fonts__default__subset,
236
365
  :view__offset__height,
237
366
  :view__offset__widht,
238
- :style__color__opacity,
239
- :style__color__default,
240
- :style__color__palette,
241
- :style__stroke__color,
242
- :style__stroke__width,
243
- :style__stroke__opacity,
244
- :style__stroke__linecap
367
+ :style__h1__color__opacity,
368
+ :style__h1__color__default,
369
+ :style__h1__color__palette,
370
+ :style__h1__stroke__color,
371
+ :style__h1__stroke__width,
372
+ :style__h1__stroke__opacity,
373
+ :style__h1__stroke__linecap,
374
+ :style__default__color__opacity,
375
+ :style__default__color__default,
376
+ :style__default__color__palette,
377
+ :style__default__stroke__color,
378
+ :style__default__stroke__width,
379
+ :style__default__stroke__opacity,
380
+ :style__default__stroke__linecap,
245
381
  ]
246
382
 
247
383
  messages = []
@@ -274,7 +410,7 @@ module MarkdownTitlesToSvg
274
410
 
275
411
  result = nil
276
412
  case mode
277
- when 'options_valid?'
413
+ when 'check_options'
278
414
  result = messages
279
415
  when 'set_options'
280
416
  result = _options
@@ -301,8 +437,8 @@ module MarkdownTitlesToSvg
301
437
  end
302
438
 
303
439
 
304
- def self.svg_items_decode( str, elements, obj )
305
- def self.svg_item( char, color, element, obj )
440
+ def self.svg_items_decode( cmd, elements, obj )
441
+ def self.svg_item( char, color, element, obj, cmd )
306
442
  item = {
307
443
  "character": nil,
308
444
  "fill": nil,
@@ -317,11 +453,11 @@ module MarkdownTitlesToSvg
317
453
 
318
454
  item[:"character"] = char
319
455
  item[:"fill"] = color
320
- item[:"fill-opacity"] = obj[:style][:color][:opacity]
321
- item[:"stroke"] = obj[:style][:stroke][:color]
322
- item[:"stroke-width"] = obj[:style][:stroke][:width]
323
- item[:"stroke-linecap"] = obj[:style][:stroke][:linecap]
324
- item[:"stroke-opacity"] = obj[:style][:stroke][:opacity]
456
+ item[:"fill-opacity"] = obj[:style][ cmd[:type] ][:color][:opacity]
457
+ item[:"stroke"] = obj[:style][ cmd[:type] ][:stroke][:color]
458
+ item[:"stroke-width"] = obj[:style][ cmd[:type] ][:stroke][:width]
459
+ item[:"stroke-linecap"] = obj[:style][ cmd[:type] ][:stroke][:linecap]
460
+ item[:"stroke-opacity"] = obj[:style][ cmd[:type] ][:stroke][:opacity]
325
461
 
326
462
  [ :"transform", :"d" ].each do | key |
327
463
  search = key.to_s
@@ -333,16 +469,16 @@ module MarkdownTitlesToSvg
333
469
  end
334
470
 
335
471
 
336
- characters = str.gsub( ' ', '' )
472
+ characters = cmd[:headline].gsub( ' ', '' )
337
473
  items = []
338
474
  elements.each.with_index do | element, index |
339
- if obj[:style][:color][:palette].length <= index
340
- color = obj[:style][:color][:default]
475
+ if obj[:style][ cmd[:type] ][:color][:palette].length <= index
476
+ color = obj[:style][ cmd[:type] ][:color][:default]
341
477
  else
342
- color = obj[:style][:color][:palette][ index ]
478
+ color = obj[:style][ cmd[:type] ][:color][:palette][ index ]
343
479
  end
344
480
 
345
- item = self.svg_item( characters[ index ], color, element, obj )
481
+ item = self.svg_item( characters[ index ], color, element, obj, cmd )
346
482
  items.push( item )
347
483
  end
348
484
  return items
@@ -381,16 +517,16 @@ module MarkdownTitlesToSvg
381
517
  end
382
518
 
383
519
 
384
- def self.svg_generate( str, obj )
520
+ def self.svg_generate( cmd, obj )
385
521
  svg = Text2svg(
386
- str,
387
- font: obj[:font][:source][:current],
522
+ cmd[:headline],
523
+ font: obj[:font][:current][ cmd[:type] ],
388
524
  text_align: obj[:font][:text_align],
389
525
  bold: obj[:font][:bold]
390
526
  ).to_s
391
527
 
392
528
  elements = self.svg_elements( svg )
393
- items = self.svg_items_decode( str, elements, obj )
529
+ items = self.svg_items_decode( cmd, elements, obj )
394
530
  code = self.svg_create_code( items, svg, obj )
395
531
  return code
396
532
  end
@@ -406,10 +542,11 @@ module MarkdownTitlesToSvg
406
542
  doc = Nokogiri::HTML( response )
407
543
  doc.xpath( '//img' ).each do | element |
408
544
  begin
409
- if !element.attribute( 'banner' ).nil?
545
+ if !element.attribute( 'alt' ).nil?
410
546
  validation = "#{obj[:github][:source]}#{obj[:github][:profile]}/"
411
547
  cmd = {
412
548
  headline: nil,
549
+ type: nil,
413
550
  src: nil,
414
551
  file: nil,
415
552
  path: nil
@@ -421,8 +558,11 @@ module MarkdownTitlesToSvg
421
558
  if cmd[:src].start_with?( validation )
422
559
  if cmd[:src].end_with?( '.svg' )
423
560
  if url =~ URI::regexp
424
- cmd[:headline] = element.attribute( 'banner' ).value
425
-
561
+ cmd[:headline] = element.attribute( 'alt' ).value
562
+
563
+ cmd[:type] = cmd[:headline].count( '#' ) == 0 ? :default : :h1
564
+ cmd[:headline] = cmd[:headline].gsub( '#', '' ).strip
565
+
426
566
  tmp = cmd[:src][ cmd[:src].index( validation ) + validation.length, cmd[:src].length ]
427
567
  tmp = tmp
428
568
  .split( '/' )
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MarkdownTitlesToSvg
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.7"
5
5
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown_titles_to_svg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - a6b8
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-18 00:00:00.000000000 Z
11
+ date: 2021-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: text2svg
@@ -101,6 +101,7 @@ files:
101
101
  - bin/setup
102
102
  - lib/markdown_titles_to_svg.rb
103
103
  - lib/markdown_titles_to_svg/version.rb
104
+ - markdown_titles_to_svg-0.1.6.gem
104
105
  - markdown_titles_to_svg.gemspec
105
106
  homepage: https://github.com/a6b8/markdown-titles-to-svg-for-ruby
106
107
  licenses: