Skip to content

Commit 28807be

Browse files
Merge pull request #2 from contentstack/supercharge-rte
Supercharge rte
2 parents ca9b8fe + b7b9b38 commit 28807be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+4548
-3234
lines changed

.talismanrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
threshold: medium

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2020 Contentstack
1+
Copyright 2021 Contentstack
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
44

README.md

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ Contentstack Utils SDK lets you interact with the Content Delivery APIs and retr
6464
To get an embedded item of a single entry, you need to provide the stack API key, environment name, content type’s UID, and entry’s UID. Then, use the `entry.fetch` function as shown below:
6565

6666
```python
67-
import contentstack
67+
import contentstack
6868

69-
stack = contentstack.Stack('api_key','delivery_token','environment')
70-
content_type = stack.content_type("content_type_uid")
71-
entry = content_type.entry("entry_uid")
72-
result = entry.fetch()
73-
if result is not None:
74-
entry = result['entries']
75-
Utils.render(entry, ['rich_text_editor', 'some_other_text'], Option())
69+
stack = contentstack.Stack('api_key','delivery_token','environment')
70+
content_type = stack.content_type("content_type_uid")
71+
entry = content_type.entry("entry_uid")
72+
result = entry.fetch()
73+
if result is not None:
74+
entry = result['entries']
75+
Utils.render(entry, ['rich_text_editor', 'some_other_text'], Option())
7676

7777
```
7878

@@ -81,13 +81,32 @@ To get an embedded item of a single entry, you need to provide the stack API key
8181
To get embedded items from multiple entries, you need to provide the stack API key, delivery token, environment name, and content type’s UID.
8282

8383
```python
84-
import contentstack
85-
86-
stack = contentstack.Stack('api_key','delivery_token','environment')
87-
query = stack.content_type("content_type_uid").query()
88-
result = query.find()
89-
if result is not None and 'entries' in result:
90-
entry = result['entries']
91-
for item in range:
92-
Utils.render(item, ['rich_text_editor', 'some_other_text'], Option())
84+
import contentstack
85+
86+
stack = contentstack.Stack('api_key','delivery_token','environment')
87+
query = stack.content_type("content_type_uid").query()
88+
result = query.find()
89+
if result is not None and 'entries' in result:
90+
entry = result['entries']
91+
for item in range:
92+
option = Option()
93+
Utils.render(item, ['rich_text_editor', 'some_other_text'], option)
94+
```
95+
96+
97+
## Supercharged
98+
99+
To get supercharged items from multiple entries, you need to provide the stack API key, delivery token, environment name, and content type’s UID.
100+
101+
```python
102+
import contentstack
103+
104+
stack = contentstack.Stack('api_key','delivery_token','environment')
105+
query = stack.content_type("content_type_uid").query()
106+
result = query.find()
107+
if result is not None and 'entries' in result:
108+
entry = result['entries']
109+
for item in range:
110+
option = Option()
111+
Utils.json_to_html(item, ['paragraph_text'], option)
93112
```

changelog.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
**CHANGELOG**
33
================
44

5+
NEW FEATURE: Supercharged RTE
6+
7+
- jsonToHtml function support added
8+
9+
*v0.2.0*
10+
============
11+
12+
**Date: 02-Sept-2021**
13+
14+
- Initial release of contentstack utility package
15+
16+
517
ENHANCEMENT, NEW FEATURE, BUG RESOLVE
618

719
*v0.1.0*

contentstack_utils/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
# coverage report -m
44
# coverage html -d coveragereport
55
"""
6-
The __init__.py files are required to make Python treat the directories as containing
7-
packages; this is done to prevent directories with a common name, such as string,
8-
from unintentionally hiding valid modules that occur later on the module search path
9-
Used: Safety checks your installed dependencies for known security vulnerabilities
10-
file __init__.py contains package information like
11-
126
__author__, __status__, __version__, __endpoint__ and __email__
137
148
`Your code has been rated at 10.00/10`

contentstack_utils/embedded/item_type.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010

1111

1212
class ItemType(enum.Enum):
13-
"""
14-
Contains Two option for ItemsType
15-
16-
ENTRY
17-
ASSET
18-
"""
13+
"""Contains Two option for ItemsType => ENTRY and ASSET """
1914
ENTRY = 'entry'
2015
ASSET = 'asset'

contentstack_utils/embedded/styletype.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ class StyleType(enum.Enum):
1010

1111
"""
1212
This StyleType contains four options like below.
13-
14-
BLOCK
15-
INLINE
16-
LINK
17-
DISPLAY
18-
DOWNLOAD
13+
BLOCK ,INLINE ,LINK,DISPLAY,DOWNLOAD
1914
"""
2015

2116
BLOCK = 'block'

contentstack_utils/helper/converter.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ def convert_style(style) -> StyleType:
1212
return StyleType.DISPLAY
1313
elif style == 'download':
1414
return StyleType.DOWNLOAD
15-

contentstack_utils/helper/metadata.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,63 +38,28 @@ def __init__(self, text: str, item_type: str, item_uid: str,
3838

3939
@property
4040
def get_text(self):
41-
"""text for embedded objects
42-
43-
Returns:
44-
str : text for embedded objects
45-
"""
4641
return self.text
4742

4843
@property
4944
def get_item_type(self):
50-
"""item_type for embedded objects
51-
52-
Returns:
53-
str : item_type for embedded objects
54-
"""
5545
return self.item_type
5646

5747
@property
5848
def get_item_uid(self):
59-
"""item_uid for embedded objects
60-
61-
Returns:
62-
str : item_uid for embedded objects
63-
"""
6449
return self.item_uid
6550

6651
@property
6752
def get_content_type_uid(self):
68-
"""content_type_uid for embedded objects
69-
70-
Returns:
71-
str : content_type_uid for embedded objects
72-
"""
7353
return self.content_type_uid
7454

7555
@property
7656
def get_style_type(self) -> StyleType:
77-
"""style_type for embedded objects
78-
79-
Returns:
80-
StyleType : style_type for embedded objects
81-
"""
8257
return self.style_type
8358

8459
@property
8560
def get_outer_html(self):
86-
"""outer_html for embedded objects
87-
88-
Returns:
89-
str : outer_html for embedded objects
90-
"""
9161
return self.outer_html
9262

9363
@property
9464
def get_attributes(self):
95-
"""attributes for embedded objects
96-
97-
Returns:
98-
str : attributes for embedded objects
99-
"""
10065
return self.attributes
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from contentstack_utils.render.options import Options
2+
3+
4+
class NodeToHtml:
5+
6+
@staticmethod
7+
def text_node_to_html(node, option: Options):
8+
"""
9+
accepts node type,
10+
on the basis of the node type, generates string
11+
:rtype: str
12+
"""
13+
node_text = node['text']
14+
if 'superscript' in node:
15+
node_text = option.render_mark('superscript', node_text)
16+
if 'subscript' in node:
17+
node_text = option.render_mark('subscript', node_text)
18+
if 'inlineCode' in node:
19+
node_text = option.render_mark('inlineCode', node_text)
20+
if 'strikethrough' in node:
21+
node_text = option.render_mark('strikethrough', node_text)
22+
if 'underline' in node:
23+
node_text = option.render_mark('underline', node_text)
24+
if 'italic' in node:
25+
node_text = option.render_mark('italic', node_text)
26+
if 'bold' in node:
27+
node_text = option.render_mark('bold', node_text)
28+
return node_text

0 commit comments

Comments
 (0)