Skip to content

Commit ff2e251

Browse files
shaileshmishrashaileshmishra
authored andcommitted
initial push
0 parents  commit ff2e251

19 files changed

+1588
-0
lines changed

.gitignore

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
/reports
9+
/tests/reports
10+
# Distribution / packaging
11+
.Python
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
*.DS_Store
29+
*.DS_Store?
30+
.pytest_cache
31+
.idea
32+
.vscode
33+
.report.log
34+
35+
# PyInstaller
36+
# Usually these files are written by a python script from a template
37+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
38+
*.manifest
39+
*.spec
40+
41+
# Installer logs
42+
pip-log.txt
43+
pip-delete-this-directory.txt
44+
45+
# Unit test / coverage reports
46+
htmlcov/
47+
.tox/
48+
.coverage
49+
.coverage.*
50+
.cache
51+
nosetests.xml
52+
coverage.xml
53+
*.cover
54+
.hypothesis/
55+
.pytest_cache/
56+
57+
# Translations
58+
*.mo
59+
*.pot
60+
61+
# Django stuff:
62+
*.log
63+
local_settings.py
64+
db.sqlite3
65+
66+
# Flask stuff:
67+
instance/
68+
.webassets-cache
69+
70+
# Scrapy stuff:
71+
.scrapy
72+
73+
# Sphinx documentation
74+
docs/_build/
75+
76+
# PyBuilder
77+
target/
78+
79+
# Jupyter Notebook
80+
.ipynb_checkpoints
81+
82+
# pyenv
83+
.python-version
84+
85+
# celery beat schedule file
86+
celerybeat-schedule
87+
88+
# SageMath parsed files
89+
*.sage.py
90+
91+
# Environments
92+
.env
93+
.venv
94+
env/
95+
venv/
96+
ENV/
97+
env.bak/
98+
venv.bak/
99+
100+
# Spyder project settings
101+
.spyderproject
102+
.spyproject
103+
104+
# Rope project settings
105+
.ropeproject
106+
107+
# mkdocs documentation
108+
/site
109+
110+
# mypy
111+
.mypy_cache/
112+
.idea/
113+
.vscode/

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2020 Contentstack
2+
3+
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:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Whitespace-only changes.

changelog.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
================
2+
**CHANGELOG**
3+
================
4+
5+
ENHANCEMENT, NEW FEATURE, BUG RESOLVE
6+
7+
*v0.0.1*
8+
============
9+
10+
**Date: 20-Nov-2020**
11+
12+
- initial release of contentstack utility package

contentstack/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# The __init__.py files are required to make Python treat the directories as containing
2+
# packages; this is done to prevent directories with a common name, such as string,
3+
# from unintentionally hiding valid modules that occur later on the module search path
4+
# Used: Safety checks your installed dependencies for known security vulnerabilities
5+
# file __init__.py contains package information like
6+
# __author__, __status__, __version__, __endpoint__ and __email__
7+
8+
from .embedded.item_type import ItemType
9+
from .embedded.style_type import StyleType
10+
from .helper.metadata import Metadata
11+
from .render.default_options import DefaultOptions
12+
from .render.options import OptionsCallback
13+
from .utils import Utils
14+
15+
__title__ = 'Contentstack'
16+
__author__ = 'Contentstack'
17+
__status__ = 'debug'
18+
__version__ = '0.0.1'
19+
__endpoint__ = 'cdn.contentstack.io'
20+
__email__ = 'shailesh.mishra@contentstack.com'

contentstack/embedded/item_type.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import enum
2+
3+
4+
class ItemType(enum.Enum):
5+
"""
6+
"""
7+
ENTRY = 'entry'
8+
ASSET = 'asset'
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
""""
2+
For `Entry`: StyleType.BLOCK, StyleType.INLINE, StyleType.LINKED,
3+
For `Assets`: StyleType.DISPLAY, StyleType.DOWNLOADABLE
4+
"""
5+
import enum
6+
7+
8+
class StyleType(enum.Enum):
9+
10+
BLOCK = "block"
11+
INLINE = 'inline'
12+
LINK = 'link'
13+
DISPLAY = 'displayable'
14+
DOWNLOADABLE = 'downloadable'

contentstack/helper/metadata.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from contentstack.embedded.style_type import StyleType
2+
3+
4+
class Metadata:
5+
6+
def __init__(self, text: str, item_type: str, item_uid: str, content_type_uid: str, style_type: StyleType,
7+
outer_html: str, attributes: str):
8+
self.text = text
9+
self.item_type = item_type
10+
self.item_uid = item_uid
11+
self.content_type_uid = content_type_uid
12+
self.style_type = style_type
13+
self.outer_html = outer_html
14+
self.attributes = attributes
15+
16+
# getter get_text() method
17+
@property
18+
def get_text(self):
19+
return self.text
20+
21+
# getter get_item_type() method
22+
@property
23+
def get_item_type(self):
24+
return self.item_type
25+
26+
# getter get_item_uid() method
27+
@property
28+
def get_item_uid(self):
29+
return self.item_uid
30+
31+
# getter get_content_type_uid() method
32+
@property
33+
def get_content_type_uid(self):
34+
return self.content_type_uid
35+
36+
# getter get_style_type() method
37+
@property
38+
def get_style_type(self):
39+
return self.style_type
40+
41+
# getter get_outer_html() method
42+
@property
43+
def get_outer_html(self):
44+
return self.outer_html
45+
46+
# getter get_attributes() method
47+
@property
48+
def get_attributes(self):
49+
return self.attributes
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# pylint: disable=missing-function-docstring
2+
# pylint: disable=missing-docstring
3+
# pylint: disable=too-few-public-methods
4+
5+
from contentstack.helper.metadata import Metadata
6+
7+
8+
def _title_or_uid(embedded_obj: dict) -> str:
9+
_title = ""
10+
if embedded_obj is not None:
11+
if 'title' in embedded_obj and len(embedded_obj['title']) != 0:
12+
_title = embedded_obj['title']
13+
elif 'uid' in embedded_obj:
14+
_title = embedded_obj['uid']
15+
return _title
16+
17+
18+
def _asset_title_or_uid(embedded_obj: dict) -> str:
19+
_title = ""
20+
if embedded_obj is not None:
21+
if 'title' in embedded_obj and len(embedded_obj['title']) != 0:
22+
_title = embedded_obj['title']
23+
elif 'filename' in embedded_obj:
24+
_title = embedded_obj['filename']
25+
elif 'uid' in embedded_obj:
26+
_title = embedded_obj['uid']
27+
return _title
28+
29+
30+
class DefaultOptions:
31+
32+
@staticmethod
33+
def render_options(embedded_obj: dict, metadata: Metadata) -> str:
34+
if metadata.style_type.name == 'block':
35+
return '<div><p>' + _title_or_uid(embedded_obj) \
36+
+ '</p><div><p>Content type: <span>' + embedded_obj['_content_type_uid'] \
37+
+ '</span></p></div>'
38+
elif metadata.style_type.name == 'inline':
39+
return '<span>' + _title_or_uid(embedded_obj) + '</span>'
40+
elif metadata.style_type.name == 'link':
41+
return '<a href=' + embedded_obj['url'] + '>' + _title_or_uid(embedded_obj) + '</a>'
42+
elif metadata.style_type.name == 'display':
43+
return '<img src=' + embedded_obj['url'] + ' alt=' \
44+
+ _asset_title_or_uid(embedded_obj) + '/>'
45+
return ''

contentstack/render/options.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# pylint: disable=missing-function-docstring
2+
from contentstack.helper.metadata import Metadata
3+
4+
5+
class OptionsCallback:
6+
7+
@staticmethod
8+
def render_options(self, embedded_obj: dict, metadata: Metadata) -> str:
9+
return 'string'

0 commit comments

Comments
 (0)