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
28610d87
Kaydet (Commit)
28610d87
authored
Ock 01, 2019
tarafından
Batuhan Osman TASKAYA
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Pass the f*cking tests
üst
b070dd46
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
46 deletions
+20
-46
darwcss.py
darwcss/darwcss.py
+19
-40
test_conf.py
tests/test_conf.py
+1
-6
No files found.
darwcss/darwcss.py
Dosyayı görüntüle @
28610d87
...
...
@@ -10,6 +10,7 @@ from operator import attrgetter
from
functools
import
partial
from
dataclasses
import
dataclass
,
field
,
fields
,
MISSING
from
collections
import
UserDict
from
random
import
randint
"""
noqa:F821 = https://github.com/PyCQA/pyflakes/issues/373
...
...
@@ -62,6 +63,10 @@ def init(*values, **kwds):
def
fake_init
(
cls
,
fields
):
return
cls
(
**
dict
(
zip
(
map
(
attrgetter
(
"name"
),
fields
),
value_generator
(
fields
))))
def
attr_get
(
self
,
name
):
print
(
self
,
name
)
return
getattr
(
self
.
_self
,
name
)
def
configurable_dataclass
(
*
args
,
**
kwargs
):
cls
=
dataclass
(
*
args
,
**
kwargs
)
...
...
@@ -71,7 +76,7 @@ def configurable_dataclass(*args, **kwargs):
cls_fields
=
fields
(
cls
)
cls
.
_self
=
fake_init
(
cls
,
cls_fields
)
cls
.
__init__
=
partial
(
init
,
self
=
cls
,
fields
=
cls_fields
+
(
meta_conf
,))
cls
.
__getattr__
=
lambda
self
,
name
:
getattr
(
self
.
_self
,
name
)
cls
.
__getattr__
=
lambda
self
,
name
:
attr_get
(
self
.
_self
,
name
)
return
cls
...
...
@@ -145,49 +150,26 @@ class NumericValue(RenderableObject):
return
f
"{self.value}{self.unit}"
@
configurable_
dataclass
@dataclass
class
Style
:
name
:
str
value
:
Any
important
:
bool
=
False
def
__
after
_init__
(
self
)
->
None
:
def
__
post
_init__
(
self
)
->
None
:
self
.
value
=
render
(
self
.
value
)
f
=
currentframe
()
.
f_back
.
f_back
# type: ignore
f
=
currentframe
()
.
f_back
.
f_back
# type: ignore
l
,
g
=
f
.
f_locals
,
f
.
f_globals
"""
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:
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"
)),
if
l
.
get
(
"DARWCSS_AUTO"
,
g
.
get
(
"DARWCSS_AUTO"
,
False
)):
try
:
selector_name
=
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
)
selector
=
l
[
selector_name
]
except
KeyError
as
exc
:
raise
NameError
(
f
"Selector can not found in local namespace."
)
from
exc
else
:
selector
.
append
(
self
)
@configurable_dataclass
...
...
@@ -203,11 +185,8 @@ class Selector:
return
self
def
append
(
self
,
style
:
Style
)
->
None
:
if
not
style
.
meta_cfg
:
style
.
meta_cfg
=
self
.
meta_cfg
self
.
styles
.
append
(
style
)
class
CSS
:
def
__init__
(
self
,
conf
:
Optional
[
Dict
]
=
None
)
->
None
:
self
.
selectors
:
Dict
[
str
,
Selector
]
=
{}
...
...
tests/test_conf.py
Dosyayı görüntüle @
28610d87
...
...
@@ -3,16 +3,11 @@ 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
)
self
.
assertEqual
(
selector
.
meta_cfg
,
{
"darwcss_auto"
:
True
})
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