SlideShare uma empresa Scribd logo
1 de 19
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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
 

Destaque (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
 

Semelhante a Programmatic CSS generation with Smalltalk DSL

Semelhante 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

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
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
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
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
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
 
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
 
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
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
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
 
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
 
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.
 
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.
 
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
 

Último (20)

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
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
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
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
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
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
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
 
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 ...
 
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...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
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
 
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
 
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 ...
 
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...
 
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
 

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