gibier 0.8.5 → 0.8.6

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
  SHA1:
3
- metadata.gz: 8501bdb9a9462925866e3bd93a20be7c494bee91
4
- data.tar.gz: 5e74f6e9c6e209bfd5681eb4808e145217036f01
3
+ metadata.gz: 5e1e19e5b708b1d18ac1a3fd54aaf5ebd49fd4c6
4
+ data.tar.gz: 22554ca8386ddd1cca524844cb7cbe278c575448
5
5
  SHA512:
6
- metadata.gz: e53fc360d58222ddd618af55f5d16f96998b232dbf8aa5caec217ac6accc29e64939cd043ff3ab5614e90e4d3d3e702f00637d2b70a12dba6234f0bcda864d80
7
- data.tar.gz: 97ed8eb82a5f04d767c0ed530e417dd30da0efcb83dd94a9f64f31353f5cfa9ed5b7d1be68d9dcb8045017cc6c603d22a24d6e0fa1487ff35a4d93335f6e0c1d
6
+ metadata.gz: b5b35b215e15116e1be7d5d1313c86c87d19e28f2740179bb6f613079d392c2c3fc0e7062ecc99ab166d9344d429fc2fc46803cc6c1091f7dee9b1244b56ac3a
7
+ data.tar.gz: f4668c4cb8bfdb1b1077bb2f307f5839249a24c468c4e51db7e6c1f106245f60c0d3ca9bdaf3eab7258f5318c6383970aca028601f17a600f6e7b1cac06dce1f
@@ -4,16 +4,19 @@ require 'redcarpet'
4
4
 
5
5
  class String
6
6
  def escape
7
- if self =~ /<a>(.*)<\/a>/
8
- "a(#{$1})"
9
- elsif self =~ /<p>(.*)<img>(.*)<\/img><\/p>/
10
- "p(#{$1}, img(#{$2}))"
11
- elsif self =~ /<div>(.*)<\/div>/
12
- "div(#{$1})"
13
- elsif self =~ /<strong>(.*)<\/strong>/
14
- "strong(nil, \"#{$1}\")"
7
+ "\"#{self.gsub(/\"/, "\\\"").gsub(/\\/, "\\\\")}\""
8
+ end
9
+
10
+ def expand_tag
11
+ m = /\A(?<head>.*?)(?<body><(?<tag>\w+)( (?<attrs>{(\w+:.+?)(, \w:.+?)*}))?>(?<inner>.*?)<\/\k<tag>>)(?<tail>.*?)\z/.match(self)
12
+ if m
13
+ arr = []
14
+ arr << m[:head].escape unless m[:head].empty?
15
+ arr << "#{m[:tag]}(#{m[:attrs] || "nil"}, #{m[:inner].expand_tag})" unless m[:body].empty?
16
+ arr << m[:tail].expand_tag unless m[:tail].empty?
17
+ arr.join(',')
15
18
  else
16
- "\"#{self.gsub(/\"/, "\\\"").gsub(/\\/, "\\\\")}\""
19
+ self.escape
17
20
  end
18
21
  end
19
22
  end
@@ -99,7 +102,7 @@ EOD
99
102
  clear_list_state
100
103
 
101
104
  if header_level > 3
102
- return " children << h#{header_level}(nil, #{text.escape})\n"
105
+ return " children << h#{header_level}(nil, #{text.expand_tag})\n"
103
106
  end
104
107
 
105
108
  "".tap do |result|
@@ -126,7 +129,7 @@ EOD
126
129
  <<EOD
127
130
  class Gibier::Page#{@page_count} < Gibier::PageBase
128
131
  def header
129
- h#{header_level}(nil, #{text.escape})
132
+ h#{header_level}(nil, #{text.expand_tag})
130
133
  end
131
134
 
132
135
  def content
@@ -151,11 +154,11 @@ EOD
151
154
  def list_item(item, orderd)
152
155
  "".tap do |result|
153
156
  if item =~ /.*\n +children << /
154
- result << item.sub(/(.*)\n +children << /) { " li(nil, #{$1.strip.escape}),\n " }.rstrip
157
+ result << item.sub(/(.*)\n +children << /) { " li(nil, #{$1.strip.expand_tag}),\n " }.rstrip
155
158
  result << ",\n"
156
159
  @enter_list = false
157
160
  else
158
- result << " li(nil, #{item.strip.escape}),\n"
161
+ result << " li(nil, #{item.strip.expand_tag}),\n"
159
162
  end
160
163
  end
161
164
  end
@@ -171,12 +174,12 @@ EOD
171
174
 
172
175
  def link(link, title, content)
173
176
  link or return
174
- "<a>{href: #{link.escape}, target: \"_blank\"}, #{content.escape}</a>"
177
+ "<a {href:#{link.escape}, target:\"_blank\"}>#{content}</a>"
175
178
  end
176
179
 
177
180
  def image(link, title, alt_text)
178
181
  href = "\#{Gibier.assets_path}/images/#{link}"
179
- "<p>{class: \"#{alt_text}\"}<img>{src: #{href.escape}}</img></p>"
182
+ "<p {class:\"#{alt_text}\"}><img {src:#{href.escape}}></img></p>"
180
183
  end
181
184
 
182
185
  def block_code(code, language)
@@ -213,9 +216,9 @@ EOD
213
216
  if text[0] == '%'
214
217
  class_name = text[1...text.index(':')]
215
218
  lines[0] = lines.first[(lines.first.index(':') + 1)...lines.first.length].lstrip
216
- " children << p({className:\"#{class_name}\"}, #{lines.map{|l| l.escape}.join(',Hyalite.create_element(\'br\'),')})\n"
219
+ " children << p({className:\"#{class_name}\"}, #{lines.map{|l| l.expand_tag}.join(',Hyalite.create_element(\'br\'),')})\n"
217
220
  else
218
- " children << p(nil, #{lines.map{|l| l.escape}.join(',Hyalite.create_element(\'br\'),')})\n"
221
+ " children << p(nil, #{lines.map{|l| l.expand_tag}.join(',Hyalite.create_element(\'br\'),')})\n"
219
222
  end
220
223
  end
221
224
 
@@ -1,3 +1,3 @@
1
1
  module Gibier
2
- VERSION = "0.8.5"
2
+ VERSION = "0.8.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gibier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - youchan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-21 00:00:00.000000000 Z
11
+ date: 2017-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -264,7 +264,7 @@ files:
264
264
  - lib/gibier.rb
265
265
  - lib/gibier/cli.rb
266
266
  - lib/gibier/haml_helper.rb
267
- - lib/gibier/render.rb
267
+ - lib/gibier/renderer.rb
268
268
  - lib/gibier/slide_helper.rb
269
269
  - lib/gibier/slide_loader.rb
270
270
  - lib/gibier/static_generator.rb