SlideShare una empresa de Scribd logo
1 de 19
Descargar para leer sin conexión
A DSL enabling programmatic
cascading style sheet generation
+
google.com/+GabrielCotelli
Project
Goals
● Improve CSS integration with existing Web Frameworks
● Write & refactor in Smalltalk, deploy to CSS
Highlights
● Source code is MIT licensed
● Documentation is CC BY-SA 4.0 licensed
● The project is managed in GitHub
● Supports Pharo 3 , 4 and 5
● Follows semantic versioning rules
Basic Example
div
{
margin: 2px;
background-color: aliceblue;
}
CascadingStyleSheetBuilder new
declareRuleSetFor: [:selector | selector div ]
with: [:style |
style
margin: 2 px;
backgroundColor: CssSVGColors aliceBlue];
build
CSS properties are defined in the API by the following rules:
● Properties without dashes are directly mapped: margin becomes a margin: message send.
● Properties with dashes are converted to Camel Case: margin-top becomes marginTop:
Simple Property Values
● Plain integers, floats or strings can be used as values.
● Several properties have keyword constants as values. This support is
provided by CssConstants and CssFontConstants:
CssConstants justify
● Other properties required measures as values. The library provides units
for length, time, angles and frequencies:
2 px. 5 em. 90 deg.
● Colors, are also supported. Well known ones can be accessed by
CssSVGColors. RGB and HSL colors are also supported including the alpha
channel specification:
CssSVGColors aliceBlue.
CssRGBColor red: 0 green: 128 blue: 0 alpha: 0.5.
Multi-valued properties
Some properties support a wide range of values. A prototypical example is the
margin property supporting 1, 2, 3 or 4 values. In this cases to provide more
than one value use an Array.
CascadingStyleSheetBuilder new
declareRuleSetFor: [:selector | selector div ]
with: [:style | style margin: { 2 px. 4 px } ];
build
div
{
margin: 2px 4px;
}
Complex Property Values
● Gradients and Box Shadows
div
{
background: linear-gradient(45deg, yellow, blue);
}
span
{
background: radial-gradient(yellow, green);
}
● Functional Notation: calc(), attr() and toggle() are also supported
CascadingStyleSheetBuilder new
declareRuleSetFor: [:selector | selector div ]
with: [:style | style background: (CssLinearGradient rotated: 45 deg fading: { CssSVGColors yellow. CssSVGColors blue }) ];
declareRuleSetFor: [:selector | selector span]
with: [:style | style background: (CssRadialGradient fading: { CssSVGColors yellow. CssSVGColors green }) ];
build
Selectors
Selectors represents a structure used to match elements in the document
tree. One of the most common selectors is the type one, matching a specific
element type in the DOM.
CascadingStyleSheetBuilder new
declareRuleSetFor: [:selector | selector orderedList ]
with: [:style | … ];
build
ol
{ … }
To get a list of the supported type selectors inspect:
CssSelector selectorsInProtocol: '*RenoirSt-HTML'
Combinators
Are used to combine other selectors.
Descendant selector div orderedList div ol
selector div * selector orderedList div * ol
Child selector div > selector orderedList div > ol
Adjacent Sibling selector div + selector orderedList div + ol
General Sibling selector div ~ selector orderedList div ~ ol
Class and Id Selectors
CascadingStyleSheetBuilder new
declareRuleSetFor: [:selector |
(selector div class: BootstrapCssStyles row) id: #account5 ]
with: [:style | … ];
build
div.row#account5
{
…
}
Attribute Selectors
Are useful to match an element using the related attributes information.
Presence selector havingAttribute: 'title' [title]
Exact value selector withAttribute: 'class' equalTo: 'example' [class="example"]
Value inclusion selector attribute: 'rel' includes: 'copyright' [rel~="copyright"]
selector firstValueOfAttribute: 'hreflang' beginsWith: 'en' [hreflang|="en"]
Substring matching selector attribute: 'type' beginsWith:image'
selector attribute: 'type' endsWith: '.html'
selector attribute: 'title' includesSubstring: 'hello'
[type^="image/"]
[type$=".html"]
[title*="hello"]
Pseudo-Class selectors
Allows selection based on information that lies outside the document tree.
CascadingStyleSheetBuilder new
declareRuleSetFor: [:selector | selector anchor visited active]
with: [:style | … ];
build
a:visited:active
{
…
}
Structural Pseudo-Classes
CascadingStyleSheetBuilder new
declareRuleSetFor: [:selector | selector childAt: 3 n + 1 ]
with: [:style | … ];
build
:nth-child(3n+1)
{
…
}
Additional Selectors
● Language Pseudo-Class :lang()
● Negation Pseudo-Class :not()
● Pseudo-Elements ::first-line ::first-letter ::before ::after
● Selector Groups:
CascadingStyleSheetBuilder new
declareRuleSetFor: [:selector | (selector div class: 'note') after ,
(selector paragraph class: 'note') before ]
with: [:style | … ];
build
div.note::after ,
p.note::before
{ … }
Important Rules
CascadingStyleSheetBuilder new
declareRuleSetFor: [:selector | selector paragraph ]
with: [:style |
style beImportantDuring: [:importantStyle | importantStyle textIndent: 1 em ].
style fontSize: 18 pt.
];
build
p
{
text-indent: 1em !important;
font-size: 18pt;
}
Media Queries
A @media rule specifies the target media types of a set of statements.
CascadingStyleSheetBuilder new
declare: [ :cssBuilder |
cssBuilder
declareRuleSetFor: [ :selector | selector id: #oop ]
with: [ :style | style color: CssSVGColors red ]
]
forMediaMatching: [ :queryBuilder | queryBuilder type: CssMediaQueryConstants print ];
build
Additional stuff
● Font Face Rules
● Vendor Specific Properties
● ZnUrl and WAUrl extensions
● Deployment and Development Groups
Seaside Extension Examples
CssDeclarationBlock can be passed as an argument when a JSObject is
required:
renderOn: aCanvas
…
aCanvas
highcharts legend
itemStyle: (CssDeclarationBlock new fontSize: 11 px; yourself).
…
Seaside Extension Examples
CssDeclarationBlock can be used to inline css using “style” attributes:
renderCompanyNameIn: color on: aCanvas
…
aCanvas div
style: (
CssDeclarationBlock new
backgroundColor: color;
yourself)
…
That’s all folks!
Any question?
Source Code and Issues:
github.com/gcotelli/RenoirSt
Docs:
- Online tutorial in GitHub
- Pharo for Enterprise Book
Q&A:
RenoirSt Community

Más contenido relacionado

La actualidad más candente

CSS for basic learner
CSS for basic learnerCSS for basic learner
CSS for basic learnerYoeung Vibol
 
20131108 cs query by howard
20131108 cs query by howard20131108 cs query by howard
20131108 cs query by howardLearningTech
 
Cordova training : Day 4 - Advanced Javascript
Cordova training : Day 4 - Advanced JavascriptCordova training : Day 4 - Advanced Javascript
Cordova training : Day 4 - Advanced JavascriptBinu Paul
 

La actualidad más candente (6)

Css
CssCss
Css
 
CSS for basic learner
CSS for basic learnerCSS for basic learner
CSS for basic learner
 
Cascading Style Sheet
Cascading Style SheetCascading Style Sheet
Cascading Style Sheet
 
20131108 cs query by howard
20131108 cs query by howard20131108 cs query by howard
20131108 cs query by howard
 
jQuery Beginner
jQuery BeginnerjQuery Beginner
jQuery Beginner
 
Cordova training : Day 4 - Advanced Javascript
Cordova training : Day 4 - Advanced JavascriptCordova training : Day 4 - Advanced Javascript
Cordova training : Day 4 - Advanced Javascript
 

Destacado

Ahmed Shaheen Ibrahim
Ahmed Shaheen IbrahimAhmed Shaheen Ibrahim
Ahmed Shaheen IbrahimAhmed Shaheen
 
с днем рождения прокопьевск!
с днем рождения прокопьевск!с днем рождения прокопьевск!
с днем рождения прокопьевск!ds80
 
Poftabuna.ro se lanseaza
Poftabuna.ro se lanseazaPoftabuna.ro se lanseaza
Poftabuna.ro se lanseazasorovidin
 
Level 5 Leadership in Health and Social Care
Level 5 Leadership in Health and Social CareLevel 5 Leadership in Health and Social Care
Level 5 Leadership in Health and Social CareThe Pathway Group
 
Power%20point%202010 jpn
Power%20point%202010 jpnPower%20point%202010 jpn
Power%20point%202010 jpndiegobicep
 
Level 5 Leadership for Health Social Care
Level 5  Leadership for Health Social Care Level 5  Leadership for Health Social Care
Level 5 Leadership for Health Social Care The Pathway Group
 
Syed Ghouse Resume 1
Syed Ghouse Resume 1Syed Ghouse Resume 1
Syed Ghouse Resume 1Gouse Sayed
 
Century College Magazine (1)
Century College Magazine (1)Century College Magazine (1)
Century College Magazine (1)Tenzin Gakyi
 
IT Architectures for Handling Big Data in Official Statistics: the Case of Sc...
IT Architectures for Handling Big Data in Official Statistics: the Case of Sc...IT Architectures for Handling Big Data in Official Statistics: the Case of Sc...
IT Architectures for Handling Big Data in Official Statistics: the Case of Sc...Istituto nazionale di statistica
 
Gestion cultural 2.0 introducción
Gestion cultural 2.0 introducciónGestion cultural 2.0 introducción
Gestion cultural 2.0 introducciónJavier Calv
 

Destacado (13)

Ahmed Shaheen Ibrahim
Ahmed Shaheen IbrahimAhmed Shaheen Ibrahim
Ahmed Shaheen Ibrahim
 
App from Fluor and Shell project
App from Fluor  and Shell project App from Fluor  and Shell project
App from Fluor and Shell project
 
с днем рождения прокопьевск!
с днем рождения прокопьевск!с днем рождения прокопьевск!
с днем рождения прокопьевск!
 
Poftabuna.ro se lanseaza
Poftabuna.ro se lanseazaPoftabuna.ro se lanseaza
Poftabuna.ro se lanseaza
 
Level 5 Leadership in Health and Social Care
Level 5 Leadership in Health and Social CareLevel 5 Leadership in Health and Social Care
Level 5 Leadership in Health and Social Care
 
2016FallGrapevineFINAL.compressed
2016FallGrapevineFINAL.compressed2016FallGrapevineFINAL.compressed
2016FallGrapevineFINAL.compressed
 
Oppcnlgfhndgfhdgf
OppcnlgfhndgfhdgfOppcnlgfhndgfhdgf
Oppcnlgfhndgfhdgf
 
Power%20point%202010 jpn
Power%20point%202010 jpnPower%20point%202010 jpn
Power%20point%202010 jpn
 
Level 5 Leadership for Health Social Care
Level 5  Leadership for Health Social Care Level 5  Leadership for Health Social Care
Level 5 Leadership for Health Social Care
 
Syed Ghouse Resume 1
Syed Ghouse Resume 1Syed Ghouse Resume 1
Syed Ghouse Resume 1
 
Century College Magazine (1)
Century College Magazine (1)Century College Magazine (1)
Century College Magazine (1)
 
IT Architectures for Handling Big Data in Official Statistics: the Case of Sc...
IT Architectures for Handling Big Data in Official Statistics: the Case of Sc...IT Architectures for Handling Big Data in Official Statistics: the Case of Sc...
IT Architectures for Handling Big Data in Official Statistics: the Case of Sc...
 
Gestion cultural 2.0 introducción
Gestion cultural 2.0 introducciónGestion cultural 2.0 introducción
Gestion cultural 2.0 introducción
 

Similar a Programmatic CSS generation with Smalltalk DSL

Similar a Programmatic CSS generation with Smalltalk DSL (20)

TIBCO General Interface - CSS Guide
TIBCO General Interface - CSS GuideTIBCO General Interface - CSS Guide
TIBCO General Interface - CSS Guide
 
Chapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssChapter 4a cascade style sheet css
Chapter 4a cascade style sheet css
 
Html advance
Html advanceHtml advance
Html advance
 
HTML-Advance.pptx
HTML-Advance.pptxHTML-Advance.pptx
HTML-Advance.pptx
 
Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
 
Introduction to css by programmerblog.net
Introduction to css by programmerblog.netIntroduction to css by programmerblog.net
Introduction to css by programmerblog.net
 
Fewd week2 slides
Fewd week2 slidesFewd week2 slides
Fewd week2 slides
 
Css.html
Css.htmlCss.html
Css.html
 
Web 102 INtro to CSS
Web 102  INtro to CSSWeb 102  INtro to CSS
Web 102 INtro to CSS
 
css v1 guru
css v1 gurucss v1 guru
css v1 guru
 
An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)
 
Css3
Css3Css3
Css3
 
Css
CssCss
Css
 
D3 data visualization
D3 data visualizationD3 data visualization
D3 data visualization
 
CSS Overview
CSS OverviewCSS Overview
CSS Overview
 
Css for Development
Css for DevelopmentCss for Development
Css for Development
 
CSS.pdf
CSS.pdfCSS.pdf
CSS.pdf
 
CSS
CSS CSS
CSS
 
CSS- Smacss Design Rule
CSS- Smacss Design RuleCSS- Smacss Design Rule
CSS- Smacss Design Rule
 

Último

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 

Último (20)

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 

Programmatic CSS generation with Smalltalk DSL

  • 1. A DSL enabling programmatic cascading style sheet generation + google.com/+GabrielCotelli
  • 2. Project Goals ● Improve CSS integration with existing Web Frameworks ● Write & refactor in Smalltalk, deploy to CSS Highlights ● Source code is MIT licensed ● Documentation is CC BY-SA 4.0 licensed ● The project is managed in GitHub ● Supports Pharo 3 , 4 and 5 ● Follows semantic versioning rules
  • 3. Basic Example div { margin: 2px; background-color: aliceblue; } CascadingStyleSheetBuilder new declareRuleSetFor: [:selector | selector div ] with: [:style | style margin: 2 px; backgroundColor: CssSVGColors aliceBlue]; build CSS properties are defined in the API by the following rules: ● Properties without dashes are directly mapped: margin becomes a margin: message send. ● Properties with dashes are converted to Camel Case: margin-top becomes marginTop:
  • 4. Simple Property Values ● Plain integers, floats or strings can be used as values. ● Several properties have keyword constants as values. This support is provided by CssConstants and CssFontConstants: CssConstants justify ● Other properties required measures as values. The library provides units for length, time, angles and frequencies: 2 px. 5 em. 90 deg. ● Colors, are also supported. Well known ones can be accessed by CssSVGColors. RGB and HSL colors are also supported including the alpha channel specification: CssSVGColors aliceBlue. CssRGBColor red: 0 green: 128 blue: 0 alpha: 0.5.
  • 5. Multi-valued properties Some properties support a wide range of values. A prototypical example is the margin property supporting 1, 2, 3 or 4 values. In this cases to provide more than one value use an Array. CascadingStyleSheetBuilder new declareRuleSetFor: [:selector | selector div ] with: [:style | style margin: { 2 px. 4 px } ]; build div { margin: 2px 4px; }
  • 6. Complex Property Values ● Gradients and Box Shadows div { background: linear-gradient(45deg, yellow, blue); } span { background: radial-gradient(yellow, green); } ● Functional Notation: calc(), attr() and toggle() are also supported CascadingStyleSheetBuilder new declareRuleSetFor: [:selector | selector div ] with: [:style | style background: (CssLinearGradient rotated: 45 deg fading: { CssSVGColors yellow. CssSVGColors blue }) ]; declareRuleSetFor: [:selector | selector span] with: [:style | style background: (CssRadialGradient fading: { CssSVGColors yellow. CssSVGColors green }) ]; build
  • 7. Selectors Selectors represents a structure used to match elements in the document tree. One of the most common selectors is the type one, matching a specific element type in the DOM. CascadingStyleSheetBuilder new declareRuleSetFor: [:selector | selector orderedList ] with: [:style | … ]; build ol { … } To get a list of the supported type selectors inspect: CssSelector selectorsInProtocol: '*RenoirSt-HTML'
  • 8. Combinators Are used to combine other selectors. Descendant selector div orderedList div ol selector div * selector orderedList div * ol Child selector div > selector orderedList div > ol Adjacent Sibling selector div + selector orderedList div + ol General Sibling selector div ~ selector orderedList div ~ ol
  • 9. Class and Id Selectors CascadingStyleSheetBuilder new declareRuleSetFor: [:selector | (selector div class: BootstrapCssStyles row) id: #account5 ] with: [:style | … ]; build div.row#account5 { … }
  • 10. Attribute Selectors Are useful to match an element using the related attributes information. Presence selector havingAttribute: 'title' [title] Exact value selector withAttribute: 'class' equalTo: 'example' [class="example"] Value inclusion selector attribute: 'rel' includes: 'copyright' [rel~="copyright"] selector firstValueOfAttribute: 'hreflang' beginsWith: 'en' [hreflang|="en"] Substring matching selector attribute: 'type' beginsWith:image' selector attribute: 'type' endsWith: '.html' selector attribute: 'title' includesSubstring: 'hello' [type^="image/"] [type$=".html"] [title*="hello"]
  • 11. Pseudo-Class selectors Allows selection based on information that lies outside the document tree. CascadingStyleSheetBuilder new declareRuleSetFor: [:selector | selector anchor visited active] with: [:style | … ]; build a:visited:active { … }
  • 12. Structural Pseudo-Classes CascadingStyleSheetBuilder new declareRuleSetFor: [:selector | selector childAt: 3 n + 1 ] with: [:style | … ]; build :nth-child(3n+1) { … }
  • 13. Additional Selectors ● Language Pseudo-Class :lang() ● Negation Pseudo-Class :not() ● Pseudo-Elements ::first-line ::first-letter ::before ::after ● Selector Groups: CascadingStyleSheetBuilder new declareRuleSetFor: [:selector | (selector div class: 'note') after , (selector paragraph class: 'note') before ] with: [:style | … ]; build div.note::after , p.note::before { … }
  • 14. Important Rules CascadingStyleSheetBuilder new declareRuleSetFor: [:selector | selector paragraph ] with: [:style | style beImportantDuring: [:importantStyle | importantStyle textIndent: 1 em ]. style fontSize: 18 pt. ]; build p { text-indent: 1em !important; font-size: 18pt; }
  • 15. Media Queries A @media rule specifies the target media types of a set of statements. CascadingStyleSheetBuilder new declare: [ :cssBuilder | cssBuilder declareRuleSetFor: [ :selector | selector id: #oop ] with: [ :style | style color: CssSVGColors red ] ] forMediaMatching: [ :queryBuilder | queryBuilder type: CssMediaQueryConstants print ]; build
  • 16. Additional stuff ● Font Face Rules ● Vendor Specific Properties ● ZnUrl and WAUrl extensions ● Deployment and Development Groups
  • 17. Seaside Extension Examples CssDeclarationBlock can be passed as an argument when a JSObject is required: renderOn: aCanvas … aCanvas highcharts legend itemStyle: (CssDeclarationBlock new fontSize: 11 px; yourself). …
  • 18. Seaside Extension Examples CssDeclarationBlock can be used to inline css using “style” attributes: renderCompanyNameIn: color on: aCanvas … aCanvas div style: ( CssDeclarationBlock new backgroundColor: color; yourself) …
  • 19. That’s all folks! Any question? Source Code and Issues: github.com/gcotelli/RenoirSt Docs: - Online tutorial in GitHub - Pharo for Enterprise Book Q&A: RenoirSt Community