Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
Darwcss
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
Darwcss
Commits
02b22579
Kaydet (Commit)
02b22579
authored
Ara 30, 2018
tarafından
Batuhan Osman TASKAYA
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Configuration
üst
a3bc74c0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
24 deletions
+74
-24
darwcss.py
darwcss/darwcss.py
+55
-23
setup.py
setup.py
+1
-1
test_conf.py
tests/test_conf.py
+18
-0
No files found.
darwcss/darwcss.py
Dosyayı görüntüle @
02b22579
...
...
@@ -7,17 +7,22 @@ from textwrap import indent
from
colorsys
import
rgb_to_hls
from
enum
import
Enum
"""
noqa:F821 = https://github.com/PyCQA/pyflakes/issues/373
"""
def
clean_name
(
css_name
:
str
)
->
str
:
if
css_name
.
startswith
(
'.'
):
css_name
=
css_name
.
replace
(
'.'
,
'cls_'
,
1
)
elif
css_name
.
startswith
(
'#'
):
css_name
=
css_name
.
replace
(
'#'
,
'id_'
,
1
)
if
css_name
.
startswith
(
"."
):
css_name
=
css_name
.
replace
(
"."
,
"cls_"
,
1
)
elif
css_name
.
startswith
(
"#"
):
css_name
=
css_name
.
replace
(
"#"
,
"id_"
,
1
)
else
:
pass
return
css_name
def
render
(
obj
:
Any
)
->
str
:
if
hasattr
(
obj
,
"__render__"
):
return
obj
.
__render__
()
...
...
@@ -31,7 +36,7 @@ class RenderableObject:
def
__render__
(
self
)
->
str
:
pass
def
__add__
(
self
,
other
:
RenderableObject
)
->
str
:
# noqa:F821
https://github.com/PyCQA/pyflakes/issues/373
def
__add__
(
self
,
other
:
RenderableObject
)
->
str
:
# noqa:F821
return
f
"{render(self)} {render(other)}"
def
__radd__
(
self
,
other
:
RenderableObject
)
->
str
:
# noqa:F821
...
...
@@ -82,37 +87,64 @@ class Style:
name
:
str
value
:
Any
important
:
bool
=
False
meta_cfg
:
Dict
[
str
,
Any
]
=
field
(
default_factory
=
dict
)
def
__post_init__
(
self
)
->
None
:
self
.
value
=
render
(
self
.
value
)
f
=
currentframe
()
.
f_back
.
f_back
# type: ignore
l
,
g
=
f
.
f_locals
,
f
.
f_globals
if
l
.
get
(
"DARWCSS_AUTO"
,
g
.
get
(
"DARWCSS_AUTO"
,
False
)):
try
:
selector_name
=
l
.
get
(
"DARWCSS_SELECTOR"
,
g
.
get
(
"DARWCSS_SELECTOR"
,
"selector"
)
)
selector
=
l
[
selector_name
]
except
KeyError
as
exc
:
raise
NameError
(
f
"Selector can not found in local namespace."
)
from
exc
"""
if not self.meta_cfg:
# Search and find closest css object
css = [value for value in l.values() if isinstance(value, CSS)]
if len(css) < 1:
css = [value for value in g.values() if isinstance(value, CSS)]
if len(css) != 1:
raise NotImplementedError("Autoadder couldn't determine what to do! Aborting process")
else:
self.meta_cfg = css.meta_cfg
elif len(css) == 1:
self.meta_cfg = css.meta_cfg
else:
selector
.
append
(
self
)
raise NotImplementedError("Autoadder couldn't determine what to do! Aborting process")
"""
if
not
self
.
meta_cfg
.
get
(
"darwcss_auto"
,
l
.
get
(
"DARWCSS_AUTO"
,
g
.
get
(
"DARWCSS_AUTO"
,
False
))
):
return
None
try
:
selector
=
l
[
self
.
meta_cfg
.
get
(
"darwcss_selector"
,
l
.
get
(
"DARWCSS_SELECTOR"
,
g
.
get
(
"DARWCSS_SELECTOR"
,
"selector"
)),
)
]
except
KeyError
as
exc
:
raise
NameError
(
f
"Selector can not found in local namespace."
)
from
exc
else
:
selector
.
append
(
self
)
@dataclass
class
Selector
:
area
:
str
styles
:
List
[
Style
]
=
field
(
default_factory
=
list
)
meta_cfg
:
Dict
[
str
,
Any
]
=
field
(
default_factory
=
dict
)
def
__add__
(
self
,
other
:
Style
)
->
None
:
self
.
styles
.
append
(
other
)
self
.
append
(
other
)
def
__iadd__
(
self
,
other
:
Style
)
->
Selector
:
# noqa:F821
self
+
other
def
__iadd__
(
self
,
other
:
Style
)
->
Selector
:
# noqa:F821
self
.
__add__
(
other
)
return
self
def
append
(
self
,
other
:
Style
)
->
None
:
self
.
styles
.
append
(
other
)
def
append
(
self
,
style
:
Style
)
->
None
:
if
not
style
.
meta_cfg
:
style
.
meta_cfg
=
self
.
meta_cfg
self
.
styles
.
append
(
style
)
class
CSS
:
...
...
@@ -131,7 +163,7 @@ class CSS:
@contextmanager
def
selector
(
self
,
area
:
str
)
->
Generator
[
Selector
,
None
,
None
]:
selector
=
Selector
(
area
)
selector
=
Selector
(
area
,
meta_cfg
=
self
.
conf
)
try
:
yield
selector
finally
:
...
...
@@ -139,6 +171,6 @@ class CSS:
def
__getitem__
(
self
,
key
:
str
)
->
Selector
:
return
self
.
selectors
[
key
]
__call__
=
render
__getattr__
=
__getitem__
setup.py
Dosyayı görüntüle @
02b22579
...
...
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup
(
name
=
"darwcss"
,
version
=
"0.2.
2
"
,
version
=
"0.2.
3
"
,
author
=
"BTaskaya"
,
author_email
=
"batuhanosmantaskaya@gmail.com"
,
packages
=
find_packages
(),
...
...
tests/test_conf.py
0 → 100644
Dosyayı görüntüle @
02b22579
import
unittest
from
darwcss.darwcss
import
CSS
,
Selector
,
Style
class
TestConf
(
unittest
.
TestCase
):
rendered_css
=
".home{
\n
a: b;
\n
c: d;
\n
}
\n
"
def
test_conf_inheritance_selector
(
self
):
css
=
CSS
({
"darwcss_auto"
:
True
})
with
css
.
selector
(
'.home'
)
as
selector
:
selector
+=
Style
(
"a"
,
"b"
)
selector
+=
Style
(
"c"
,
"d"
)
self
.
assertEqual
(
css
.
render
(),
self
.
rendered_css
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment