class_maker_gyazz 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/Gemfile +2 -0
- data/lib/class_maker_gyazz/version.rb +1 -1
- data/lib/class_maker_gyazz.rb +43 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 020d29b40b25cde3b1999484cc9f30833c9f0359
|
4
|
+
data.tar.gz: bbae2e2b659b1edb95b1bdfe525e95c913ce9ef1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40121df23fbbe25ef1f3123ef3be83dae0d16ad7616faa40fc661f72ca0f0925e53a3c82ce14972a6e76c0780c031328f6a2cc783eff9211ffdfff1f7073318f
|
7
|
+
data.tar.gz: 3f553cb3a88a5dbed3c4bbdd9560a076c4d7f70c32eacac7b1f3c38d1a35a9568b066fe94a08f5f653add88868e2ca09544e66bc871e039c0204dfd54335333c
|
data/Gemfile
CHANGED
data/lib/class_maker_gyazz.rb
CHANGED
@@ -7,10 +7,9 @@ module ClassMakerGyazz
|
|
7
7
|
attr_accessor :html
|
8
8
|
|
9
9
|
def initialize text
|
10
|
-
before_depth
|
10
|
+
before_depth = current_depth = next_depth = 0
|
11
11
|
rows = text.split("\n")
|
12
12
|
html = rows.map.with_index do |m, i|
|
13
|
-
puts "current #{current_depth}, next_depth #{next_depth}, before_depth #{before_depth}"
|
14
13
|
prefix = "<li>"
|
15
14
|
suffix = "</li>"
|
16
15
|
current_depth = m.length - m.lstrip.length
|
@@ -19,10 +18,51 @@ module ClassMakerGyazz
|
|
19
18
|
prefix = "<ul><li>" if before_depth < current_depth # nest start
|
20
19
|
suffix = "#{suffix}#{'</li></ul>' * (current_depth - next_depth)}" if current_depth > next_depth # nest end
|
21
20
|
before_depth = current_depth
|
22
|
-
|
21
|
+
tag, end_tag = text_tag(m, current_depth, next_depth)
|
22
|
+
"#{prefix}#{tag}#{check_text(m)}#{end_tag}#{suffix}"
|
23
23
|
end
|
24
24
|
@html = "<ul>#{html.join}</ul>"
|
25
25
|
end
|
26
|
+
|
27
|
+
def text_tag text, current_depth, next_depth
|
28
|
+
if current_depth == 0
|
29
|
+
tag = is_img?(text) ? "<h2>" : "<h2 class='page-header'>"
|
30
|
+
end_tag = "</h2>"
|
31
|
+
return tag, end_tag
|
32
|
+
elsif current_depth == 1
|
33
|
+
tag = "<blockquote><p>"
|
34
|
+
end_tag = "</p></blockquote>"
|
35
|
+
return tag, end_tag
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def check_text text
|
40
|
+
if is_img?(text)
|
41
|
+
text = "<img class='img-thumbnail' src='#{clean_brackets(text)}'>"
|
42
|
+
elsif text =~ /\[\[\[.*\]\]\]/
|
43
|
+
text = "<strong>#{text}</strong>"
|
44
|
+
text = check_link(clean_brackets(text))
|
45
|
+
elsif text =~ /\[\[.*\]\]/
|
46
|
+
text = check_link(clean_brackets(text))
|
47
|
+
end
|
48
|
+
text
|
49
|
+
end
|
50
|
+
|
51
|
+
def check_link text
|
52
|
+
if text =~ /(http|https)\:\/\/\w.*/
|
53
|
+
text = "#{text.gsub($&,"")}<a href='#{$&}'>#{$&}</a>"
|
54
|
+
end
|
55
|
+
text
|
56
|
+
end
|
57
|
+
|
58
|
+
def is_img? text
|
59
|
+
text =~ /\[\[(http|https)\:\/\/\w.*(png|jpg|jpeg|gif)\]\]/
|
60
|
+
end
|
61
|
+
|
62
|
+
def clean_brackets text
|
63
|
+
text.gsub(/(\[\[\[|\]\]\])/, "").gsub(/(\[\[|\]\])/, "")
|
64
|
+
end
|
65
|
+
|
26
66
|
end
|
27
67
|
|
28
68
|
end
|