contentstack_utils 1.1.1 → 1.1.2
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 +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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f23686be72fce0284785accb2b67d2d80806d35a01054ef760b10b0ee4236ddd
|
4
|
+
data.tar.gz: 7f92d325f202771e549d4bee7cab111a956df876a833139323df7f80cf5bc106
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 989bc3b67fcadd8872ea4e9f1748d0d343be33550338d94a6c14b604847c6b8c0ffc521dc7530fbfce8a3416850043f66a70de843c4265557c1342e4ec53302a
|
7
|
+
data.tar.gz: 0da5efa25ac4abf4522952ea52efd0faeb54d6c38e44a5323df738a709a4de7a40b146a2963f4340737542a90a712b120e6571ec1742494119bc15b382922620
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# For most projects, this workflow file will not need changing; you simply need
|
2
|
+
# to commit it to your repository.
|
3
|
+
#
|
4
|
+
# You may wish to alter this file to override the set of languages analyzed,
|
5
|
+
# or to provide custom queries or build logic.
|
6
|
+
#
|
7
|
+
# ******** NOTE ********
|
8
|
+
# We have attempted to detect the languages in your repository. Please check
|
9
|
+
# the `language` matrix defined below to confirm you have the correct set of
|
10
|
+
# supported CodeQL languages.
|
11
|
+
#
|
12
|
+
name: "CodeQL"
|
13
|
+
|
14
|
+
on:
|
15
|
+
pull_request:
|
16
|
+
# The branches below must be a subset of the branches above
|
17
|
+
branches: '*'
|
18
|
+
|
19
|
+
jobs:
|
20
|
+
analyze:
|
21
|
+
name: Analyze
|
22
|
+
runs-on: ubuntu-latest
|
23
|
+
permissions:
|
24
|
+
actions: read
|
25
|
+
contents: read
|
26
|
+
security-events: write
|
27
|
+
|
28
|
+
strategy:
|
29
|
+
fail-fast: false
|
30
|
+
matrix:
|
31
|
+
language: [ 'ruby' ]
|
32
|
+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
33
|
+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
|
34
|
+
|
35
|
+
steps:
|
36
|
+
- name: Checkout repository
|
37
|
+
uses: actions/checkout@v3
|
38
|
+
|
39
|
+
# Initializes the CodeQL tools for scanning.
|
40
|
+
- name: Initialize CodeQL
|
41
|
+
uses: github/codeql-action/init@v2
|
42
|
+
with:
|
43
|
+
languages: ${{ matrix.language }}
|
44
|
+
# If you wish to specify custom queries, you can do so here or in a config file.
|
45
|
+
# By default, queries listed here will override any specified in a config file.
|
46
|
+
# Prefix the list here with "+" to use these queries and those in the config file.
|
47
|
+
|
48
|
+
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
|
49
|
+
# queries: security-extended,security-and-quality
|
50
|
+
|
51
|
+
|
52
|
+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
53
|
+
# If this step fails, then you should remove it and run the build manually (see below)
|
54
|
+
- name: Autobuild
|
55
|
+
uses: github/codeql-action/autobuild@v2
|
56
|
+
|
57
|
+
# ℹ️ Command-line programs to run using the OS shell.
|
58
|
+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
59
|
+
|
60
|
+
# If the Autobuild fails above, remove it and uncomment the following three lines.
|
61
|
+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
|
62
|
+
|
63
|
+
# - run: |
|
64
|
+
# echo "Run, Build Application using script"
|
65
|
+
# ./location_of_script_within_repo/buildscript.sh
|
66
|
+
|
67
|
+
- name: Perform CodeQL Analysis
|
68
|
+
uses: github/codeql-action/analyze@v2
|
@@ -0,0 +1,28 @@
|
|
1
|
+
name: Create JIRA ISSUE
|
2
|
+
on:
|
3
|
+
pull_request:
|
4
|
+
types: [opened]
|
5
|
+
jobs:
|
6
|
+
security:
|
7
|
+
if: ${{ github.actor == 'dependabot[bot]' || github.actor == 'snyk-bot' || contains(github.event.pull_request.head.ref, 'snyk-fix-') || contains(github.event.pull_request.head.ref, 'snyk-upgrade-')}}
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v2
|
11
|
+
- name: Login into JIRA
|
12
|
+
uses: atlassian/gajira-login@master
|
13
|
+
env:
|
14
|
+
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
|
15
|
+
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
|
16
|
+
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
|
17
|
+
- name: Create a JIRA Issue
|
18
|
+
id: create
|
19
|
+
uses: atlassian/gajira-create@master
|
20
|
+
with:
|
21
|
+
project: ${{ secrets.JIRA_PROJECT }}
|
22
|
+
issuetype: ${{ secrets.JIRA_ISSUE_TYPE }}
|
23
|
+
summary: |
|
24
|
+
${{ github.event.pull_request.title }}
|
25
|
+
description: |
|
26
|
+
PR: ${{ github.event.pull_request.html_url }}
|
27
|
+
|
28
|
+
fields: "${{ secrets.JIRA_FIELDS }}"
|
@@ -0,0 +1,31 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
release:
|
5
|
+
types: [created]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
name: Build + Publish
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
permissions:
|
12
|
+
contents: read
|
13
|
+
packages: write
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v3
|
17
|
+
- name: Set up Ruby 2.6
|
18
|
+
uses: actions/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: 2.6.x
|
21
|
+
|
22
|
+
- name: Publish to RubyGems
|
23
|
+
run: |
|
24
|
+
mkdir -p $HOME/.gem
|
25
|
+
touch $HOME/.gem/credentials
|
26
|
+
chmod 0600 $HOME/.gem/credentials
|
27
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
28
|
+
gem build *.gemspec
|
29
|
+
gem push *.gem
|
30
|
+
env:
|
31
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
name: SAST Scan
|
2
|
+
on:
|
3
|
+
pull_request:
|
4
|
+
types: [opened, synchronize, reopened]
|
5
|
+
jobs:
|
6
|
+
security:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Horusec Scan
|
11
|
+
run: docker run -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd):/src horuszup/horusec-cli:latest horusec start -p /src -P $(pwd)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
name: Source Composition Analysis Scan
|
2
|
+
on:
|
3
|
+
pull_request:
|
4
|
+
types: [opened, synchronize, reopened]
|
5
|
+
jobs:
|
6
|
+
security:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@master
|
10
|
+
- name: Run Snyk to check for vulnerabilities
|
11
|
+
uses: snyk/actions/ruby@master
|
12
|
+
env:
|
13
|
+
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
|
14
|
+
with:
|
15
|
+
args: --fail-on=all
|
data/.gitignore
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
contentstack_utils-*
|
2
|
-
build_doc.sh
|
3
|
-
test
|
4
|
-
doc
|
5
|
-
spec-integration
|
6
|
-
coverage
|
7
|
-
\.yardoc
|
8
|
-
.DS_Store
|
9
|
-
.bundle/
|
10
|
-
**/rspec_results.html
|
1
|
+
contentstack_utils-*
|
2
|
+
build_doc.sh
|
3
|
+
test
|
4
|
+
doc
|
5
|
+
spec-integration
|
6
|
+
coverage
|
7
|
+
\.yardoc
|
8
|
+
.DS_Store
|
9
|
+
.bundle/
|
10
|
+
**/rspec_results.html
|
11
11
|
.dccache
|
data/.yardopts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
README.md
|
2
|
-
lib/contentstack_utils/*
|
3
|
-
lib/contentstack_utils.rb
|
1
|
+
README.md
|
2
|
+
lib/contentstack_utils/*
|
3
|
+
lib/contentstack_utils.rb
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,18 @@
|
|
1
|
-
# Changelog
|
2
|
-
|
3
|
-
## [1.1.
|
4
|
-
-
|
5
|
-
|
6
|
-
## [1.
|
7
|
-
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## [1.1.2](https://github.com/contentstack/contentstack-utils-ruby/tree/v1.1.2) (2023-02-27)
|
4
|
+
- Dependency gem updated (Activesupport gem)
|
5
|
+
|
6
|
+
## [1.1.1](https://github.com/contentstack/contentstack-utils-ruby/tree/v1.1.1) (2022-04-21)
|
7
|
+
- Json RTE image, link and frame source url issue resolved
|
8
|
+
|
9
|
+
## [1.1.0](https://github.com/contentstack/contentstack-utils-ruby/tree/v1.1.0) (2021-08-10)
|
10
|
+
- GQL Json rte to Html content support added
|
11
|
+
|
12
|
+
## [1.0.2](https://github.com/contentstack/contentstack-utils-ruby/tree/v1.0.2) (2021-07-16)
|
13
|
+
- JSON RTE support added
|
14
|
+
## [1.0.1](https://github.com/contentstack/contentstack-utils-ruby/tree/v1.0.1) (2021-06-02)
|
15
|
+
- Gemspec Dependency update
|
16
|
+
|
17
|
+
## [1.0.0](https://github.com/contentstack/contentstack-utils-ruby/tree/v1.0.0) (2021-04-05)
|
18
|
+
- Initial release for Contentstack Utils SDK
|
data/CODEOWNERS
CHANGED
@@ -1 +1 @@
|
|
1
|
-
* @contentstack/security-admin @contentstack/sdk-admin
|
1
|
+
* @contentstack/security-admin @contentstack/sdk-admin
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Gemfile
|
2
|
-
source "https://rubygems.org"
|
3
|
-
|
4
|
-
gemspec
|
1
|
+
# Gemfile
|
2
|
+
source "https://rubygems.org"
|
3
|
+
|
4
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,76 +1,81 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
contentstack_utils (1.1.0)
|
5
|
-
activesupport (>= 3.2, <
|
6
|
-
nokogiri (~> 1.11, >= 1.11.0)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
activesupport (6.1.
|
12
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
-
i18n (>= 1.6, < 2)
|
14
|
-
minitest (>= 5.1)
|
15
|
-
tzinfo (~> 2.0)
|
16
|
-
zeitwerk (~> 2.3)
|
17
|
-
addressable (2.8.
|
18
|
-
public_suffix (>= 2.0.2, <
|
19
|
-
concurrent-ruby (1.
|
20
|
-
crack (0.4.5)
|
21
|
-
rexml
|
22
|
-
diff-lcs (1.
|
23
|
-
docile (1.4.0)
|
24
|
-
hashdiff (1.0.1)
|
25
|
-
i18n (1.
|
26
|
-
concurrent-ruby (~> 1.0)
|
27
|
-
mini_portile2 (2.8.
|
28
|
-
minitest (5.
|
29
|
-
nokogiri (1.13.
|
30
|
-
mini_portile2 (~> 2.8.0)
|
31
|
-
racc (~> 1.4)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
rspec-
|
40
|
-
|
41
|
-
rspec-
|
42
|
-
rspec-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
contentstack_utils (1.1.0)
|
5
|
+
activesupport (>= 3.2, < 7.0.4)
|
6
|
+
nokogiri (~> 1.11, >= 1.11.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (6.1.7.2)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 1.6, < 2)
|
14
|
+
minitest (>= 5.1)
|
15
|
+
tzinfo (~> 2.0)
|
16
|
+
zeitwerk (~> 2.3)
|
17
|
+
addressable (2.8.1)
|
18
|
+
public_suffix (>= 2.0.2, < 6.0)
|
19
|
+
concurrent-ruby (1.2.0)
|
20
|
+
crack (0.4.5)
|
21
|
+
rexml
|
22
|
+
diff-lcs (1.5.0)
|
23
|
+
docile (1.4.0)
|
24
|
+
hashdiff (1.0.1)
|
25
|
+
i18n (1.12.0)
|
26
|
+
concurrent-ruby (~> 1.0)
|
27
|
+
mini_portile2 (2.8.1)
|
28
|
+
minitest (5.17.0)
|
29
|
+
nokogiri (1.13.10)
|
30
|
+
mini_portile2 (~> 2.8.0)
|
31
|
+
racc (~> 1.4)
|
32
|
+
nokogiri (1.13.10-x64-mingw32)
|
33
|
+
racc (~> 1.4)
|
34
|
+
public_suffix (5.0.1)
|
35
|
+
racc (1.6.2)
|
36
|
+
rake (13.0.6)
|
37
|
+
rexml (3.2.5)
|
38
|
+
rspec (3.10.0)
|
39
|
+
rspec-core (~> 3.10.0)
|
40
|
+
rspec-expectations (~> 3.10.0)
|
41
|
+
rspec-mocks (~> 3.10.0)
|
42
|
+
rspec-core (3.10.2)
|
43
|
+
rspec-support (~> 3.10.0)
|
44
|
+
rspec-expectations (3.10.2)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.10.0)
|
47
|
+
rspec-mocks (3.10.3)
|
48
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
+
rspec-support (~> 3.10.0)
|
50
|
+
rspec-support (3.10.3)
|
51
|
+
simplecov (0.21.2)
|
52
|
+
docile (~> 1.1)
|
53
|
+
simplecov-html (~> 0.11)
|
54
|
+
simplecov_json_formatter (~> 0.1)
|
55
|
+
simplecov-html (0.12.3)
|
56
|
+
simplecov_json_formatter (0.1.4)
|
57
|
+
tzinfo (2.0.6)
|
58
|
+
concurrent-ruby (~> 1.0)
|
59
|
+
webmock (3.11.3)
|
60
|
+
addressable (>= 2.3.6)
|
61
|
+
crack (>= 0.3.2)
|
62
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
63
|
+
webrick (1.7.0)
|
64
|
+
yard (0.9.28)
|
65
|
+
webrick (~> 1.7.0)
|
66
|
+
zeitwerk (2.6.7)
|
67
|
+
|
68
|
+
PLATFORMS
|
69
|
+
ruby
|
70
|
+
x64-mingw32
|
71
|
+
|
72
|
+
DEPENDENCIES
|
73
|
+
contentstack_utils!
|
74
|
+
rake (~> 13.0.3)
|
75
|
+
rspec (~> 3.10.0)
|
76
|
+
simplecov (~> 0.21.1)
|
77
|
+
webmock (~> 3.11.0)
|
78
|
+
yard (~> 0.9.26)
|
79
|
+
|
80
|
+
BUNDLED WITH
|
81
|
+
2.3.13
|
data/LICENSE
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2012-
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2012-2023 Contentstack. All Rights Reserved
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,97 +1,97 @@
|
|
1
|
-
# Contentstack Utils Ruby
|
2
|
-
|
3
|
-
Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. Read More.
|
4
|
-
|
5
|
-
This guide will help you get started with Contentstack Ruby Utils SDK to build apps powered by Contentstack.
|
6
|
-
|
7
|
-
## Prerequisites
|
8
|
-
|
9
|
-
- Ruby version 2.0 or later
|
10
|
-
|
11
|
-
## SDK Installation and Setup
|
12
|
-
|
13
|
-
To set up Ruby Utils SDK, install it via gem:
|
14
|
-
```sh
|
15
|
-
gem install contentstack_utils
|
16
|
-
```
|
17
|
-
|
18
|
-
> Note: If you are using Contentstack Ruby SDK, then “contentstack/utils” is already imported into your project.
|
19
|
-
|
20
|
-
## Usage
|
21
|
-
|
22
|
-
Let’s learn how you can use Utils SDK to render embedded items.
|
23
|
-
|
24
|
-
### Create Render Option:
|
25
|
-
|
26
|
-
To render embedded items on the front-end, use the render_option function, and define the UI elements you want to show in the front-end of your website, as shown in the example code below:
|
27
|
-
```ruby
|
28
|
-
class CustomLOption < ContentstackUtils::Model::Option
|
29
|
-
def render_option(embeddedObject, metadata)
|
30
|
-
case metadata.style_type
|
31
|
-
when 'block'
|
32
|
-
if metadataArray.content_type_uid === 'product'
|
33
|
-
return "<div>
|
34
|
-
<h2 >#{embeddedObject["title"]}</h2>
|
35
|
-
<img src=#{embeddedObject["product_image"]["url"]} alt=#{embeddedObject["product_image"]["title"]}/>
|
36
|
-
<p>#{embeddedObject["price"]}</p>
|
37
|
-
</div>"
|
38
|
-
end
|
39
|
-
when 'inline'
|
40
|
-
return "<span><b>#{embeddedObject["title"]}</b> - #{embeddedObject["description"]}</span>"
|
41
|
-
when link
|
42
|
-
return "<a href='#{metadata.attributes["href"].value}'>#{metadata.text}</a>"
|
43
|
-
when 'display'
|
44
|
-
return "<img src='#{metadata.attributes["src"].value}' alt='#{metadata.alt}' />"
|
45
|
-
when download
|
46
|
-
return "<a href='#{metadata.attributes["href"].value}'>#{metadata.text}</a>"
|
47
|
-
end
|
48
|
-
super(embeddedObject, metadata)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
```
|
52
|
-
## Basic Queries
|
53
|
-
|
54
|
-
Contentstack Utils SDK lets you interact with the Content Delivery APIs and retrieve embedded items from the RTE field of an entry.
|
55
|
-
|
56
|
-
### Fetch Embedded Item(s) from a Single Entry:
|
57
|
-
|
58
|
-
To get an embedded item of a single entry, you need to provide the stack API key, environment name, delivery token, content type’s UID, and entry’s UID. Then, use the include_embedded_items function as shown below:
|
59
|
-
```ruby
|
60
|
-
require 'contentstack'
|
61
|
-
|
62
|
-
@stack = Contentstack::Client.new('<API_KEY>', '<ENVIRONMENT_SPECIFIC_DELIVERY_TOKEN>', '<ENVIRONMENT>')
|
63
|
-
@entry = @stack.content_type('<CONTENT_TYPE>').entry('<ENTRY_UID>')
|
64
|
-
.include_embedded_items
|
65
|
-
.fetch
|
66
|
-
|
67
|
-
@rendered_rich_text = Contentstack.render_content(@entry.rte_field_uid, ContentstackUtils::Model::Option.new(@entry))
|
68
|
-
```
|
69
|
-
|
70
|
-
If you want to render embedded items using the CustomOption function, you can refer to the code below:
|
71
|
-
```ruby
|
72
|
-
@rendered_rich_text = Contentstack.render_content(@entry.rte_field_uid, CustomLOption.new(@entry))
|
73
|
-
```
|
74
|
-
### Fetch Embedded Item(s) from Multiple Entries
|
75
|
-
|
76
|
-
To get embedded items from multiple entries, you need to provide the stack API key, environment name, delivery token, and content type’s UID.
|
77
|
-
```ruby
|
78
|
-
require 'contentstack'
|
79
|
-
@stack = Contentstack::Client.new('<API_KEY>', '<ENVIRONMENT_SPECIFIC_DELIVERY_TOKEN>', '<ENVIRONMENT>')
|
80
|
-
@query = @stack.content_type('<CONTENT_TYPE>').query
|
81
|
-
@entries = @query.where('title', 'welcome')
|
82
|
-
.include_embedded_items
|
83
|
-
.fetch
|
84
|
-
|
85
|
-
@entries.each do |entry|
|
86
|
-
Contentstack.render_content(@entry.rte_field_uid, ContentstackUtils::Model::Option.new(@entry))
|
87
|
-
end
|
88
|
-
```
|
89
|
-
### GQL Json RTE to HTML
|
90
|
-
To parse JSON RTE content from GQL response to HTML content use `ContentstackUtils::GQL.json_to_html` function as below:
|
91
|
-
|
92
|
-
```ruby
|
93
|
-
require 'contentstack_utils'
|
94
|
-
|
95
|
-
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
96
|
-
|
1
|
+
# Contentstack Utils Ruby
|
2
|
+
|
3
|
+
Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. Read More.
|
4
|
+
|
5
|
+
This guide will help you get started with Contentstack Ruby Utils SDK to build apps powered by Contentstack.
|
6
|
+
|
7
|
+
## Prerequisites
|
8
|
+
|
9
|
+
- Ruby version 2.0 or later
|
10
|
+
|
11
|
+
## SDK Installation and Setup
|
12
|
+
|
13
|
+
To set up Ruby Utils SDK, install it via gem:
|
14
|
+
```sh
|
15
|
+
gem install contentstack_utils
|
16
|
+
```
|
17
|
+
|
18
|
+
> Note: If you are using Contentstack Ruby SDK, then “contentstack/utils” is already imported into your project.
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Let’s learn how you can use Utils SDK to render embedded items.
|
23
|
+
|
24
|
+
### Create Render Option:
|
25
|
+
|
26
|
+
To render embedded items on the front-end, use the render_option function, and define the UI elements you want to show in the front-end of your website, as shown in the example code below:
|
27
|
+
```ruby
|
28
|
+
class CustomLOption < ContentstackUtils::Model::Option
|
29
|
+
def render_option(embeddedObject, metadata)
|
30
|
+
case metadata.style_type
|
31
|
+
when 'block'
|
32
|
+
if metadataArray.content_type_uid === 'product'
|
33
|
+
return "<div>
|
34
|
+
<h2 >#{embeddedObject["title"]}</h2>
|
35
|
+
<img src=#{embeddedObject["product_image"]["url"]} alt=#{embeddedObject["product_image"]["title"]}/>
|
36
|
+
<p>#{embeddedObject["price"]}</p>
|
37
|
+
</div>"
|
38
|
+
end
|
39
|
+
when 'inline'
|
40
|
+
return "<span><b>#{embeddedObject["title"]}</b> - #{embeddedObject["description"]}</span>"
|
41
|
+
when link
|
42
|
+
return "<a href='#{metadata.attributes["href"].value}'>#{metadata.text}</a>"
|
43
|
+
when 'display'
|
44
|
+
return "<img src='#{metadata.attributes["src"].value}' alt='#{metadata.alt}' />"
|
45
|
+
when download
|
46
|
+
return "<a href='#{metadata.attributes["href"].value}'>#{metadata.text}</a>"
|
47
|
+
end
|
48
|
+
super(embeddedObject, metadata)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
```
|
52
|
+
## Basic Queries
|
53
|
+
|
54
|
+
Contentstack Utils SDK lets you interact with the Content Delivery APIs and retrieve embedded items from the RTE field of an entry.
|
55
|
+
|
56
|
+
### Fetch Embedded Item(s) from a Single Entry:
|
57
|
+
|
58
|
+
To get an embedded item of a single entry, you need to provide the stack API key, environment name, delivery token, content type’s UID, and entry’s UID. Then, use the include_embedded_items function as shown below:
|
59
|
+
```ruby
|
60
|
+
require 'contentstack'
|
61
|
+
|
62
|
+
@stack = Contentstack::Client.new('<API_KEY>', '<ENVIRONMENT_SPECIFIC_DELIVERY_TOKEN>', '<ENVIRONMENT>')
|
63
|
+
@entry = @stack.content_type('<CONTENT_TYPE>').entry('<ENTRY_UID>')
|
64
|
+
.include_embedded_items
|
65
|
+
.fetch
|
66
|
+
|
67
|
+
@rendered_rich_text = Contentstack.render_content(@entry.rte_field_uid, ContentstackUtils::Model::Option.new(@entry))
|
68
|
+
```
|
69
|
+
|
70
|
+
If you want to render embedded items using the CustomOption function, you can refer to the code below:
|
71
|
+
```ruby
|
72
|
+
@rendered_rich_text = Contentstack.render_content(@entry.rte_field_uid, CustomLOption.new(@entry))
|
73
|
+
```
|
74
|
+
### Fetch Embedded Item(s) from Multiple Entries
|
75
|
+
|
76
|
+
To get embedded items from multiple entries, you need to provide the stack API key, environment name, delivery token, and content type’s UID.
|
77
|
+
```ruby
|
78
|
+
require 'contentstack'
|
79
|
+
@stack = Contentstack::Client.new('<API_KEY>', '<ENVIRONMENT_SPECIFIC_DELIVERY_TOKEN>', '<ENVIRONMENT>')
|
80
|
+
@query = @stack.content_type('<CONTENT_TYPE>').query
|
81
|
+
@entries = @query.where('title', 'welcome')
|
82
|
+
.include_embedded_items
|
83
|
+
.fetch
|
84
|
+
|
85
|
+
@entries.each do |entry|
|
86
|
+
Contentstack.render_content(@entry.rte_field_uid, ContentstackUtils::Model::Option.new(@entry))
|
87
|
+
end
|
88
|
+
```
|
89
|
+
### GQL Json RTE to HTML
|
90
|
+
To parse JSON RTE content from GQL response to HTML content use `ContentstackUtils::GQL.json_to_html` function as below:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
require 'contentstack_utils'
|
94
|
+
|
95
|
+
result = ContentstackUtils::GQL.json_to_html(entry['single_rte'], ContentstackUtils::Model::Options.new())
|
96
|
+
|
97
97
|
```
|