Migrating CSS to Preprocessors by Introducing Mixins

Slides:



Advertisements
Similar presentations
HTML and CSS. HTML Hyper Text Markup Language Tells browser how to display text and images.
Advertisements

Web Pages Week 10 This week: CSS Next week: CSS – Part 2.
Cascading Style Sheets
UNDERSTANDING CSS: THINKING INSIDE THE BOX The Cottage Garden The cottage garden is a distinct style of garden that uses an informal design, dense planting.
Layout using CSS. Using multiple classes In the head:.important{font-style:italic;}.title{color:red;} In the body: Here's a type of paragraph that is.
Discovering Refactoring Opportunities in Cascading Style Sheets Davood Mazinanian Nikolaos Tsantalis Ali Mesbah Concordia University, Montréal, Canada.
Cascading Style Sheets (CSS): Pixel-Level Control with HTML Ease
Cascading Style Sheets. CSS stands for Cascading Style Sheets and is a simple styling language which allows attaching style to HTML elements. CSS is a.
Advance CSS (Menu and Layout) Miftahul Huda. CSS Navigation MENU It's truly remarkable what can be achieved through CSS, especially with navigation menus.
CSS BASICS. CSS Rules Components of a CSS Rule  Selector: Part of the rule that targets an element to be styled  Declaration: Two or more parts: a.
1 Pengantar Teknologi Internet W03: CSS Cascading Style Sheets.
Recognizing the Benefits of Using CSS 1. The Evolution of CSS CSS was developed to standardize display information CSS was slow to be supported by browsers.
1 Dreamweaver CS5 intermediate class by Cookie Setton Build a CSS website WITHOUT TABLES Just when you thought you were starting to understand HTML coding,
Web Pages and Style Sheets Bert Wachsmuth. HTML versus XHTML XHTML is a stricter version of HTML: HTML + stricter rules = XHTML. XHTML Rule violations:
กระบวนวิชา CSS. What is CSS? CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles were added to HTML 4.0 to.
Unit 20 - Client Side Customisation of Web Pages
An empirical study on the use of CSS Preprocessors Davood Mazinanian - Nikolaos Tsantalis Department of Computer Science and Software Engineering Concordia.
CSS normally control the html elements. Three Ways to Insert CSS There are three ways of inserting a style sheet: External style sheet Internal style.
Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design.
Web Workshop: CSS Objectives: - “What is CSS?” - Structure of CSS - How to use CSS in your webpage.
4.01 Cascading Style Sheets
CM143 Week 4 Introducing CSS. Cascading Style Sheets A definition for the style in which an element of the webpage will be displayed Border width, colour,
Working with Cascading Style Sheets. 2 Objectives Introducing Cascading Style Sheets Using Inline Styles Using Embedded Styles Using an External Style.
Working with Cascading Style Sheets. Introducing Cascading Style Sheets Style sheets are files or forms that describe the layout and appearance of a document.
Chapter 11 Cascading Style Sheets: Part I The Web Warrior Guide to Web Design Technologies.
XP Tutorial 7New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks.
Dreamweaver -- CSS. Dreamweaver -- MX New icons are added in MX Most of the features commonly used in web design, and are same as FrontPage. New feature.
Chapter 12 Cascading Style Sheets: Part II The Web Warrior Guide to Web Design Technologies.
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
CS134 Web Design & Development Cascading Style Sheets (CSS) Mehmud Abliz.
Davood Mazinanian, Nikolaos Tsantalis Concordia University, Montreal CSER FALL 2013 MEETING 1 An Empirical Study of Duplication in Cascading Style Sheets.
Chapter 6 Introducing Cascading Style Sheets Principles of Web Design, 4 th Edition.
Advanced Web Development Instructor: Thomas Bombach.
HTML with Style!. What is a Style Sheet? CSS? Style Sheet CSSCascading Style Sheets A “language” for defining style rules. Rules that tell the browser.
CNIT 132 – Week 4 Cascading Style Sheets. Introducing Cascading Style Sheets Style sheets are files or forms that describe the layout and appearance of.
Web Design (12) CSS Introduction. Cascading Style Sheets - Defined CSS is the W3C standard for defining the presentation of documents written in HTML.
Lecture 2: Cascading Style Sheets (CSS) Instructor: Dr. M. Anwar Hossain.
ACM 262 INTRODUCTION TO WEB DESIGN Week-7 ACM 262 Course Notes.
5 th ed: Chapter 4 4 th ed: Chapter 5 SY306 Web and Databases for Cyber Operations SlideSet #5: Advanced CSS.
XP Tutorial 7New Perspectives on HTML and XHTML, Comprehensive 1 Working with Cascading Style Sheets Creating a Style for Online Scrapbooks Tutorial 7.
CSS Cascading Style Sheets Prepared By
An empirical study on the use of CSS Preprocessors Davood Mazinanian Nikolaos Tsantalis Department of Computer Science and Software Engineering Concordia.
WEB FOUNDATIONS CSS Overview. Outline  What is CSS  What does it do  Where are styles stored  Why use them  What is the cascade effect  CSS Syntax.
WebD Introduction to CSS By Manik Rastogi.
CSS.
Laying out Elements with CSS
Working with Cascading Style Sheets
Simple theme creation using Sass
CS3220 Web and Internet Programming CSS Basics
Creating Your Own Webpage
>> Introduction to CSS
Cascading Style Sheets (Layout)
>> CSS Layouts.
IS333: MULTI-TIER APPLICATION DEVELOPMENT
Website Design 3
CSS Borders and Margins.
Software Engineering for Internet Applications
: Clone Refactoring Davood Mazinanian Nikolaos Tsantalis Raphael Stein
Software Refactoring Group
CS134 Web Design & Development
How to use the CSS box model for spacing, borders, and backgrounds
Training & Development
CS3220 Web and Internet Programming CSS Basics
CS3220 Web and Internet Programming CSS Basics
Cascading Style sheet. What is CSS?  CSS stands for Cascading Style Sheets  Cascading: refers to the procedure that determines which style will apply.
Web Design & Development
Cascading Style Sheets III B. Com (Paper - VI) & III B
Web Programming and Design
Introduction to Cascading Style Sheets (CSS)
Presentation transcript:

Migrating CSS to Preprocessors by Introducing Mixins Davood Mazinanian Nikolaos Tsantalis ASE’16

What is CSS?

CSS is a Style Sheet language Defines how documents are presented

Simple syntax… Target document (e.g., HTML) CSS <html> … <p>My cool paragraph</p> </html> CSS

Missing traditional code reuse constructs … yet inadequate! Missing traditional code reuse constructs e.g., functions and {variables}

Duplication is pervasive! [Mazinanian et al. 2014]

Add the missing features to CSS! CSS preprocessors Add the missing features to CSS! DRY: using Extend or Mixin constructs Developers prefer Mixins! [SANER’16]

Mixins = functions! Preprocessor code CSS code Transpile .s1 { text-align: center; .mixin1(8pt; Tahoma; 100px); } .s2 { float: left; .mixin1(10pt; Arial; 70px); .s3 { float: right; font: 9pt Tahoma .mixin1(@fontS; @fontN; @colW) { font: @fontS @fontN; -moz-columns: @colW 3; columns: @colW 3; .s1 { text-align: center; font: 8pt Tahoma; -moz-columns: 100px 3; columns: 100px 3 } .s2 { float: left; font: 10pt Arial; -moz-columns: 70px 3; columns: 70px 3; .s3 { float: right; font: 9pt Tahoma Transpile

Can we do the reverse?!

Extracting Mixins CSS code Preprocessor code Extract Mixin .s1 { text-align: center; font: 8pt Tahoma; -moz-columns: 100px 3; columns: 100px 3 } .s2 { float: left; font: 10pt Arial; -moz-columns: 70px 3; columns: 70px 3; .s3 { float: right; font: 9pt Tahoma .s1 { text-align: center; .m1(8pt; Tahoma; 100px); } .s2 { float: left; .m1(10pt; Arial; 70px); .s3 { float: right; font: 9pt Tahoma .m1(@fontS; @fontN; @colW) { font: @fontS @fontN; -moz-columns: @colW 3; columns: @colW 3; Extract Mixin

Why should we do the reverse?!

Why? A core for Migration Preprocessors are under-utilized For the people who still like ‘Vanila’ Preprocessors are under-utilized More opportunities than what is actually used

How? 1) Group duplicated declarations 2) Detect differences 3) Extract the mixin Make mixin calls!

1) Grouping declarations text-align: center; font: 8pt Tahoma; -moz-columns: 100px 3; columns: 100px 3 } .s2 { float: left; font: 10pt Arial; -moz-columns: 70px 3; columns: 70px 3; .s3 { float: right; font: 9pt Tahoma Brute force ⟹ combinatorial explosion

1) Grouping declarations text-align: center; font: 8pt Tahoma; -moz-columns: 100px 3; columns: 100px 3 } .s2 { float: left; font: 10pt Arial; -moz-columns: 70px 3; columns: 70px 3; .s3 { float: right; font: 9pt Tahoma Using frequent itemset mining!

1) Grouping declarations Frequent Itemsets: Set of items bought together (in a store) in at least s transactions (|s| ⩾ 2)

1) Grouping declarations Frequent Declarations: Set of declarations appearing together In more than s selectors (|s| ⩾ 2)

1) Grouping declarations text-align: center; font: 8pt Tahoma; -moz-columns: 100px 3; columns: 100px 3 } .s2 { float: left; font: 10pt Arial; -moz-columns: 70px 3; columns: 70px 3; .s3 { float: right; font: 9pt Tahoma Application of the FP-Growth algorithm

2) Detecting differences in values .mixin(@v1; @v2; @v3) { border: @v1 @v2 @v3; } .s1 { float: left; will-change: transform; .mixin(#f00; 1px; solid); .s2 { color: red; .mixin(dotted; red; thin); .s1 { float: left; will-change: transform; border: #f00 1px solid; } .s2 { color: red; border: dotted red thin; 3 differences = 3 parameters

2) Detecting differences in values .mixin(@style) { border: #f00 1px @style; } .s1 { float: left; will-change: transform; .mixin(solid); .s2 { color: red; .mixin(dotted); .s1 { float: left; will-change: transform; border: #f00 1px solid; } .s2 { color: red; border: dotted red thin; 1 difference = 1 parameter

2) Detecting differences in values float: left; will-change: transform; border: #f00 1px solid; } .s2 { color: red; border: dotted red thin; ISP: border-style Detecting Individual Style Properties ISP: border-style

Extract mixin! Add the grouped declarations to the mixin Parameterize declarations Each difference = 1 parameter Make mixin calls and put them in selectors… where?!

Are these transformations safe?

What can go wrong? Expected output Extract Mixin Resulting Transpile

Preserving Presentation Precondition: Preserve all order dependencies [Mazinanian et al. 2014] .a { ... border: solid 3px red; border-bottom: none; padding: 1px; } Mixin call position: A CSP! pos(.mixin()) < pos(border-bottom) Variables: .mixin(), border-bottom Values’ domain: 1, 2

Evaluation Dataset: 21 Websites from [SANER’16] dataset 8 CSS Libraries For every pair of matching style rules (S, S’) defined in C and C’, respectively, style-map(S) == style-map(S’). style-map(S) : what styles are assigned to an individual style property

Evaluation RQ1: Is the presentation preserved? CSS Before (C) Preprocessor Code CSS After (C’) Extract Mixin Transpile For every pair of matching style rules (S, S’) defined in C and C’, respectively, style-map(S) == style-map(S’). style-map(S) : what styles are assigned to an individual style property Test the presentation preservation conditions

RQ1: Preserving Presentation The main condition: Select the same elements, Same ISPs should get equivalent styles <html> … <></> </html> Before <html> … <></> </html> ISP1: border-left-color Value: green ISP1: border-left-color Value: #0f0 After

RQ1 Results RQ1: All tests were eventually passed! 9555 opportunities were tested Bugs related to implementation Bugs related to assigning correct ISPs

Evaluation RQ2: Can we detect all manually-developed mixins? Preprocessor (Manually developed) Preprocessor (Automatically Generated) CSS Transpile Extract Mixin Compare mixins

RQ2 Results Almost 98% recall 189 / 193 manually developed mixins 2 advanced features (in 4 mixins) that we do not support

Libraries are better coded!

Limitations High number of opportunities Filter out based on box plot outliers

Conclusions and Future Work An approach for extracting mixins Safe to apply High recall Filters can reduce the number of opportunities, while keeping recall high Yet we need a ranking mechanism Conducting a user study is crucial

Let’s collaborate! Check my tool out! /dmazinanian dmazinanian.me

What we don’t support String interpolation

Preserving Presentation Precondition II: The ordering of the style declarations inside a mixin should preserve their original order dependencies in the style rules from which they are extracted The “template” ensures that The only possibility: conflicting dependencies

2) Detecting differences in values .mixin(@mtop; @mbottom) { margin: @mtop 5px @mbottom 5px; } .s1 { ... .mixin(3px; 3px); .s2 { .mixin(2px; 1px); .s1 { ... margin-left: 5px; margin-right: 5px; margin-top: 3px; margin-bottom: 3px; } .s2 { margin: 2px 5px 1px; Shorthand Declaration

References [FSE’14] Davood Mazinanian, Nikolaos Tsantalis, and Ali Mesbah, "Discovering Refactoring Opportunities in Cascading Style Sheets," 22nd ACM SIGSOFT International Symposium on the Foundations of Software Engineering (FSE'2014), pp. 496-506, 2014 [SANER’16] Davood Mazinanian, and Nikolaos Tsantalis, "An Empirical Study on the Use of CSS Preprocessors," 23rd IEEE International Conference on Software Analysis, Evolution, and Reengineering (SANER'2016), pp. 168-178, 2016.