contentstack_utils 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/codeql-analysis.yml +68 -0
- data/.github/workflows/jira.yml +28 -0
- data/.github/workflows/release-gem.yml +31 -0
- data/.github/workflows/sast-scan.yml +11 -0
- data/.github/workflows/sca-scan.yml +15 -0
- data/.github/workflows/secrets-scan.yml +11 -0
- data/.gitignore +10 -10
- data/.yardopts +3 -3
- data/CHANGELOG.md +18 -12
- data/CODEOWNERS +1 -1
- data/Gemfile +4 -4
- data/Gemfile.lock +81 -76
- data/LICENSE +20 -20
- data/README.md +96 -96
- data/Rakefile +32 -32
- data/SECURITY.md +27 -27
- data/contentstack_utils.gemspec +31 -31
- data/lib/contentstack_utils/interface/renderable.rb +8 -8
- data/lib/contentstack_utils/model/metadata.rb +68 -68
- data/lib/contentstack_utils/model/options.rb +115 -113
- data/lib/contentstack_utils/support/helper.rb +2 -2
- data/lib/contentstack_utils/utils.rb +163 -163
- data/lib/contentstack_utils/version.rb +2 -2
- data/lib/contentstack_utils.rb +3 -3
- data/spec/lib/model/metadata_spec.rb +94 -94
- data/spec/lib/model/option_spec.rb +316 -309
- data/spec/lib/utils_spec.rb +642 -642
- data/spec/mock/constant_render_options.rb +15 -15
- data/spec/mock/custom_render_option.rb +23 -23
- data/spec/mock/json_to_html_mock.rb +146 -146
- data/spec/spec_helper.rb +8 -8
- data/spec/support/constant.rb +616 -616
- data/spec/support/xml_parse.rb +30 -30
- metadata +17 -11
data/Rakefile
CHANGED
@@ -1,33 +1,33 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
|
5
|
-
require 'yard'
|
6
|
-
YARD::Rake::YardocTask.new do |t|
|
7
|
-
t.files = ['lib/contentstack_utils/*.rb', 'lib/contentstack_utils.rb'] # optional
|
8
|
-
end
|
9
|
-
|
10
|
-
require 'rspec/core/rake_task'
|
11
|
-
RSpec::Core::RakeTask.new(:spec) do |t|
|
12
|
-
t.pattern = Dir.glob('spec/**/*_spec.rb')
|
13
|
-
t.rspec_opts = '--format documentation'
|
14
|
-
end
|
15
|
-
|
16
|
-
require "rdoc/task"
|
17
|
-
task ghpages: :rdoc do
|
18
|
-
%x[git checkout gh-pages]
|
19
|
-
require "fileutils"
|
20
|
-
FileUtils.rm_rf "/tmp/html"
|
21
|
-
FileUtils.mv "html", "/tmp"
|
22
|
-
FileUtils.rm_rf "*"
|
23
|
-
FileUtils.cp_r Dir.glob("/tmp/html/*"), "."
|
24
|
-
end
|
25
|
-
|
26
|
-
RDoc::Task.new do |doc|
|
27
|
-
doc.main = "README.rdoc"
|
28
|
-
doc.title = "Rake -- Ruby Make"
|
29
|
-
doc.rdoc_files = FileList.new %w[lib LICENSE doc/**/*.rdoc *.rdoc]
|
30
|
-
doc.rdoc_dir = "html"
|
31
|
-
end
|
32
|
-
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'yard'
|
6
|
+
YARD::Rake::YardocTask.new do |t|
|
7
|
+
t.files = ['lib/contentstack_utils/*.rb', 'lib/contentstack_utils.rb'] # optional
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rspec/core/rake_task'
|
11
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
12
|
+
t.pattern = Dir.glob('spec/**/*_spec.rb')
|
13
|
+
t.rspec_opts = '--format documentation'
|
14
|
+
end
|
15
|
+
|
16
|
+
require "rdoc/task"
|
17
|
+
task ghpages: :rdoc do
|
18
|
+
%x[git checkout gh-pages]
|
19
|
+
require "fileutils"
|
20
|
+
FileUtils.rm_rf "/tmp/html"
|
21
|
+
FileUtils.mv "html", "/tmp"
|
22
|
+
FileUtils.rm_rf "*"
|
23
|
+
FileUtils.cp_r Dir.glob("/tmp/html/*"), "."
|
24
|
+
end
|
25
|
+
|
26
|
+
RDoc::Task.new do |doc|
|
27
|
+
doc.main = "README.rdoc"
|
28
|
+
doc.title = "Rake -- Ruby Make"
|
29
|
+
doc.rdoc_files = FileList.new %w[lib LICENSE doc/**/*.rdoc *.rdoc]
|
30
|
+
doc.rdoc_dir = "html"
|
31
|
+
end
|
32
|
+
|
33
33
|
task default: :spec
|
data/SECURITY.md
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
## Security
|
2
|
-
|
3
|
-
Contentstack takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations.
|
4
|
-
|
5
|
-
If you believe you have found a security vulnerability in any Contentstack-owned repository, please report it to us as described below.
|
6
|
-
|
7
|
-
## Reporting Security Issues
|
8
|
-
|
9
|
-
**Please do not report security vulnerabilities through public GitHub issues.**
|
10
|
-
|
11
|
-
Send email to [security@contentstack.com](mailto:security@contentstack.com).
|
12
|
-
|
13
|
-
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message.
|
14
|
-
|
15
|
-
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
|
16
|
-
|
17
|
-
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
|
18
|
-
* Full paths of source file(s) related to the manifestation of the issue
|
19
|
-
* The location of the affected source code (tag/branch/commit or direct URL)
|
20
|
-
* Any special configuration required to reproduce the issue
|
21
|
-
* Step-by-step instructions to reproduce the issue
|
22
|
-
* Proof-of-concept or exploit code (if possible)
|
23
|
-
* Impact of the issue, including how an attacker might exploit the issue
|
24
|
-
|
25
|
-
This information will help us triage your report more quickly.
|
26
|
-
|
27
|
-
[https://www.contentstack.com/trust/](https://www.contentstack.com/trust/)
|
1
|
+
## Security
|
2
|
+
|
3
|
+
Contentstack takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations.
|
4
|
+
|
5
|
+
If you believe you have found a security vulnerability in any Contentstack-owned repository, please report it to us as described below.
|
6
|
+
|
7
|
+
## Reporting Security Issues
|
8
|
+
|
9
|
+
**Please do not report security vulnerabilities through public GitHub issues.**
|
10
|
+
|
11
|
+
Send email to [security@contentstack.com](mailto:security@contentstack.com).
|
12
|
+
|
13
|
+
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message.
|
14
|
+
|
15
|
+
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
|
16
|
+
|
17
|
+
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
|
18
|
+
* Full paths of source file(s) related to the manifestation of the issue
|
19
|
+
* The location of the affected source code (tag/branch/commit or direct URL)
|
20
|
+
* Any special configuration required to reproduce the issue
|
21
|
+
* Step-by-step instructions to reproduce the issue
|
22
|
+
* Proof-of-concept or exploit code (if possible)
|
23
|
+
* Impact of the issue, including how an attacker might exploit the issue
|
24
|
+
|
25
|
+
This information will help us triage your report more quickly.
|
26
|
+
|
27
|
+
[https://www.contentstack.com/trust/](https://www.contentstack.com/trust/)
|
data/contentstack_utils.gemspec
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
lib = File.expand_path('../lib', __FILE__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
|
4
|
-
require 'contentstack_utils/version'
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = %q{contentstack_utils}
|
7
|
-
s.version = ContentstackUtils::VERSION.dup
|
8
|
-
s.date = Time.now
|
9
|
-
s.authors = [%q{Contentstack}]
|
10
|
-
s.email = ["support@contentstack.com"]
|
11
|
-
|
12
|
-
s.required_ruby_version = '>= 2.0'
|
13
|
-
|
14
|
-
s.license = "MIT"
|
15
|
-
s.homepage = "https://github.com/contentstack/contentstack-utils-ruby"
|
16
|
-
|
17
|
-
s.summary = %q{Contentstack Ruby Utils for }
|
18
|
-
s.description = %q{Contentstack Ruby client for the Content Delivery API}
|
19
|
-
|
20
|
-
s.files = `git ls-files`.split("\n")
|
21
|
-
s.test_files = s.files.grep(%r{^spec/})
|
22
|
-
s.require_paths = ["lib"]
|
23
|
-
|
24
|
-
s.add_dependency 'activesupport', '>= 3.2', '<
|
25
|
-
s.add_dependency 'nokogiri', '~> 1.11', '>= 1.11.0'
|
26
|
-
|
27
|
-
s.add_development_dependency 'rake', '~> 13.0.3'
|
28
|
-
s.add_development_dependency 'rspec', '~> 3.10.0'
|
29
|
-
s.add_development_dependency 'webmock', '~> 3.11.0'
|
30
|
-
s.add_development_dependency 'simplecov', '~> 0.21.1'
|
31
|
-
s.add_development_dependency 'yard', '~> 0.9.26'
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'contentstack_utils/version'
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = %q{contentstack_utils}
|
7
|
+
s.version = ContentstackUtils::VERSION.dup
|
8
|
+
s.date = Time.now
|
9
|
+
s.authors = [%q{Contentstack}]
|
10
|
+
s.email = ["support@contentstack.com"]
|
11
|
+
|
12
|
+
s.required_ruby_version = '>= 2.0'
|
13
|
+
|
14
|
+
s.license = "MIT"
|
15
|
+
s.homepage = "https://github.com/contentstack/contentstack-utils-ruby"
|
16
|
+
|
17
|
+
s.summary = %q{Contentstack Ruby Utils for }
|
18
|
+
s.description = %q{Contentstack Ruby client for the Content Delivery API}
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = s.files.grep(%r{^spec/})
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
|
24
|
+
s.add_dependency 'activesupport', '>= 3.2', '< 7.0.4'
|
25
|
+
s.add_dependency 'nokogiri', '~> 1.11', '>= 1.11.0'
|
26
|
+
|
27
|
+
s.add_development_dependency 'rake', '~> 13.0.3'
|
28
|
+
s.add_development_dependency 'rspec', '~> 3.10.0'
|
29
|
+
s.add_development_dependency 'webmock', '~> 3.11.0'
|
30
|
+
s.add_development_dependency 'simplecov', '~> 0.21.1'
|
31
|
+
s.add_development_dependency 'yard', '~> 0.9.26'
|
32
32
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module ContentstackUtils
|
2
|
-
module Interface
|
3
|
-
class Rendarable
|
4
|
-
def render_option(embeddedObject, metadata)
|
5
|
-
raise NotImplementedError, "Implement this method in a child class"
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
1
|
+
module ContentstackUtils
|
2
|
+
module Interface
|
3
|
+
class Rendarable
|
4
|
+
def render_option(embeddedObject, metadata)
|
5
|
+
raise NotImplementedError, "Implement this method in a child class"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
9
|
end
|
@@ -1,69 +1,69 @@
|
|
1
|
-
|
2
|
-
module ContentstackUtils
|
3
|
-
module Model
|
4
|
-
class Metadata
|
5
|
-
def initialize( element )
|
6
|
-
if element.instance_of? Nokogiri::XML::Element
|
7
|
-
@itemType = element.attribute('type') ? element.attribute('type').value : nil
|
8
|
-
@styleType = element.attribute('sys-style-type') ? element.attribute('sys-style-type').value : nil
|
9
|
-
@itemUid ||= (element.attribute('data-sys-entry-uid') ? element.attribute('data-sys-entry-uid').value : nil) || (element.attribute('data-sys-asset-uid') ? element.attribute('data-sys-asset-uid').value : nil)
|
10
|
-
@contentTypeUid = element.attribute('data-sys-content-type-uid') ? element.attribute('data-sys-content-type-uid').value : nil
|
11
|
-
@text = element.text
|
12
|
-
@element = element
|
13
|
-
@attributes = element
|
14
|
-
else
|
15
|
-
@itemType = element["attrs"]['type']
|
16
|
-
@styleType = element["attrs"]['display-type']
|
17
|
-
@itemUid ||= element["attrs"]['entry-uid'] || element["attrs"]['asset-uid']
|
18
|
-
@contentTypeUid = element["attrs"]['content-type-uid']
|
19
|
-
if element["children"] && element["children"].length() > 0
|
20
|
-
child = element["children"]
|
21
|
-
for item in child do
|
22
|
-
if item["type"] == nil && item["text"]
|
23
|
-
@text = item["text"]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
@element = element
|
28
|
-
@attributes = element["attrs"]
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def item_type
|
33
|
-
@itemType ? @itemType : nil
|
34
|
-
end
|
35
|
-
|
36
|
-
def style_type
|
37
|
-
@styleType ? @styleType : nil
|
38
|
-
end
|
39
|
-
|
40
|
-
def item_uid
|
41
|
-
@itemUid ? @itemUid : nil
|
42
|
-
end
|
43
|
-
|
44
|
-
def content_type_uid
|
45
|
-
@contentTypeUid ? @contentTypeUid : nil
|
46
|
-
end
|
47
|
-
|
48
|
-
def text
|
49
|
-
@text
|
50
|
-
end
|
51
|
-
|
52
|
-
def element
|
53
|
-
@element
|
54
|
-
end
|
55
|
-
|
56
|
-
def attributes
|
57
|
-
@attributes
|
58
|
-
end
|
59
|
-
|
60
|
-
def get_attribute_value(string)
|
61
|
-
if @attributes.instance_of? Nokogiri::XML::Element
|
62
|
-
@attributes.attribute(string) ? @attributes.attribute(string).value : nil
|
63
|
-
else
|
64
|
-
@attributes[string]
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
1
|
+
|
2
|
+
module ContentstackUtils
|
3
|
+
module Model
|
4
|
+
class Metadata
|
5
|
+
def initialize( element )
|
6
|
+
if element.instance_of? Nokogiri::XML::Element
|
7
|
+
@itemType = element.attribute('type') ? element.attribute('type').value : nil
|
8
|
+
@styleType = element.attribute('sys-style-type') ? element.attribute('sys-style-type').value : nil
|
9
|
+
@itemUid ||= (element.attribute('data-sys-entry-uid') ? element.attribute('data-sys-entry-uid').value : nil) || (element.attribute('data-sys-asset-uid') ? element.attribute('data-sys-asset-uid').value : nil)
|
10
|
+
@contentTypeUid = element.attribute('data-sys-content-type-uid') ? element.attribute('data-sys-content-type-uid').value : nil
|
11
|
+
@text = element.text
|
12
|
+
@element = element
|
13
|
+
@attributes = element
|
14
|
+
else
|
15
|
+
@itemType = element["attrs"]['type']
|
16
|
+
@styleType = element["attrs"]['display-type']
|
17
|
+
@itemUid ||= element["attrs"]['entry-uid'] || element["attrs"]['asset-uid']
|
18
|
+
@contentTypeUid = element["attrs"]['content-type-uid']
|
19
|
+
if element["children"] && element["children"].length() > 0
|
20
|
+
child = element["children"]
|
21
|
+
for item in child do
|
22
|
+
if item["type"] == nil && item["text"]
|
23
|
+
@text = item["text"]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
@element = element
|
28
|
+
@attributes = element["attrs"]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def item_type
|
33
|
+
@itemType ? @itemType : nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def style_type
|
37
|
+
@styleType ? @styleType : nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def item_uid
|
41
|
+
@itemUid ? @itemUid : nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def content_type_uid
|
45
|
+
@contentTypeUid ? @contentTypeUid : nil
|
46
|
+
end
|
47
|
+
|
48
|
+
def text
|
49
|
+
@text
|
50
|
+
end
|
51
|
+
|
52
|
+
def element
|
53
|
+
@element
|
54
|
+
end
|
55
|
+
|
56
|
+
def attributes
|
57
|
+
@attributes
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_attribute_value(string)
|
61
|
+
if @attributes.instance_of? Nokogiri::XML::Element
|
62
|
+
@attributes.attribute(string) ? @attributes.attribute(string).value : nil
|
63
|
+
else
|
64
|
+
@attributes[string]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
69
|
end
|
@@ -1,113 +1,115 @@
|
|
1
|
-
require_relative '../interface/renderable.rb'
|
2
|
-
require_relative './metadata.rb'
|
3
|
-
|
4
|
-
module ContentstackUtils
|
5
|
-
module Model
|
6
|
-
class Options < Interface::Rendarable
|
7
|
-
|
8
|
-
def initialize(entry = nil)
|
9
|
-
@entry = entry
|
10
|
-
end
|
11
|
-
|
12
|
-
def entry
|
13
|
-
@entry
|
14
|
-
end
|
15
|
-
|
16
|
-
def render_option(embeddedObject, metadata)
|
17
|
-
renderString = ''
|
18
|
-
case metadata.style_type
|
19
|
-
when 'block'
|
20
|
-
renderString = "<div><p>#{embeddedObject['title'] || embeddedObject['uid']}</p><p>Content type: <span>#{embeddedObject['_content_type_uid'] || embeddedObject['system']['content_type_uid']}</span></p></div>"
|
21
|
-
when 'inline'
|
22
|
-
renderString = "<span>#{embeddedObject["title"] || embeddedObject["uid"]}</span>";
|
23
|
-
when 'link'
|
24
|
-
metadata.get_attribute_value("href")
|
25
|
-
renderString = "<a href='#{metadata.get_attribute_value("href") || embeddedObject["url"] || embeddedObject["title"] || embeddedObject["uid"]}'>#{(metadata.text && metadata.text != '' ? metadata.text : (embeddedObject["title"] || embeddedObject["uid"]))}</a>";
|
26
|
-
when 'display'
|
27
|
-
renderString = "<img src='#{metadata.get_attribute_value("src")|| embeddedObject["url"]}' alt='#{(metadata.attributes["alt"] ? metadata.attributes["alt"].value : (embeddedObject["title"] || embeddedObject["filename"] || embeddedObject["uid"]))}' />";
|
28
|
-
when 'download'
|
29
|
-
renderString = "<a href='#{metadata.get_attribute_value("href") || embeddedObject["url"]}'>#{(metadata.text && metadata.text != '' ? metadata.text : (embeddedObject["filename"] || embeddedObject["title"] || embeddedObject["uid"]))}</a>";
|
30
|
-
end
|
31
|
-
renderString
|
32
|
-
end
|
33
|
-
|
34
|
-
def render_mark(mark_type, text)
|
35
|
-
renderString = text
|
36
|
-
case mark_type
|
37
|
-
when 'bold'
|
38
|
-
renderString = "<strong>#{text}</strong>"
|
39
|
-
when 'italic'
|
40
|
-
renderString = "<em>#{text}</em>"
|
41
|
-
when 'underline'
|
42
|
-
renderString = "<u>#{text}</u>"
|
43
|
-
when 'strikethrough'
|
44
|
-
renderString = "<strike>#{text}</strike>"
|
45
|
-
when 'inlineCode'
|
46
|
-
renderString = "<span>#{text}</span>"
|
47
|
-
when 'subscript'
|
48
|
-
renderString = "<sub>#{text}</sub>"
|
49
|
-
when 'superscript'
|
50
|
-
renderString = "<sup>#{text}</sup>"
|
51
|
-
end
|
52
|
-
renderString
|
53
|
-
end
|
54
|
-
|
55
|
-
def render_node(node_type, node, inner_html)
|
56
|
-
renderString = ""
|
57
|
-
case node_type
|
58
|
-
when 'doc'
|
59
|
-
renderString = ""
|
60
|
-
when 'p'
|
61
|
-
renderString = "<p>#{inner_html}</p>"
|
62
|
-
when 'a'
|
63
|
-
renderString = "<a href='#{node["attrs"]["href"] || node["attrs"]["url"] || ""}'>#{inner_html}</a>"
|
64
|
-
when 'img'
|
65
|
-
renderString = "<img src='#{node["attrs"]["src"] || node["attrs"]["url"] || ""}' />#{inner_html}"
|
66
|
-
when 'embed'
|
67
|
-
renderString = "<iframe src='#{node["attrs"]["src"] || node["attrs"]["url"] || ""}'></iframe>"
|
68
|
-
when 'h1'
|
69
|
-
renderString = "<h1>#{inner_html}</h1>"
|
70
|
-
when 'h2'
|
71
|
-
renderString = "<h2>#{inner_html}</h2>"
|
72
|
-
when 'h3'
|
73
|
-
renderString = "<h3>#{inner_html}</h3>"
|
74
|
-
when 'h4'
|
75
|
-
renderString = "<h4>#{inner_html}</h4>"
|
76
|
-
when 'h5'
|
77
|
-
renderString = "<h5>#{inner_html}</h5>"
|
78
|
-
when 'h6'
|
79
|
-
renderString = "<h6>#{inner_html}</h6>"
|
80
|
-
when 'ol'
|
81
|
-
renderString = "<ol>#{inner_html}</ol>"
|
82
|
-
when 'ul'
|
83
|
-
renderString = "<ul>#{inner_html}</ul>"
|
84
|
-
when 'li'
|
85
|
-
renderString = "<li>#{inner_html}</li>"
|
86
|
-
when 'hr'
|
87
|
-
renderString = "<hr />"
|
88
|
-
when 'table'
|
89
|
-
renderString = "<table>#{inner_html}</table>"
|
90
|
-
when 'thead'
|
91
|
-
renderString = "<thead>#{inner_html}</thead>"
|
92
|
-
when 'tbody'
|
93
|
-
renderString = "<tbody>#{inner_html}</tbody>"
|
94
|
-
when 'tfoot'
|
95
|
-
renderString = "<tfoot>#{inner_html}</tfoot>"
|
96
|
-
when 'tr'
|
97
|
-
renderString = "<tr>#{inner_html}</tr>"
|
98
|
-
when 'th'
|
99
|
-
renderString = "<th>#{inner_html}</th>"
|
100
|
-
when 'td'
|
101
|
-
renderString = "<td>#{inner_html}</td>"
|
102
|
-
when 'blockquote'
|
103
|
-
renderString = "<blockquote>#{inner_html}</blockquote>"
|
104
|
-
when 'code'
|
105
|
-
renderString = "<code>#{inner_html}</code>"
|
106
|
-
when 'reference'
|
107
|
-
renderString = ""
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
end
|
1
|
+
require_relative '../interface/renderable.rb'
|
2
|
+
require_relative './metadata.rb'
|
3
|
+
|
4
|
+
module ContentstackUtils
|
5
|
+
module Model
|
6
|
+
class Options < Interface::Rendarable
|
7
|
+
|
8
|
+
def initialize(entry = nil)
|
9
|
+
@entry = entry
|
10
|
+
end
|
11
|
+
|
12
|
+
def entry
|
13
|
+
@entry
|
14
|
+
end
|
15
|
+
|
16
|
+
def render_option(embeddedObject, metadata)
|
17
|
+
renderString = ''
|
18
|
+
case metadata.style_type
|
19
|
+
when 'block'
|
20
|
+
renderString = "<div><p>#{embeddedObject['title'] || embeddedObject['uid']}</p><p>Content type: <span>#{embeddedObject['_content_type_uid'] || embeddedObject['system']['content_type_uid']}</span></p></div>"
|
21
|
+
when 'inline'
|
22
|
+
renderString = "<span>#{embeddedObject["title"] || embeddedObject["uid"]}</span>";
|
23
|
+
when 'link'
|
24
|
+
metadata.get_attribute_value("href")
|
25
|
+
renderString = "<a href='#{metadata.get_attribute_value("href") || embeddedObject["url"] || embeddedObject["title"] || embeddedObject["uid"]}'>#{(metadata.text && metadata.text != '' ? metadata.text : (embeddedObject["title"] || embeddedObject["uid"]))}</a>";
|
26
|
+
when 'display'
|
27
|
+
renderString = "<img src='#{metadata.get_attribute_value("src")|| embeddedObject["url"]}' alt='#{(metadata.attributes["alt"] ? metadata.attributes["alt"].value : (embeddedObject["title"] || embeddedObject["filename"] || embeddedObject["uid"]))}' />";
|
28
|
+
when 'download'
|
29
|
+
renderString = "<a href='#{metadata.get_attribute_value("href") || embeddedObject["url"]}'>#{(metadata.text && metadata.text != '' ? metadata.text : (embeddedObject["filename"] || embeddedObject["title"] || embeddedObject["uid"]))}</a>";
|
30
|
+
end
|
31
|
+
renderString
|
32
|
+
end
|
33
|
+
|
34
|
+
def render_mark(mark_type, text)
|
35
|
+
renderString = text
|
36
|
+
case mark_type
|
37
|
+
when 'bold'
|
38
|
+
renderString = "<strong>#{text}</strong>"
|
39
|
+
when 'italic'
|
40
|
+
renderString = "<em>#{text}</em>"
|
41
|
+
when 'underline'
|
42
|
+
renderString = "<u>#{text}</u>"
|
43
|
+
when 'strikethrough'
|
44
|
+
renderString = "<strike>#{text}</strike>"
|
45
|
+
when 'inlineCode'
|
46
|
+
renderString = "<span>#{text}</span>"
|
47
|
+
when 'subscript'
|
48
|
+
renderString = "<sub>#{text}</sub>"
|
49
|
+
when 'superscript'
|
50
|
+
renderString = "<sup>#{text}</sup>"
|
51
|
+
end
|
52
|
+
renderString
|
53
|
+
end
|
54
|
+
|
55
|
+
def render_node(node_type, node, inner_html)
|
56
|
+
renderString = ""
|
57
|
+
case node_type
|
58
|
+
when 'doc'
|
59
|
+
renderString = ""
|
60
|
+
when 'p'
|
61
|
+
renderString = "<p>#{inner_html}</p>"
|
62
|
+
when 'a'
|
63
|
+
renderString = "<a href='#{node["attrs"]["href"] || node["attrs"]["url"] || ""}'>#{inner_html}</a>"
|
64
|
+
when 'img'
|
65
|
+
renderString = "<img src='#{node["attrs"]["src"] || node["attrs"]["url"] || ""}' />#{inner_html}"
|
66
|
+
when 'embed'
|
67
|
+
renderString = "<iframe src='#{node["attrs"]["src"] || node["attrs"]["url"] || ""}'></iframe>"
|
68
|
+
when 'h1'
|
69
|
+
renderString = "<h1>#{inner_html}</h1>"
|
70
|
+
when 'h2'
|
71
|
+
renderString = "<h2>#{inner_html}</h2>"
|
72
|
+
when 'h3'
|
73
|
+
renderString = "<h3>#{inner_html}</h3>"
|
74
|
+
when 'h4'
|
75
|
+
renderString = "<h4>#{inner_html}</h4>"
|
76
|
+
when 'h5'
|
77
|
+
renderString = "<h5>#{inner_html}</h5>"
|
78
|
+
when 'h6'
|
79
|
+
renderString = "<h6>#{inner_html}</h6>"
|
80
|
+
when 'ol'
|
81
|
+
renderString = "<ol>#{inner_html}</ol>"
|
82
|
+
when 'ul'
|
83
|
+
renderString = "<ul>#{inner_html}</ul>"
|
84
|
+
when 'li'
|
85
|
+
renderString = "<li>#{inner_html}</li>"
|
86
|
+
when 'hr'
|
87
|
+
renderString = "<hr />"
|
88
|
+
when 'table'
|
89
|
+
renderString = "<table>#{inner_html}</table>"
|
90
|
+
when 'thead'
|
91
|
+
renderString = "<thead>#{inner_html}</thead>"
|
92
|
+
when 'tbody'
|
93
|
+
renderString = "<tbody>#{inner_html}</tbody>"
|
94
|
+
when 'tfoot'
|
95
|
+
renderString = "<tfoot>#{inner_html}</tfoot>"
|
96
|
+
when 'tr'
|
97
|
+
renderString = "<tr>#{inner_html}</tr>"
|
98
|
+
when 'th'
|
99
|
+
renderString = "<th>#{inner_html}</th>"
|
100
|
+
when 'td'
|
101
|
+
renderString = "<td>#{inner_html}</td>"
|
102
|
+
when 'blockquote'
|
103
|
+
renderString = "<blockquote>#{inner_html}</blockquote>"
|
104
|
+
when 'code'
|
105
|
+
renderString = "<code>#{inner_html}</code>"
|
106
|
+
when 'reference'
|
107
|
+
renderString = ""
|
108
|
+
when 'span'
|
109
|
+
renderString = "<span>#{inner_html}</span>"
|
110
|
+
end
|
111
|
+
renderString
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
def appendFrame(string)
|
2
|
-
"<documentfragmentcontainer>#{string}</documentfragmentcontainer>"
|
1
|
+
def appendFrame(string)
|
2
|
+
"<documentfragmentcontainer>#{string}</documentfragmentcontainer>"
|
3
3
|
end
|