openwebslides-converter 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 +7 -0
- data/.gitignore +54 -0
- data/.rdoc_options +16 -0
- data/.rspec +1 -0
- data/.rubocop.yml +16 -0
- data/.travis.yml +6 -0
- data/Gemfile +5 -0
- data/LICENSE.md +20 -0
- data/README.md +23 -0
- data/Rakefile +24 -0
- data/lib/openwebslides/converter.rb +8 -0
- data/lib/openwebslides/converter/content.rb +13 -0
- data/lib/openwebslides/converter/content/content_item.rb +12 -0
- data/lib/openwebslides/converter/content/heading.rb +13 -0
- data/lib/openwebslides/converter/content/paragraph.rb +13 -0
- data/lib/openwebslides/converter/content/properties/container.rb +21 -0
- data/lib/openwebslides/converter/content/properties/identifier.rb +41 -0
- data/lib/openwebslides/converter/content/properties/metadata.rb +24 -0
- data/lib/openwebslides/converter/content/properties/subable.rb +21 -0
- data/lib/openwebslides/converter/content/properties/text.rb +21 -0
- data/lib/openwebslides/converter/content/properties/type.rb +21 -0
- data/lib/openwebslides/converter/content/root.rb +11 -0
- data/lib/openwebslides/converter/helpers/sanitization.rb +21 -0
- data/lib/openwebslides/converter/pressbooks.rb +181 -0
- data/lib/openwebslides/converter/result.rb +16 -0
- data/lib/openwebslides/converter/version.rb +7 -0
- data/openwebslides-converter.gemspec +43 -0
- data/spec/content/content_item_spec.rb +25 -0
- data/spec/content/heading_spec.rb +27 -0
- data/spec/content/paragraph_spec.rb +27 -0
- data/spec/content/properties/container_spec.rb +48 -0
- data/spec/content/properties/identifier_spec.rb +51 -0
- data/spec/content/properties/metadata_spec.rb +48 -0
- data/spec/content/properties/subable_spec.rb +48 -0
- data/spec/content/properties/text_spec.rb +48 -0
- data/spec/content/properties/type_spec.rb +48 -0
- data/spec/content/root_spec.rb +26 -0
- data/spec/converter_spec.rb +10 -0
- data/spec/spec_helper.rb +11 -0
- metadata +221 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 32e2b829902eba27855f5b7d3be24992607e326721c451953f3592bdc7c17f68
|
4
|
+
data.tar.gz: a94aa71d42dcecbb2b55b06c2ce60fb1481acc333f764357a18de229d516b248
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 17e6ab071e726634cd713f8c9ab389d6778afba918f0af5e16a8e3acb2fddbcada134e467a0543ee0e573729b574423a7cadbe7a2a1354d6ec525d742c894423
|
7
|
+
data.tar.gz: 00ba4632095b4ed1a20e9084c0043ea6b88ba33e63156de02b617655a54e1ebdf58f72b2e0bdab873c4fa1d1648abeee33912133932e2938f7c47c926864601d
|
data/.gitignore
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
.byebug_history
|
13
|
+
|
14
|
+
# Used by dotenv library to load environment variables.
|
15
|
+
# .env
|
16
|
+
|
17
|
+
## Specific to RubyMotion:
|
18
|
+
.dat*
|
19
|
+
.repl_history
|
20
|
+
build/
|
21
|
+
*.bridgesupport
|
22
|
+
build-iPhoneOS/
|
23
|
+
build-iPhoneSimulator/
|
24
|
+
|
25
|
+
## Specific to RubyMotion (use of CocoaPods):
|
26
|
+
#
|
27
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
28
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
29
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
30
|
+
#
|
31
|
+
# vendor/Pods/
|
32
|
+
|
33
|
+
## Documentation cache and generated files:
|
34
|
+
/.yardoc/
|
35
|
+
/_yardoc/
|
36
|
+
/doc/
|
37
|
+
/rdoc/
|
38
|
+
|
39
|
+
## Environment normalization:
|
40
|
+
/.bundle/
|
41
|
+
/vendor/bundle
|
42
|
+
/lib/bundler/man/
|
43
|
+
|
44
|
+
# for a library or gem, you might want to ignore these files since the code is
|
45
|
+
# intended to run in multiple environments; otherwise, check them in:
|
46
|
+
Gemfile.lock
|
47
|
+
.ruby-version
|
48
|
+
.ruby-gemset
|
49
|
+
|
50
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
51
|
+
.rvmrc
|
52
|
+
|
53
|
+
# IDE files
|
54
|
+
.idea
|
data/.rdoc_options
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
--- !ruby/object:RDoc::Options
|
2
|
+
encoding: UTF-8
|
3
|
+
static_path: []
|
4
|
+
rdoc_include:
|
5
|
+
- .
|
6
|
+
charset: UTF-8
|
7
|
+
exclude:
|
8
|
+
hyperlink_all: false
|
9
|
+
line_numbers: false
|
10
|
+
main_page: README.md
|
11
|
+
markup: markdown
|
12
|
+
show_hash: false
|
13
|
+
tab_width: 8
|
14
|
+
title: openwebslides-converter Documentation
|
15
|
+
visibility: :protected
|
16
|
+
webcvs:
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format documentation
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Metrics/LineLength:
|
2
|
+
Max: 120
|
3
|
+
|
4
|
+
Metrics/BlockLength:
|
5
|
+
Exclude:
|
6
|
+
- openwebslides-converter.gemspec
|
7
|
+
|
8
|
+
Style/HashSyntax:
|
9
|
+
EnforcedStyle: hash_rockets
|
10
|
+
|
11
|
+
Style/MixinUsage:
|
12
|
+
Exclude:
|
13
|
+
- spec/spec_helper.rb
|
14
|
+
|
15
|
+
Style/NestedParenthesizedCalls:
|
16
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2018 Florian Dejonckheere
|
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,23 @@
|
|
1
|
+
# Open Webslides Converter [](https://travis-ci.org//openwebslides-converter)
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
Converts arbitrary documents to Open Webslides data format.
|
6
|
+
|
7
|
+
## Features
|
8
|
+
|
9
|
+
## Examples
|
10
|
+
|
11
|
+
require 'openwebslides/converter'
|
12
|
+
|
13
|
+
## Requirements
|
14
|
+
|
15
|
+
## Install
|
16
|
+
|
17
|
+
$ gem install openwebslides-converter
|
18
|
+
|
19
|
+
## Copyright
|
20
|
+
|
21
|
+
Copyright (c) 2018 Florian Dejonckheere
|
22
|
+
|
23
|
+
See LICENSE.txt for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'bundler/setup'
|
7
|
+
rescue LoadError => e
|
8
|
+
abort e.message
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'rake'
|
12
|
+
|
13
|
+
require 'rubygems/tasks'
|
14
|
+
Gem::Tasks.new
|
15
|
+
|
16
|
+
require 'rdoc/task'
|
17
|
+
RDoc::Task.new
|
18
|
+
task :doc => :rdoc
|
19
|
+
|
20
|
+
require 'rspec/core/rake_task'
|
21
|
+
RSpec::Core::RakeTask.new
|
22
|
+
|
23
|
+
task :test => :spec
|
24
|
+
task :default => :spec
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openwebslides/converter/helpers/sanitization'
|
4
|
+
|
5
|
+
require 'openwebslides/converter/version'
|
6
|
+
require 'openwebslides/converter/content'
|
7
|
+
require 'openwebslides/converter/result'
|
8
|
+
require 'openwebslides/converter/pressbooks'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'openwebslides/converter/content/properties/type'
|
4
|
+
require 'openwebslides/converter/content/properties/identifier'
|
5
|
+
require 'openwebslides/converter/content/properties/container'
|
6
|
+
require 'openwebslides/converter/content/properties/metadata'
|
7
|
+
require 'openwebslides/converter/content/properties/subable'
|
8
|
+
require 'openwebslides/converter/content/properties/text'
|
9
|
+
|
10
|
+
require 'openwebslides/converter/content/content_item'
|
11
|
+
require 'openwebslides/converter/content/root'
|
12
|
+
require 'openwebslides/converter/content/heading'
|
13
|
+
require 'openwebslides/converter/content/paragraph'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWebslides
|
4
|
+
module Converter
|
5
|
+
module Content
|
6
|
+
module Properties
|
7
|
+
module Container
|
8
|
+
attr_accessor :child_item_ids
|
9
|
+
|
10
|
+
def child_item_ids
|
11
|
+
@child_item_ids ||= []
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_h
|
15
|
+
super.merge :child_item_ids => child_item_ids
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWebslides
|
4
|
+
module Converter
|
5
|
+
module Content
|
6
|
+
module Properties
|
7
|
+
module Identifier
|
8
|
+
attr_accessor :id
|
9
|
+
|
10
|
+
def id
|
11
|
+
@id ||= generate_id
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# Convert property to hash
|
16
|
+
#
|
17
|
+
# This is the start of the chain of overridden #to_h methods.
|
18
|
+
# In all subsequent included property modules, #to_h should call
|
19
|
+
# `super.merge :property => property`
|
20
|
+
#
|
21
|
+
def to_h
|
22
|
+
{ :id => id }
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
##
|
28
|
+
# Generate a random 10-digit alphanumeric identifier
|
29
|
+
#
|
30
|
+
# @return [String] identifier
|
31
|
+
#
|
32
|
+
def generate_id
|
33
|
+
r = ('a'..'z').to_a + ('0'..'9').to_a
|
34
|
+
|
35
|
+
10.times.map { r.sample }.join
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWebslides
|
4
|
+
module Converter
|
5
|
+
module Content
|
6
|
+
module Properties
|
7
|
+
module Metadata
|
8
|
+
attr_accessor :metadata
|
9
|
+
|
10
|
+
def metadata
|
11
|
+
@metadata ||= {
|
12
|
+
:tags => [],
|
13
|
+
:visibility_overrides => {}
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_h
|
18
|
+
super.merge :metadata => metadata
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWebslides
|
4
|
+
module Converter
|
5
|
+
module Content
|
6
|
+
module Properties
|
7
|
+
module Subable
|
8
|
+
attr_accessor :sub_item_ids
|
9
|
+
|
10
|
+
def sub_item_ids
|
11
|
+
@sub_item_ids ||= []
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_h
|
15
|
+
super.merge :sub_item_ids => sub_item_ids
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWebslides
|
4
|
+
module Converter
|
5
|
+
module Content
|
6
|
+
module Properties
|
7
|
+
module Text
|
8
|
+
attr_accessor :text
|
9
|
+
|
10
|
+
def text
|
11
|
+
@text ||= ''
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_h
|
15
|
+
super.merge :text => text
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWebslides
|
4
|
+
module Converter
|
5
|
+
module Content
|
6
|
+
module Properties
|
7
|
+
module Type
|
8
|
+
attr_accessor :type
|
9
|
+
|
10
|
+
def type
|
11
|
+
"contentItemTypes/#{self.class.name.split('::').last.upcase}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_h
|
15
|
+
super.merge :type => type
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenWebslides
|
4
|
+
module Converter
|
5
|
+
module Helpers
|
6
|
+
module Sanitization
|
7
|
+
##
|
8
|
+
# Sanitize a string
|
9
|
+
# @param [String] text
|
10
|
+
# @return [String]
|
11
|
+
#
|
12
|
+
def sanitize(text)
|
13
|
+
text.gsub(/[[:space:]]+/, ' ')
|
14
|
+
.gsub(/_ _/, '')
|
15
|
+
.strip
|
16
|
+
.gsub(/\A \z/, '')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|