Skip to content

Commit ff5848a

Browse files
Keyframerules (#3)
* add border property * change to Visitor pattern * Add converter for Css Media/FontFace/KeyFrames-Rules Co-authored-by: Jens Klingenberg <[email protected]>
1 parent fba399d commit ff5848a

26 files changed

+924
-638
lines changed

converter/src/main/kotlin/de/jensklingenberg/htmltocfw/converter/Attributes.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package de.jensklingenberg.htmltocfw.converter
22

3+
import de.jensklingenberg.htmltocfw.converter.node.ComposeAttribute
34
import org.jsoup.nodes.Attribute
45

6+
fun parseAttributes(attributesList: List<Attribute>): String {
7+
return parseAttributes(attributesList.map { ComposeAttribute(it.key,it.value) })
8+
}
9+
510
/**
611
*
712
*/
8-
fun parseAttributes(attributesList: List<Attribute>): String {
13+
@JvmName("parseAttributes1")
14+
fun parseAttributes(attributesList: List<ComposeAttribute>): String {
915

1016
var str = ""
1117
attributesList.forEachIndexed { index, attribute ->
@@ -21,7 +27,7 @@ fun parseAttributes(attributesList: List<Attribute>): String {
2127
"draggable(Draggable.${attribute.value.capitalize()})"
2228
}
2329
"style" -> {
24-
parseStyleText(attribute)
30+
parseStyleText(ComposeAttribute(attribute.key,attribute.value))
2531
}
2632
"required", "hidden", "selected", "disabled" -> {
2733
attribute.key + "()"
@@ -45,6 +51,7 @@ fun parseAttributes(attributesList: List<Attribute>): String {
4551
}
4652
}
4753
str += "\n"
54+
4855
if (index == attributesList.lastIndex) {
4956
str += "}"
5057
}

converter/src/main/kotlin/de/jensklingenberg/htmltocfw/converter/Main.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package de.jensklingenberg.htmltocfw.converter
22

3+
import de.jensklingenberg.htmltocfw.converter.node.LayoutNode
4+
import de.jensklingenberg.htmltocfw.converter.visitor.MyVisitor
35
import de.jensklingenberg.htmltocfw.converter.node.getMyNode
46
import org.jsoup.parser.ParseSettings
57
import org.jsoup.parser.Parser
@@ -8,11 +10,11 @@ import java.io.File
810
fun main() {
911

1012
val html =
11-
File("/Users/jklingenberg/Code/2021/jk/HtmlToComposeWebConverter/converter/src/main/kotlin/de/jensklingenberg/htmltocfw/converter/html.text").readText()
13+
File("/home/jens/Code/2021/jk/HtmlToComposeWeb/converter/src/main/kotlin/de/jensklingenberg/htmltocfw/converter/html.text").readText()
1214

1315
val text = htmlToCompose(html)
1416

15-
File("/Users/jklingenberg/Code/2021/jk/HtmlToComposeWebConverter/converter/src/main/kotlin/de/jensklingenberg/htmltocfw/converter/Result.txt").writeText(
17+
File("/home/jens/Code/2021/jk/HtmlToComposeWeb/converter/src/main/kotlin/de/jensklingenberg/htmltocfw/converter/Result.txt").writeText(
1618
text
1719
)
1820
}
@@ -33,14 +35,14 @@ fun htmlToCompose(html: String): String {
3335
getMyNode(node).toString()
3436
}
3537

36-
val wrappedBody = if (hasStyle) {
38+
val bodyContent = if (hasStyle) {
3739
"Style(appStylesheet())\n$body"
3840
} else {
3941
body
4042
}
4143

4244

43-
return "@Composable\nfun GeneratedComposable(){\n $head \n$wrappedBody}\n"
45+
return "@Composable\nfun GeneratedComposable(){\n $head \n$bodyContent}\n"
4446
}
4547

4648

Lines changed: 19 additions & 244 deletions
Original file line numberDiff line numberDiff line change
@@ -1,258 +1,33 @@
11
@Composable
22
fun GeneratedComposable(){
3-
document.title="Page Title"
4-
fun appStylesheet() = object : StyleSheet() {
5-
init {
6-
"*" style {
7-
boxSizing("border-box")
8-
}
9-
"body" style {
10-
fontFamily("Arial")
11-
property("margin","0")
12-
}
13-
".header" style {
14-
padding(60.px)
15-
textAlign("center")
16-
property("background","#1abc9c")
17-
property("color","white")
18-
}
19-
".navbar" style {
20-
display(DisplayStyle.Flex)
21-
property("background-color","#333")
22-
}
23-
".navbar a" style {
24-
property("color","white")
25-
padding(14.px, 20.px)
26-
textDecoration("none")
27-
textAlign("center")
28-
}
29-
".navbar a:hover" style {
30-
property("background-color","#ddd")
31-
property("color","black")
32-
}
33-
".row" style {
34-
display(DisplayStyle.Flex)
35-
flexWrap(FlexWrap.Wrap)
36-
}
37-
".side" style {
38-
property("flex","30%")
39-
property("background-color","#f1f1f1")
40-
padding(20.px)
41-
}
42-
".main" style {
43-
property("flex","70%")
44-
property("background-color","white")
45-
padding(20.px)
46-
}
47-
".fakeimg" style {
48-
property("background-color","#aaa")
49-
width(100.percent)
50-
padding(20.px)
51-
}
52-
".footer" style {
53-
padding(20.px)
54-
textAlign("center")
55-
property("background","#ddd")
3+
fun appStylesheet() = object : StyleSheet() {
4+
fun fontFace() {
5+
val newStyle = document.getElementsByTagName("style")[0] ?: document.createElement("style")
6+
7+
newStyle.append(
8+
document.createTextNode("""@font-face {
9+
font-family:myFirstFont;
10+
src:url(sansation_light.woff);
5611
}
57-
media("(max-width:700px)") {
58-
".row, .navbar" style {
59-
flexDirection(FlexDirection.Column)
12+
""")
13+
)
14+
15+
document.head?.appendChild(newStyle);
6016
}
17+
init {
18+
fontFace()
19+
"div" style {
20+
property("font-family","myFirstFont")
6121
}
6222
}}
6323

6424
Style(appStylesheet())
65-
// Note
66-
Div (attrs = {
67-
style {
68-
property("background","yellow")
69-
padding(5.px)
70-
}
71-
}){
72-
H4 (attrs = {
73-
style {
74-
textAlign("center")
75-
}
76-
}){
77-
Text("Resize the browser window to see the responsive effect.")
78-
79-
}
80-
81-
}
82-
// Header
83-
Div (attrs = {
84-
classes("header")
85-
}){
8625
H1 {
87-
Text("My Website")
88-
89-
}
90-
P {
91-
Text("With a ")
92-
B {
93-
Text("flexible")
94-
95-
}
96-
Text(" layout.")
97-
98-
}
99-
100-
}
101-
// Navigation Bar
102-
Div (attrs = {
103-
classes("navbar")
104-
}){
105-
A (href = "#"){
106-
Text("Link")
107-
108-
}
109-
A (href = "#"){
110-
Text("Link")
111-
112-
}
113-
A (href = "#"){
114-
Text("Link")
115-
116-
}
117-
A (href = "#"){
118-
Text("Link")
119-
120-
}
121-
122-
}
123-
// The flexible grid (content)
124-
Div (attrs = {
125-
classes("row")
126-
}){
127-
Div (attrs = {
128-
classes("side")
129-
}){
130-
H2 {
131-
Text("About Me")
132-
133-
}
134-
H5 {
135-
Text("Photo of me:")
136-
137-
}
138-
Div (attrs = {
139-
classes("fakeimg")
140-
style {
141-
height(200.px)
142-
}
143-
}){
144-
Text("Image")
145-
146-
}
147-
P {
148-
Text("Some text about me in culpa qui officia deserunt mollit anim..")
149-
150-
}
151-
H3 {
152-
Text("More Text")
153-
154-
}
155-
P {
156-
Text("Lorem ipsum dolor sit ame.")
157-
158-
}
159-
Div (attrs = {
160-
classes("fakeimg")
161-
style {
162-
height(60.px)
163-
}
164-
}){
165-
Text("Image")
166-
167-
}
168-
Br {}
169-
Div (attrs = {
170-
classes("fakeimg")
171-
style {
172-
height(60.px)
173-
}
174-
}){
175-
Text("Image")
176-
177-
}
178-
Br {}
179-
Div (attrs = {
180-
classes("fakeimg")
181-
style {
182-
height(60.px)
183-
}
184-
}){
185-
Text("Image")
186-
187-
}
188-
189-
}
190-
Div (attrs = {
191-
classes("main")
192-
}){
193-
H2 {
194-
Text("TITLE HEADING")
195-
196-
}
197-
H5 {
198-
Text("Title description, Dec 7, 2017")
199-
200-
}
201-
Div (attrs = {
202-
classes("fakeimg")
203-
style {
204-
height(200.px)
205-
}
206-
}){
207-
Text("Image")
208-
209-
}
210-
P {
211-
Text("Some text..")
212-
213-
}
214-
P {
215-
Text("Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.")
216-
217-
}
218-
Br {}
219-
H2 {
220-
Text("TITLE HEADING")
221-
222-
}
223-
H5 {
224-
Text("Title description, Sep 2, 2017")
225-
226-
}
227-
Div (attrs = {
228-
classes("fakeimg")
229-
style {
230-
height(200.px)
231-
}
232-
}){
233-
Text("Image")
234-
235-
}
236-
P {
237-
Text("Some text..")
238-
239-
}
240-
P {
241-
Text("Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.")
242-
243-
}
244-
245-
}
246-
247-
}
248-
// Footer
249-
Div (attrs = {
250-
classes("footer")
251-
}){
252-
H2 {
253-
Text("Footer")
26+
Text("The @font-face Rule")
25427

25528
}
29+
Div {
30+
Text("With CSS, websites can finally use fonts other than the pre selected \"web-safe\" fonts.")
25631

25732
}
25833
}

0 commit comments

Comments
 (0)