booklab-sml 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: eb84a4a2755b03fb16c63b38f4ab28f43da86969d804ee410b7528a2583253c6
4
+ data.tar.gz: 8f295eb84d47b6e55cc93b63b4ce86d518b699137fc214062ecfe53fef27ada7
5
+ SHA512:
6
+ metadata.gz: 13025c837e41198f0135b212d24e55728a97ca481dcc36f797d8e46e6d9bc455ac289128a7f4ead66e39d87297abd172077bc3be2e2d593d7d22b88a228f24d1
7
+ data.tar.gz: 290ffa8e82198cdcc2a8a35f34070b0e23d3711e993ab38a6869149b4201d02474ec30336425a5f8852eeef5afe0cacdc70b1207148c84ea91fb5e524d1ce887
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Jason Lee
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # BookLab::SML
2
+
3
+ *SML* is a document format base on [JsonML](http://jsonml.org).
4
+
5
+ ## Usage
6
+
7
+ ```rb
8
+ gem "booklab-sml"
9
+ ```
10
+
11
+ and then run `bundle install`
12
+
13
+ ```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>
17
+ ```
18
+
19
+ ## License
20
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Jsonml'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ task default: :test
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+
5
+ module BookLab
6
+ module SML
7
+ def self.parse(src, out = StringIO.new)
8
+ ml = YAML.load(src)
9
+ parse_node(ml).string
10
+ end
11
+
12
+ private
13
+
14
+ # base code from: https://github.com/blambeau/jsonml-rb
15
+ def self.parse_node(src, out = StringIO.new)
16
+ has_attrs = src[1].is_a?(Hash)
17
+ first_child = has_attrs ? 2 : 1
18
+
19
+ case src
20
+ when Array
21
+ out << "<#{src.first}"
22
+ out << " " << attrs2html(src[1]) if has_attrs
23
+ out << ">"
24
+ src[first_child..-1].each { |child| parse_node(child, out) }
25
+ out << "</#{src.first}>"
26
+ when String
27
+ out << src
28
+ else
29
+ raise "Unexpected node `#{src}`"
30
+ end
31
+ end
32
+
33
+ def self.attrs2html(attrs)
34
+ attrs.each_pair.map { |pair| attr2html(*pair) }.join(" ")
35
+ end
36
+
37
+ def self.attr2html(key, value)
38
+ %(#{key}="#{value}")
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ module BookLab
2
+ module SML
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require "booklab/sml/version"
2
+ require "booklab/sml/base"
3
+
4
+ module BookLab
5
+ module SML
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: booklab-sml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Lee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: "*SML* is a document format base on [JsonML](http://jsonml.org)."
28
+ email:
29
+ - huacnlee@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - lib/booklab-sml.rb
38
+ - lib/booklab/sml/base.rb
39
+ - lib/booklab/sml/version.rb
40
+ homepage: https://github.com/huacnlee/booklab-sml
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.7.8
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: SML is a document format base on JsonML
64
+ test_files: []