booklab-sml 0.2.1 → 0.2.2

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: d7221135ee40e21ca054073ec862e70f9f298b858a47254cabc978fd5b1b2ea1
4
- data.tar.gz: b0aa1e7faaba0780cd2ac13a02d4247f5ed76a980ed4a5874f7084afe95336aa
3
+ metadata.gz: 185f05ba4b7c2f499267560d5f7d7a9afb090f2283815b8ec477491fe95b3589
4
+ data.tar.gz: 3266ed391058555f8d38a5551170199e751363e5d8f9c58ade854be4657f495a
5
5
  SHA512:
6
- metadata.gz: 8e924228f106d6885dce973fdb0a9abf97f1171ebeefd829529424a161627ffafefacbb56d448c5bd441d2605c9bf53aa429ea94e8a369d40b2abc8824feef92
7
- data.tar.gz: f673b5dcffe277844ccd491b93c26919e6ffdc7076610ef138bfa2335eb7ff74deb44ca2eb4f9b3a07a8d4f5c59a5221f4d87c57fc4fa800fc3ced60e55df067
6
+ metadata.gz: dcb794b686118b2879af4c8ffd9ede6e021c030051574364d68ece9eb5aa8b1e4ae60569441b0714097b2d32ac65b95e2ecb43b20316621c967a93855ec989b7
7
+ data.tar.gz: 15cdeff70e66a0572c240b991e39635178501cd44be16d35909c2e5853c2a8a6f87d0a45331fd52a0972cefe3c1b63c97fb2779c92b95779b9240488cb3b11f5
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # BookLab::SML
2
2
 
3
- *SML* is a document format base on [JsonML](http://jsonml.org).
3
+ [![CircleCI](https://circleci.com/gh/huacnlee/booklab-sml/tree/master.svg?style=shield&circle-token=231806e2ce24e58a85190a0cd167b7d2da27c0b9)](https://circleci.com/gh/huacnlee/booklab-sml/tree/master)
4
+
5
+ SML __(Slate markup language)__ is a rich text format for describe of the BookLab rich contents.
6
+
7
+ It base on [JsonML](http://jsonml.org) format, and including custom DSL.
4
8
 
5
9
  ## Usage
6
10
 
@@ -11,10 +15,11 @@ gem "booklab-sml"
11
15
  and then run `bundle install`
12
16
 
13
17
  ```rb
14
- $ ml = %(["html", { lang: "en" }, ["body", ["p", "Hello world"]]])
15
- $ puts BookLab::SML.parse(ml)
16
- => <html lang="en"><body><p>Hello world</p></body></html>
18
+ $ sml = %(["p", { align: "center", indent: 1 }, "Hello world"])
19
+ $ BookLab::SML.parse(sml)
20
+ => <p style="text-align: center; text-indent: 32px;">Hello world</p>
17
21
  ```
18
22
 
19
23
  ## License
24
+
20
25
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -37,7 +37,7 @@ module BookLab::SML
37
37
  prev_node = idx > 0 ? children[idx - 1] : nil
38
38
  next_node = idx < children.length ? children[idx + 1] : nil
39
39
 
40
- node_to_html(child, { prev: prev_node, next: next_node })
40
+ node_to_html(child, prev: prev_node, next: next_node)
41
41
  end.join("")
42
42
  end
43
43
  end
@@ -34,13 +34,18 @@ module BookLab::SML::Rules
34
34
  if attrs[:indent]
35
35
  style["text-indent"] = "#{4 * INDENT_PX}px"
36
36
  end
37
- props = styleize(style)
37
+ props = css_attrs(style)
38
38
  return "" if props.strip.blank?
39
39
  %( style="#{props}")
40
40
  end
41
41
 
42
- def self.styleize(style)
42
+ def self.css_attrs(style)
43
43
  style.map { |k, v| "#{k}: #{v};" }.join(" ")
44
44
  end
45
+
46
+ def self.html_attrs(attrs)
47
+ props = attrs.map { |k, v| v.present? ? %(#{k}="#{v}") : nil }.compact.join(" ")
48
+ %( #{props})
49
+ end
45
50
  end
46
51
  end
@@ -25,9 +25,9 @@ module BookLab::SML::Rules
25
25
  level = attrs[:level] || 1
26
26
  num = (attrs[:num] || 0) + 1
27
27
 
28
- style_attrs = style_for_attrs(attrs, {
28
+ style_attrs = style_for_attrs(attrs,
29
29
  "padding-left": "#{indent_left * INDENT_PX}px"
30
- })
30
+ )
31
31
 
32
32
  wrap_tag = list_type == "bulleted" ? "ul" : "ol"
33
33
 
@@ -73,7 +73,9 @@ module BookLab::SML::Rules
73
73
  li_item += "\n"
74
74
  end
75
75
  else
76
- li_item += "</li></#{wrap_tag}>"
76
+ (level - 1 + 1).times do
77
+ li_item += "</li></#{wrap_tag}>"
78
+ end
77
79
  end
78
80
 
79
81
  outs << li_item
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BookLab::SML::Rules
4
+ class Video < Base
5
+ def self.match?(node)
6
+ tag_name(node) == "video"
7
+ end
8
+
9
+ def self.to_html(node, opts = {})
10
+ attrs = attributes(node)
11
+
12
+ return "" if attrs[:src].blank?
13
+
14
+ video_attrs = html_attrs({
15
+ width: attrs[:width],
16
+ height: attrs[:height]
17
+ })
18
+
19
+ out = <<~HTML
20
+ <video controls preload="no"#{video_attrs}>
21
+ <source src="#{attrs[:src]}" type="#{attrs[:type]}">
22
+ </video>
23
+ HTML
24
+
25
+ out
26
+ end
27
+ end
28
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module BookLab
4
4
  module SML
5
- VERSION = "0.2.1"
5
+ VERSION = "0.2.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: booklab-sml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
@@ -52,7 +52,8 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: "*SML* is a document format base on [JsonML](http://jsonml.org)."
55
+ description: SML is a rich text format for describe of the BookLab rich contents,
56
+ base on [JsonML](http://jsonml.org).
56
57
  email:
57
58
  - huacnlee@gmail.com
58
59
  executables: []
@@ -87,6 +88,7 @@ files:
87
88
  - lib/booklab/sml/rules/td.rb
88
89
  - lib/booklab/sml/rules/text.rb
89
90
  - lib/booklab/sml/rules/tr.rb
91
+ - lib/booklab/sml/rules/video.rb
90
92
  - lib/booklab/sml/utils.rb
91
93
  - lib/booklab/sml/version.rb
92
94
  homepage: https://github.com/huacnlee/booklab-sml
@@ -108,8 +110,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
110
  - !ruby/object:Gem::Version
109
111
  version: '0'
110
112
  requirements: []
111
- rubygems_version: 3.0.1
113
+ rubyforge_project:
114
+ rubygems_version: 2.7.8
112
115
  signing_key:
113
116
  specification_version: 4
114
- summary: SML is a document format base on JsonML
117
+ summary: SML is a rich text format for describe of the BookLab rich contents.
115
118
  test_files: []