jekyll-kw-loremipsum 0.1.1 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2cb333d4e45fe1ad3019e414349461bc8706d3eb62c1dbae69578b84b0b63670
4
- data.tar.gz: 689bf48ab2676386c81066622078f19e4ccb05d3bda19cf520c0a926117e31ab
3
+ metadata.gz: 6f6f928108ad428d1e65607f5db0cf4ea4966d088f3da19ccfb1ba1fcfd9101c
4
+ data.tar.gz: 4d11cf15ff57e97e5a164232d305aec10b467d1884b587923965609e620b63bc
5
5
  SHA512:
6
- metadata.gz: 4bab01269a3824e700187cdeffd9f80c2ec613a7aa96b085534ac006ea368afd2e4cb4ceff5094e4131899733e43ff0e5e25c1269e8a7fe73ed054d64980aad1
7
- data.tar.gz: 231056200d765f0046308c330871a7047d800da5f4af8d05fb73507eb146e500981bb94fd09d0b7c88c4b1c6d571a288183c43b913c649602b1f75fe354982bc
6
+ metadata.gz: 8bfc9397c1f00d219b3f6c4815ae3f55b187ef0a5d9533aeb9bd2eced4e94d5c94f9a339d62e254c5760fcacd2420551a0849f3c7840f29a20f729d2d0bc22c7
7
+ data.tar.gz: 18c1889e78fcff4f988d8bc54713cc0bf6e704fd575348ad67ff670eaf197ddf20efd4dfd9e0548fd1421065c68a16fd1da4c1249fdee1dcc90fd5d22bb10d56
data/lib/Song.rb ADDED
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KargWare
4
+ # A class Song for music
5
+ class Song
6
+ attr_reader :name, :artist, :duration
7
+
8
+ # attr_reader :name, :artist
9
+
10
+ def initialize(name, artist, duration)
11
+ @name = name
12
+ @artist = artist
13
+ @duration = duration
14
+ end
15
+
16
+ def to_s
17
+ # format('%s (%s) [ %s ]', @name, @artist, @duration)
18
+ "#{@name} (#{@artist}) [ #{@duration} ]"
19
+ end
20
+
21
+ def echo
22
+ puts to_s
23
+ end
24
+ end
25
+ end
@@ -23,9 +23,7 @@ module Jekyll
23
23
  @my_string = options['my_string']
24
24
  end
25
25
 
26
- private
27
-
28
- def generate_option_hash(options)
26
+ private def generate_option_hash(options)
29
27
  DEFAULT_CONFIG.merge(options)
30
28
  rescue TypeError
31
29
  DEFAULT_CONFIG
@@ -1,77 +1,48 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'jekyll-kw-loremipsum/parser_parameter'
4
+
3
5
  module Jekyll
4
6
  module KargWare
5
7
  module LoremIpsum
6
8
  # LoremIpsum parser class
7
9
  class Parser
8
- # https://loremipsum.de/downloads/original.txt
9
- @@words_lorem_ipsum = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat. Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
10
- # @@words_lorem_ipsum = "Lorem ipsum dolor sit amet, consetetur sadipscing"
11
-
12
- @@arr_words_lorem_ipsum = nil
13
- def self.arr_words_lorem_ipsum
14
- if @@arr_words_lorem_ipsum == nil
15
- @@arr_words_lorem_ipsum = @@words_lorem_ipsum.split(" ")
16
- end
17
- @@arr_words_lorem_ipsum
18
- end
19
-
20
- def self.get_words(cnt, random=false)
21
- if random
22
- arr_part = self.arr_words_lorem_ipsum.sample(cnt)
23
- else
24
- arr_part = self.arr_words_lorem_ipsum.slice(0, cnt)
25
- end
10
+ attr_reader :config
26
11
 
27
- arr_part.join(" ").chomp(",")
28
- end
12
+ ARR_WORDS_LOREM_IPSUM = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat. Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.'.split.freeze
29
13
 
30
- def initialize(config)
31
- @config = config
14
+ def self.get_words(cnt, random = false)
15
+ arr_part = random ? ARR_WORDS_LOREM_IPSUM.sample(cnt) : ARR_WORDS_LOREM_IPSUM.slice(0, cnt)
32
16
 
33
- match_parameters(@config)
17
+ arr_part.join(' ').chomp(',')
34
18
  end
35
19
 
36
- def match_parameters(str)
37
- # 1w == 1 word (default 40)
38
- @words = 40
39
- # 3p == 3 paragraphs (default -1)
40
- # 7miw == 7 Min words in para (default 40)
41
- # 15maw == 15 Max words in para (default 40)
42
- @paras = -1
43
- @minw = 40
44
- @maxw = 40
45
- # random == Should the words be random (or ordered) (default false)
46
- @random = false
47
-
48
- matched_words = str.strip.match(/\d+w/)
49
- matched_paras = str.strip.match(/\d+p/)
50
- matched_minw = str.strip.match(/\d+miw/)
51
- matched_maxw = str.strip.match(/\d+maw/)
52
- matched_random = str.strip.match(/random/)
53
-
54
- # puts "Parser: W: %s P: %s MiW: %s MaW: %s Random: $s" % [matched_words, matched_paras, matched_minw, matched_maxw, matched_random]
55
-
56
- @words = matched_words[0].strip.sub("w", "").to_i if matched_words
57
- @paras = matched_paras[0].strip.sub("p", "").to_i if matched_paras
58
- @minw = matched_minw[0].strip.sub("miw", "").to_i if matched_minw
59
- @maxw = matched_maxw[0].strip.sub("maw", "").to_i if matched_maxw
60
- @random = true if matched_random
20
+ def self.create_parameters(input)
21
+ parameters = ParserParameter.new
22
+ parameters.init(input)
23
+ parameters
61
24
  end
62
25
 
63
- def echo_config
64
- puts "%s (%s) - W: %04d P: %04d MiW: %04d MaW: %04d" % [@paras == -1 ? "Words" : "Paras", @random, @words, @paras, @minw, @maxw]
26
+ def initialize(options = {})
27
+ @config = Jekyll::KargWare::LoremIpsum::Configuration.new(options)
65
28
  end
66
29
 
67
- def get_lorem_ipsum
68
- if @paras == -1
69
- Jekyll::KargWare::LoremIpsum::Parser.get_words(@words, @random)
30
+ # TODO: Fucntion "get_lorem_ipsum" should be parse
31
+ def get_lorem_ipsum(input)
32
+ parameters = Jekyll::KargWare::LoremIpsum::Parser.create_parameters(input)
33
+
34
+ if parameters.use_words
35
+ Jekyll::KargWare::LoremIpsum::Parser.get_words(parameters.words, parameters.random)
70
36
  else
71
- arr_oneliner = Array.new
72
- for i in 1..@paras
73
- r = rand(@minw..@maxw)
74
- arr_oneliner += [Jekyll::KargWare::LoremIpsum::Parser.get_words(r, @random)]
37
+ arr_oneliner = []
38
+ # for i in 1..parameters.paras
39
+ # r = rand(parameters.minw..parameters.maxw)
40
+ # arr_oneliner += [Jekyll::KargWare::LoremIpsum::Parser.get_words(r, parameters.random)]
41
+ # end
42
+
43
+ (1..parameters.paras).each do
44
+ r = rand(parameters.minw..parameters.maxw)
45
+ arr_oneliner += [Jekyll::KargWare::LoremIpsum::Parser.get_words(r, parameters.random)]
75
46
  end
76
47
  # arr_oneliner.join("\n") # No line wrap
77
48
  # arr_oneliner.join("<br>") # OK, but no 2nd p
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module KargWare
5
+ module LoremIpsum
6
+ # Parameters for parser class
7
+ class ParserParameter
8
+ attr_reader :words, :paras, :minw, :maxw, :random
9
+
10
+ def initialize
11
+ super
12
+
13
+ # 1w == 1 word (default 40)
14
+ @words = 40
15
+ # 3p == 3 paragraphs (default 1)
16
+ # 7miw == 7 Min words in para (default 40)
17
+ # 15maw == 15 Max words in para (default 40)
18
+ @paras = 1
19
+ @minw = 40
20
+ @maxw = 40
21
+ # random == Should the words be random (or ordered) (default false)
22
+ @random = false
23
+ end
24
+
25
+ def init(parameters = nil)
26
+ return if parameters.nil?
27
+
28
+ # TODO: Min > Max --> Warning
29
+ # TODO: unkown words, e.g. "p, word, min, max" --> Warning
30
+
31
+ matched_words = parameters.strip.match(/\d+w/)
32
+ matched_paras = parameters.strip.match(/\d+p/)
33
+ matched_minw = parameters.strip.match(/\d+miw/)
34
+ matched_maxw = parameters.strip.match(/\d+maw/)
35
+ matched_random = parameters.strip.match(/random/)
36
+
37
+ # puts "Parser: W: %s P: %s MiW: %s MaW: %s Random: $s" % [matched_words, matched_paras, matched_minw, matched_maxw, matched_random]
38
+
39
+ @words = matched_words[0].strip.sub('w', '').to_i if matched_words
40
+ @paras = matched_paras[0].strip.sub('p', '').to_i if matched_paras
41
+ @minw = matched_minw[0].strip.sub('miw', '').to_i if matched_minw
42
+ @maxw = matched_maxw[0].strip.sub('maw', '').to_i if matched_maxw
43
+ @random = true if matched_random
44
+ end
45
+
46
+ def to_str_random
47
+ @random ? 'random' : 'sorted'
48
+ end
49
+
50
+ def use_words
51
+ @paras.nil? || @paras == 1
52
+ end
53
+
54
+ def use_paragraphs
55
+ !use_words
56
+ end
57
+
58
+ def to_s
59
+ if use_words
60
+ format(
61
+ 'W: %<amount_words>04d (%<random_or_sorted>s)',
62
+ amount_words: @words,
63
+ random_or_sorted: to_str_random
64
+ )
65
+ else
66
+ format(
67
+ 'P: %<amount_paragraphs>04d (%<random_or_sorted>s) MiW: %<min_per_paragraph>04d MaW: %<max_per_paragraph>04d',
68
+ amount_paragraphs: @paras,
69
+ random_or_sorted: to_str_random,
70
+ min_per_paragraph: @minw,
71
+ max_per_paragraph: @maxw
72
+ )
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -4,7 +4,8 @@ module Jekyll
4
4
  module KargWare
5
5
  module LoremIpsum
6
6
  RUBYGEM_NAME = 'jekyll-kw-loremipsum'
7
- VERSION = '0.1.1'
7
+ VERSION = '0.2.2'
8
+ JEKYLL_TAGNAME = 'kw_lorem_ipsum'
8
9
  end
9
10
  end
10
11
  end
@@ -1,30 +1,45 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'jekyll-kw-loremipsum/configuration'
4
+ require 'jekyll-kw-loremipsum/parser'
5
+ require 'jekyll-kw-loremipsum/version'
6
+
3
7
  module Jekyll
4
8
  module KargWare
9
+ # LoremIpsum a Jekyll PlugIn inside `Jekyll::KargWare`
5
10
  module LoremIpsum
6
11
  class Error < StandardError; end
7
12
  class Exception < Gem::Exception; end
8
13
 
14
+ module_function def get_plugin_config(context)
15
+ if defined? context.registers[:site].config
16
+ context.registers[:site].config[Jekyll::KargWare::LoremIpsum::RUBYGEM_NAME] || {}
17
+ else
18
+ {}
19
+ end
20
+ end
21
+
22
+ # LoremIpsum tag {% kw_lorem_ipsum input %} for Jekyll
9
23
  class LoremIpsumTag < Liquid::Tag
10
24
  # safe true
11
25
  # priority :low
12
26
 
13
- def initialize(tag_name, text, tokens)
27
+ def initialize(tag_name, input, tokens)
14
28
  super
15
- @text = text.strip
16
- tokens = tokens
17
-
18
- @parser = Jekyll::KargWare::LoremIpsum::Parser.new(@text)
19
- # @parser.echo_config
29
+ @input = input.to_s.strip
20
30
  end
21
31
 
22
32
  def render(context)
23
- @parser.get_lorem_ipsum
33
+ parser = Jekyll::KargWare::LoremIpsum::Parser.new(
34
+ Jekyll::KargWare::LoremIpsum.get_plugin_config(context)
35
+ )
36
+
37
+ # parser = Jekyll::KargWare::LoremIpsum::Parser.new(@input)
38
+ parser.get_lorem_ipsum(@input)
24
39
  end
25
40
  end
26
41
  end
27
42
  end
28
43
  end
29
44
 
30
- Liquid::Template.register_tag('kw_lorem_ipsum', Jekyll::KargWare::LoremIpsum::LoremIpsumTag)
45
+ Liquid::Template.register_tag(Jekyll::KargWare::LoremIpsum::JEKYLL_TAGNAME, Jekyll::KargWare::LoremIpsum::LoremIpsumTag)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-kw-loremipsum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Karg
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-03-20 00:00:00.000000000 Z
12
+ date: 2022-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll
@@ -43,9 +43,11 @@ extensions: []
43
43
  extra_rdoc_files: []
44
44
  files:
45
45
  - README.md
46
+ - lib/Song.rb
46
47
  - lib/jekyll-kw-loremipsum.rb
47
48
  - lib/jekyll-kw-loremipsum/configuration.rb
48
49
  - lib/jekyll-kw-loremipsum/parser.rb
50
+ - lib/jekyll-kw-loremipsum/parser_parameter.rb
49
51
  - lib/jekyll-kw-loremipsum/version.rb
50
52
  homepage: https://notes.n13.org/rubygems
51
53
  licenses: