SlideShare a Scribd company logo
Haml, Sass, Compass

         Bácsi László
     bacsi.laszlo@virgo.hu
Haml

•   Sablonozó motor
•   HTML-nél egyszerűbb és átláthatóbb
•   Nincs redundancia (DRY)
•   Szemantikus kód, szép kimenet
Sass

•   Haml szerű szintaxis StyleSheet-ekhez
•   Egymásba ágyazott kiválasztók
•   Nincs redundancia (DRY)
•   Konstansok és egyszerű műveletek
•   Újrahasználató CSS mixinek
•   A leíró kód szép kellene legyen

•   A leíró kód nem kellene ismételje
    magát

•   A leíró kód jól indentált kellene
    legyen

•   A struktúra tisztán látható kellene
    legyen
Haml
Alapok
Haml                                            HTML
#content                                        <div id='content'>
  .left.column                                    <div class='left column'>
    %h2 Welcome to our site!                        <h2>Welcome to our site!</h2>
    %p= print_information                           <p>
  .right.column= render :partial => quot;sidebarquot;          <%= print_information %>
                                                    </p>
                                                  </div>
                                                  <div class=quot;right columnquot;>
                                                    <%= render :partial => quot;sidebarquot; %>
                                                  </div>
                                                </div>
Alapok
Haml                                 HTML
%tagname{:attr => 'value'} content   <tagname attr=quot;valuequot;>content</tagname>
%tagname#id.class content            <tagname id=quot;idquot; class=quot;classquot;>content</
                                     tagname>

%tagname                             <tagname>
  %innerTag                            <innerTag/>
  and some content                     and some content
                                     </tagname>

#company Virgo                       <div id=quot;companyquot;>Virgo</div>

.employee Bácsi László               <div class=quot;employeequot;>Bácsi László</div>
-, = – Ruby kód beágyazás
Rubys Haml kód                                Generált HTML
%dl                                           <dl>
  - now = DateTime.now                          <dt>Dátum és idő:</dt>
  %dt Dátum és idő:                             <dd>
  %dd                                              Boldog új évet!
    - if now > DateTime.parse('2008-12-31')     </dd>
      Boldog új évet!                         </dl>
    - else
      = now.to_s                              <dl>
                                                <dt>Dátum és idő:</dt>
                                                <dd>
                                                   2008-12-30T12:31:45+01:00
                                                </dd>
                                              </dl>

- @gems = %w{rails haml compass}              <ul id='gems'>
%ul#gems                                        <li class='gem'>rails</li>
  - @gems.each do |gem|                         <li class='gem'>haml</li>
    %li.gem= gem                                <li class='gem'>compass</li>
                                              </ul>
{} – Attribútumok
Haml                                            HTML
%bar/                                           <bar/>

%script{:type => 'text/' + 'javascript', |      <script src='/js/locale.hu.js' type='text/
        :src => quot;/js/locale.#{@lang}.jsquot;} |     javascript'></script>

# ruby helperek
def defaults
  {:type => 'checkbox', :value => '1'}
end

def override
  {:type => 'radio'}
end

                                                <input type=quot;radioquot; value=quot;1quot;
%input{defaults, override, :selected => true}
                                                selected=quot;selectedquot;/>
[] – id és class generálás
Haml                      HTML
- @user = User.find(42)   <div id=quot;current_user_42quot;
%div[@user, :current]     class=quot;current_userquot;>
  %span[7] 7.               <span id=quot;fixnum_7quot; class=quot;fixnumquot;>7.</span>
  Kúl, mi?                  Kúl, mi?
                          </div>
==, &=, !=, -# – Ruby inputok
Haml                                      HTML
- name = quot;<b>Haml</b>quot;

= quot;Hello, #{name}!quot;                       Hello,   <b>Haml</b>!
== Hello, #{name}!                        Hello,   <b>Haml</b>!
&= quot;Hello, #{name}!quot;                      Hello,   &lt;b&gt;Haml&lt;/b&gt;!
!= quot;Hello, #{name}!quot;                      Hello,   <b>Haml</b>!
-# Ez itt egy komment, ami nem kerül ki
!!! – xml és doctype
Haml                 HTML
!!! XML              <?xml version='1.0' encoding='utf-8' ?>
!!! XML iso-8859-2   <?xml version='1.0' encoding='iso-8859-2' ?>
!!! Strict           <!DOCTYPE html PUBLIC quot;-//W3C//DTD XHTML 1.0
                     Strict//ENquot; quot;http://www.w3.org/TR/xhtml1/DTD/
                     xhtml1-strict.dtdquot;>
/ – Kommentek
Haml                                           HTML
- name = quot;Calvinquot;                              <div class='user'>
.user                                            <!-- Ez itt a neve -->
  / Ez itt a neve                                Calvin
  = name                                       </div>

/                                              <!--
    Ezt a kódot most egyelőre nem rakjuk ki,     Ezt a kódot most egyelőre nem rakjuk ki,
    mert problémák lehetnek belőle.              mert problémák lehetnek belőle.
    %script                                      <script>
      evil();                                       evil();
                                                 </script>
                                               -->

                                               <!--[if IE]>
/[if IE]
                                                 <link href='/css/ie.css' rel='stylesheet'
  %link{:href => quot;/css/ie.cssquot;, |
                                               type='text/css' />
         :rel => quot;stylesheetquot;, |
                                               <![endif]-->
         :type => quot;text/cssquot;}   |
:markdown – Filterek
Haml                            HTML
%div                            <div>
  :markdown                       <h1>Hello <em>World</em>!</h1>
     # Hello *World*!           </div>

%Content{:type => 'html'}       <Content type='html'>
  :cdata                          <![CDATA[
    <p>iWiW gadzsett</p>              <p>iWiW gadzsett</p>
                                  ]]>
                                </Content>

# saját filter
module Haml::Filters::Upcaser
  include Haml::Filters::Base

  def render(text)
    text.upcase
  end
end

%h1                             <h1>
  :upcaser                        FIGYELEM, FIGYELEM!
    figyelem, figyelem!         </h1>
Sass
Alapok
Sass                           CSS
#box                           #box {
  margin: 10px                   margin: 10px;
  color: #ff0                    color: #ff0; }

#box                           #box {
  :margin 10px                   margin: 10px;
  :color #ff0                    color: #ff0; }

#box                           #box {
  :margin 10px                   margin: 10px;
  :color #ff0                    color: #ff0; }
  h1                             #box h1 {
     :font-size 0.8em              font-size: 0.8em; }
     a                             #box h1 a {
       :text-decoration none          text-decoration: none; }
Konstansok
Sass                                      CSS
!highlight = #ccb
!normal_text = 12px

body                                      body {
  :font-size = !normal_text                 font-size: 12px; }

em                                        em {
  :background-color = !highlight            background-color: #ccccbb; }

em.important                              em.important {
  :background-color = !highlight + #333     background-color: #ffffee;
  :font-size = 1.5 * !normal_text           font-size: 18px; }
Kommentek
Sass                                            CSS
/* Fejléc                                       /* Fejléc */
#header                                         #header {
  :font-size 1em                                  font-size: 1em; }

// Ez itt meg bele se kerül a generált css-be
                                                /*
/*                                               * Ez egy többsoros
  Ez egy többsoros                               * quot;hangosquot; komment */
  quot;hangosquot; komment                              #footer {
#footer                                            font-size: 0.8em; }
  :font-size 0.8em

//
  Ez pedig szintén több soros,
  de nem kerül be a css kódba
Bonyolultabb kombinációk
Sass                      CSS
#main                     #main {
  :width 600px              width: 600px; }
  p, div                    #main p, #main div {
    :font-size 1.5em          font-size: 1.5em; }
    a                         #main p a, #main div a {
      :font-weight bold         font-weight: bold; }
      img                       #main p a img, #main div a img {
         :border 0                border: 0; }
Szülő választó
Sass                              CSS
a                                 a{
    :color #00f                    color: #00f; }
    img                            a img {
      :border 0                      border: 0; }
    &.disabled                     a.disabled {
      :color #444                    color: #444; }
    &:link, &:active, &:visited    a:link, a:active, a:visited {
      :text-decoration none          text-decoration: none; }
    &:hover                        a:hover {
      :color #0ff                    color: #0ff; }
      img                            a:hover img {
        :border 2px solid #0ff         border: 2px solid #0ff; }
        body.admin &                   body.admin a:hover img {
          :border-color #f00             border-color: #f00; }
Attribútum namespace
Sass                              CSS
em                                em {
  :font                             font-size: 14px;
    :size 14px                      font-style: italic;
    :style italic                   font-family: Verdana, sans-serif; }
    :family Verdana, sans-serif
Újrafelhasználható kódok
Sass                      CSS
=clearfix                 ul.images {
  display: inline-block     display: inline-block; }
  &:after                   ul.images:after {
    content: quot;.quot;              content: quot;.quot;;
    display: block            display: block;
    height: 0                 height: 0;
    clear: both               clear: both;
    visibility: hidden        visibility: hidden; }
  * html &                  * html ul.images {
    height: 1px               height: 1px; }

ul.images
  +clearfix

                          p strong {
=larger-text                font-size: 1.2em; }
  :font-size 1.2em          p strong em {
p strong                      font-size: 1.2em; }
  +larger-text                p strong em .important {
  em                            font-size: 1.2em; }
     +larger-text
     .important
       +larger-text
Paraméterek és kombinálás
Sass                            CSS
=hanging-indent(!indentation)   p{
  text-indent = -!indentation    text-indent: -12px;
  padding-left = !indentation    padding-left: 12px; }

p
    +hanging-indent(12px)

=float-container                #items {
  +clearfix                       display: inline-block; }
  div                             #items:after {
    float: left                     content: quot;.quot;;
  .clear                            display: block;
    clear: both                     height: 0;
                                    clear: both;
#items                              visibility: hidden; }
  +float-container                * html #items {
                                    height: 1px; }
                                  #items div {
                                    float: left; }
                                  #items .clear {
                                    clear: both; }
@import
Sass                                   CSS
// classes.sass                        .highlight {
.highlight                               color: #ffe; }
  :color #ffe
                                       @import url(zen.css);
@import classes.sass                   @font-face {
                                         font-family: quot;Bitstream Vera Sansquot;;
@import zen.css                          src: url(http://foo.bar/bvs); }

// egyéb kukacokat is békénhagyja
@font-face
  :font-family quot;Bitstream Vera Sansquot;
  :src url(http://foo.bar/bvs)
Compass
Mi az a Compass?
•   Egy Sass-re épülő framework
•   Több ismert CSS framework-öt
    támogat Sass mixinek segítségével
    (Blueprint, YUI, 960.gs)
•   Sok hasznos CSS mintát ad (reset,
    clearfix, no-bullets, horizontal-list,
    inline-list, inline-block, tag-cloud,
    alternating-rows-and-columns, stb.)
screen.sass (példa)
@import   blueprint/screen.sass
@import   blueprint/modules/grid.sass
@import   blueprint/modules/colors.sass
@import   compass/reset.sass
@import   compass/utilities.sass

body.blueprint
  +blueprint-typography
  .container
    +container
  #header
    +column(24)
    h1
       :float left
    #site-actions
       :float right
       +horizontal-list
       +no-bullets
  #main-content
    +column(18)
    +colborder
  #sidebar
    +column(5,true)
  #footer
    +column(24)
Kompatibilitás
Akkor ERB szemét?
•   A különböző template-ek megélnek
    egymás mellett
•   show.html.erb, show.html.haml,
    feed.xml.builder, feed.xml.haml
•   Generált ERB kódok maradhatnak,
    amíg át nem kell írni
•   Akár kombinálhatóak is
És a CSS

•   Sass nagyon hasonlít CSS-hez
•   Csak kiszeded a {} és ; karaktereket és
    valid Sass
•   html2haml, css2sass
Konfigurálhatóság


•   :escape_html, :supress_eval,
    :autoclose, :preserve, stb.
•   :style, :attribute_syntax
Telepítés
$   git clone git://github.com/nex3/haml.git
$   cd haml && rake install; cd ..
$   git clone git://github.com/chriseppstein/compass.git
$   cd compass && rake install; cd ..
$   cd /my/cool/rails/project
$   haml --rails .
$   compass --rails -f blueprint
Compass recommends that you keep your stylesheets in app/stylesheets/
instead of the Sass default location of public/stylesheets/sass/.
Is this OK? (Y/n) y

Compass recommends that you keep your compiled css in public/stylesheets/
compiled/ instead the Sass default of public/stylesheets/.
However, if you're exclusively using Sass, then public/stylesheets/ is
recommended.
Emit compiled stylesheets to public/stylesheets/compiled? (Y/n) n
directory app/stylesheets/
   create app/stylesheets/screen.sass
   create app/stylesheets/print.sass
   create app/stylesheets/ie.sass
   create config/initializers/compass.rb
   create app/views/layouts/application.html.haml
További infók

•   http://haml.hamptoncatlin.com/

•   http://haml.hamptoncatlin.com/docs/rdoc/classes/Haml.html

•   http://haml.hamptoncatlin.com/docs/rdoc/classes/Sass.html

•   http://wiki.github.com/chriseppstein/compass/

•   http://acts-as-architect.blogspot.com/2008/11/compass-
    primer.html

•   http://www.blueprintcss.org/

More Related Content

What's hot

Rapid Prototyping
Rapid PrototypingRapid Prototyping
Rapid Prototyping
Even Wu
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?
brynary
 
El día grande de los rodriguez
El día grande de los rodriguezEl día grande de los rodriguez
El día grande de los rodriguez
yumac00
 
Changing Template Engine
Changing Template EngineChanging Template Engine
Changing Template Engine
Takatsugu Shigeta
 
Evolution of API With Blogging
Evolution of API With BloggingEvolution of API With Blogging
Evolution of API With Blogging
Takatsugu Shigeta
 
Javascript Basic
Javascript BasicJavascript Basic
Javascript Basic
Kang-min Liu
 
Critical Rendering Path
Critical Rendering PathCritical Rendering Path
Critical Rendering Path
BarbaraFellner1
 
ColdFusion ORM
ColdFusion ORMColdFusion ORM
ColdFusion ORM
Denard Springle IV
 
Script iklan cse
Script iklan cseScript iklan cse
Script iklan cse
Ahmad Kartiwa
 
Tfbyoweb.4.9.17
Tfbyoweb.4.9.17Tfbyoweb.4.9.17
Tfbyoweb.4.9.17
Jordan Zurowski
 
Meetup django common_problems(1)
Meetup django common_problems(1)Meetup django common_problems(1)
Meetup django common_problems(1)
Eric Satterwhite
 
Beyond CSS Architecture
Beyond CSS ArchitectureBeyond CSS Architecture
Beyond CSS Architecture
拓樹 谷
 
Pemrograman Web 4 - Bootstrap 3
Pemrograman Web 4 - Bootstrap 3Pemrograman Web 4 - Bootstrap 3
Pemrograman Web 4 - Bootstrap 3
Nur Fadli Utomo
 
Handout6 html frames
Handout6 html framesHandout6 html frames
Handout6 html frames
Nadine Guevarra
 
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsMobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
Kaelig Deloumeau-Prigent
 
WordPress theme translation
WordPress theme translationWordPress theme translation
WordPress theme translation
Yoav Farhi
 
Handout3 links
Handout3 linksHandout3 links
Handout3 links
Nadine Guevarra
 
PHP 102: Out with the Bad, In with the Good
PHP 102: Out with the Bad, In with the GoodPHP 102: Out with the Bad, In with the Good
PHP 102: Out with the Bad, In with the Good
Jeremy Kendall
 
Stylesheets for Online Help - Scott DeLoach, ClickStart
Stylesheets for Online Help - Scott DeLoach, ClickStartStylesheets for Online Help - Scott DeLoach, ClickStart
Stylesheets for Online Help - Scott DeLoach, ClickStart
Scott DeLoach
 
CSS Layout Tutorial
CSS Layout TutorialCSS Layout Tutorial
CSS Layout Tutorial
hstryk
 

What's hot (20)

Rapid Prototyping
Rapid PrototypingRapid Prototyping
Rapid Prototyping
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?
 
El día grande de los rodriguez
El día grande de los rodriguezEl día grande de los rodriguez
El día grande de los rodriguez
 
Changing Template Engine
Changing Template EngineChanging Template Engine
Changing Template Engine
 
Evolution of API With Blogging
Evolution of API With BloggingEvolution of API With Blogging
Evolution of API With Blogging
 
Javascript Basic
Javascript BasicJavascript Basic
Javascript Basic
 
Critical Rendering Path
Critical Rendering PathCritical Rendering Path
Critical Rendering Path
 
ColdFusion ORM
ColdFusion ORMColdFusion ORM
ColdFusion ORM
 
Script iklan cse
Script iklan cseScript iklan cse
Script iklan cse
 
Tfbyoweb.4.9.17
Tfbyoweb.4.9.17Tfbyoweb.4.9.17
Tfbyoweb.4.9.17
 
Meetup django common_problems(1)
Meetup django common_problems(1)Meetup django common_problems(1)
Meetup django common_problems(1)
 
Beyond CSS Architecture
Beyond CSS ArchitectureBeyond CSS Architecture
Beyond CSS Architecture
 
Pemrograman Web 4 - Bootstrap 3
Pemrograman Web 4 - Bootstrap 3Pemrograman Web 4 - Bootstrap 3
Pemrograman Web 4 - Bootstrap 3
 
Handout6 html frames
Handout6 html framesHandout6 html frames
Handout6 html frames
 
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsMobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
 
WordPress theme translation
WordPress theme translationWordPress theme translation
WordPress theme translation
 
Handout3 links
Handout3 linksHandout3 links
Handout3 links
 
PHP 102: Out with the Bad, In with the Good
PHP 102: Out with the Bad, In with the GoodPHP 102: Out with the Bad, In with the Good
PHP 102: Out with the Bad, In with the Good
 
Stylesheets for Online Help - Scott DeLoach, ClickStart
Stylesheets for Online Help - Scott DeLoach, ClickStartStylesheets for Online Help - Scott DeLoach, ClickStart
Stylesheets for Online Help - Scott DeLoach, ClickStart
 
CSS Layout Tutorial
CSS Layout TutorialCSS Layout Tutorial
CSS Layout Tutorial
 

Viewers also liked

Ruby Crash Course
Ruby Crash CourseRuby Crash Course
Ruby Crash Course
László Bácsi
 
Monk
MonkMonk
App Lego
App LegoApp Lego
App Lego
László Bácsi
 
Firefox kiterjesztés fejlesztés
Firefox kiterjesztés fejlesztésFirefox kiterjesztés fejlesztés
Firefox kiterjesztés fejlesztés
László Bácsi
 
GovLoop Online Innovator's Summit 9/2012
GovLoop Online Innovator's Summit 9/2012GovLoop Online Innovator's Summit 9/2012
GovLoop Online Innovator's Summit 9/2012
Hillary Hartley
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
Luminary Labs
 

Viewers also liked (6)

Ruby Crash Course
Ruby Crash CourseRuby Crash Course
Ruby Crash Course
 
Monk
MonkMonk
Monk
 
App Lego
App LegoApp Lego
App Lego
 
Firefox kiterjesztés fejlesztés
Firefox kiterjesztés fejlesztésFirefox kiterjesztés fejlesztés
Firefox kiterjesztés fejlesztés
 
GovLoop Online Innovator's Summit 9/2012
GovLoop Online Innovator's Summit 9/2012GovLoop Online Innovator's Summit 9/2012
GovLoop Online Innovator's Summit 9/2012
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 

Similar to Haml, Sass & Compass

Front End on Rails
Front End on RailsFront End on Rails
Front End on Rails
Justin Halsall
 
Ajax On S2 Odp
Ajax On S2 OdpAjax On S2 Odp
Ajax On S2 Odp
ghessler
 
Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On Rails
Wen-Tien Chang
 
JSP Custom Tags
JSP Custom TagsJSP Custom Tags
JSP Custom Tags
BG Java EE Course
 
Rails e suas Gems
Rails e suas GemsRails e suas Gems
Rails e suas Gems
Rodrigo Martins
 
User Experience is dead. Long live the user experience!
User Experience is dead. Long live the user experience!User Experience is dead. Long live the user experience!
User Experience is dead. Long live the user experience!
Greg Bell
 
Plone Interactivity
Plone InteractivityPlone Interactivity
Plone Interactivity
Eric Steele
 
Html5, css3, canvas, svg and webgl
Html5, css3, canvas, svg and webglHtml5, css3, canvas, svg and webgl
Html5, css3, canvas, svg and webgl
Kilian Valkhof
 
LAMP_TRAINING_SESSION_3
LAMP_TRAINING_SESSION_3LAMP_TRAINING_SESSION_3
LAMP_TRAINING_SESSION_3
umapst
 
KMUTNB - Internet Programming 3/7
KMUTNB - Internet Programming 3/7KMUTNB - Internet Programming 3/7
KMUTNB - Internet Programming 3/7
phuphax
 
Jade & Javascript templating
Jade & Javascript templatingJade & Javascript templating
Jade & Javascript templating
wearefractal
 
What I brought back from Austin
What I brought back from AustinWhat I brought back from Austin
What I brought back from Austin
Lisa Adkins
 
Ajax ons2
Ajax ons2Ajax ons2
Ajax ons2
Chad Davis
 
We9 Struts 2.0
We9 Struts 2.0We9 Struts 2.0
We9 Struts 2.0
wangjiaz
 
Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8
Tatsuhiko Miyagawa
 
Page Caching Resurrected
Page Caching ResurrectedPage Caching Resurrected
Page Caching Resurrected
Ben Scofield
 
Rails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity PresentationRails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity Presentation
railsconf
 
5.2 nesting and floating elements
5.2 nesting and floating elements5.2 nesting and floating elements
5.2 nesting and floating elements
Bulldogs83
 
Lecture1 B Frames&Forms
Lecture1 B  Frames&FormsLecture1 B  Frames&Forms
Lecture1 B Frames&Forms
Sur College of Applied Sciences
 
JWU Guest Talk: JavaScript and AJAX
JWU Guest Talk: JavaScript and AJAXJWU Guest Talk: JavaScript and AJAX
JWU Guest Talk: JavaScript and AJAX
Hilary Mason
 

Similar to Haml, Sass & Compass (20)

Front End on Rails
Front End on RailsFront End on Rails
Front End on Rails
 
Ajax On S2 Odp
Ajax On S2 OdpAjax On S2 Odp
Ajax On S2 Odp
 
Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On Rails
 
JSP Custom Tags
JSP Custom TagsJSP Custom Tags
JSP Custom Tags
 
Rails e suas Gems
Rails e suas GemsRails e suas Gems
Rails e suas Gems
 
User Experience is dead. Long live the user experience!
User Experience is dead. Long live the user experience!User Experience is dead. Long live the user experience!
User Experience is dead. Long live the user experience!
 
Plone Interactivity
Plone InteractivityPlone Interactivity
Plone Interactivity
 
Html5, css3, canvas, svg and webgl
Html5, css3, canvas, svg and webglHtml5, css3, canvas, svg and webgl
Html5, css3, canvas, svg and webgl
 
LAMP_TRAINING_SESSION_3
LAMP_TRAINING_SESSION_3LAMP_TRAINING_SESSION_3
LAMP_TRAINING_SESSION_3
 
KMUTNB - Internet Programming 3/7
KMUTNB - Internet Programming 3/7KMUTNB - Internet Programming 3/7
KMUTNB - Internet Programming 3/7
 
Jade & Javascript templating
Jade & Javascript templatingJade & Javascript templating
Jade & Javascript templating
 
What I brought back from Austin
What I brought back from AustinWhat I brought back from Austin
What I brought back from Austin
 
Ajax ons2
Ajax ons2Ajax ons2
Ajax ons2
 
We9 Struts 2.0
We9 Struts 2.0We9 Struts 2.0
We9 Struts 2.0
 
Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8
 
Page Caching Resurrected
Page Caching ResurrectedPage Caching Resurrected
Page Caching Resurrected
 
Rails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity PresentationRails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity Presentation
 
5.2 nesting and floating elements
5.2 nesting and floating elements5.2 nesting and floating elements
5.2 nesting and floating elements
 
Lecture1 B Frames&Forms
Lecture1 B  Frames&FormsLecture1 B  Frames&Forms
Lecture1 B Frames&Forms
 
JWU Guest Talk: JavaScript and AJAX
JWU Guest Talk: JavaScript and AJAXJWU Guest Talk: JavaScript and AJAX
JWU Guest Talk: JavaScript and AJAX
 

Recently uploaded

GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Jeffrey Haguewood
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
Pravash Chandra Das
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
Intelisync
 

Recently uploaded (20)

GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
 

Haml, Sass & Compass

  • 1. Haml, Sass, Compass Bácsi László bacsi.laszlo@virgo.hu
  • 2. Haml • Sablonozó motor • HTML-nél egyszerűbb és átláthatóbb • Nincs redundancia (DRY) • Szemantikus kód, szép kimenet
  • 3. Sass • Haml szerű szintaxis StyleSheet-ekhez • Egymásba ágyazott kiválasztók • Nincs redundancia (DRY) • Konstansok és egyszerű műveletek • Újrahasználató CSS mixinek
  • 4. A leíró kód szép kellene legyen • A leíró kód nem kellene ismételje magát • A leíró kód jól indentált kellene legyen • A struktúra tisztán látható kellene legyen
  • 6. Alapok Haml HTML #content <div id='content'> .left.column <div class='left column'> %h2 Welcome to our site! <h2>Welcome to our site!</h2> %p= print_information <p> .right.column= render :partial => quot;sidebarquot; <%= print_information %> </p> </div> <div class=quot;right columnquot;> <%= render :partial => quot;sidebarquot; %> </div> </div>
  • 7. Alapok Haml HTML %tagname{:attr => 'value'} content <tagname attr=quot;valuequot;>content</tagname> %tagname#id.class content <tagname id=quot;idquot; class=quot;classquot;>content</ tagname> %tagname <tagname> %innerTag <innerTag/> and some content and some content </tagname> #company Virgo <div id=quot;companyquot;>Virgo</div> .employee Bácsi László <div class=quot;employeequot;>Bácsi László</div>
  • 8. -, = – Ruby kód beágyazás Rubys Haml kód Generált HTML %dl <dl> - now = DateTime.now <dt>Dátum és idő:</dt> %dt Dátum és idő: <dd> %dd Boldog új évet! - if now > DateTime.parse('2008-12-31') </dd> Boldog új évet! </dl> - else = now.to_s <dl> <dt>Dátum és idő:</dt> <dd> 2008-12-30T12:31:45+01:00 </dd> </dl> - @gems = %w{rails haml compass} <ul id='gems'> %ul#gems <li class='gem'>rails</li> - @gems.each do |gem| <li class='gem'>haml</li> %li.gem= gem <li class='gem'>compass</li> </ul>
  • 9. {} – Attribútumok Haml HTML %bar/ <bar/> %script{:type => 'text/' + 'javascript', | <script src='/js/locale.hu.js' type='text/ :src => quot;/js/locale.#{@lang}.jsquot;} | javascript'></script> # ruby helperek def defaults {:type => 'checkbox', :value => '1'} end def override {:type => 'radio'} end <input type=quot;radioquot; value=quot;1quot; %input{defaults, override, :selected => true} selected=quot;selectedquot;/>
  • 10. [] – id és class generálás Haml HTML - @user = User.find(42) <div id=quot;current_user_42quot; %div[@user, :current] class=quot;current_userquot;> %span[7] 7. <span id=quot;fixnum_7quot; class=quot;fixnumquot;>7.</span> Kúl, mi? Kúl, mi? </div>
  • 11. ==, &=, !=, -# – Ruby inputok Haml HTML - name = quot;<b>Haml</b>quot; = quot;Hello, #{name}!quot; Hello, <b>Haml</b>! == Hello, #{name}! Hello, <b>Haml</b>! &= quot;Hello, #{name}!quot; Hello, &lt;b&gt;Haml&lt;/b&gt;! != quot;Hello, #{name}!quot; Hello, <b>Haml</b>! -# Ez itt egy komment, ami nem kerül ki
  • 12. !!! – xml és doctype Haml HTML !!! XML <?xml version='1.0' encoding='utf-8' ?> !!! XML iso-8859-2 <?xml version='1.0' encoding='iso-8859-2' ?> !!! Strict <!DOCTYPE html PUBLIC quot;-//W3C//DTD XHTML 1.0 Strict//ENquot; quot;http://www.w3.org/TR/xhtml1/DTD/ xhtml1-strict.dtdquot;>
  • 13. / – Kommentek Haml HTML - name = quot;Calvinquot; <div class='user'> .user <!-- Ez itt a neve --> / Ez itt a neve Calvin = name </div> / <!-- Ezt a kódot most egyelőre nem rakjuk ki, Ezt a kódot most egyelőre nem rakjuk ki, mert problémák lehetnek belőle. mert problémák lehetnek belőle. %script <script> evil(); evil(); </script> --> <!--[if IE]> /[if IE] <link href='/css/ie.css' rel='stylesheet' %link{:href => quot;/css/ie.cssquot;, | type='text/css' /> :rel => quot;stylesheetquot;, | <![endif]--> :type => quot;text/cssquot;} |
  • 14. :markdown – Filterek Haml HTML %div <div> :markdown <h1>Hello <em>World</em>!</h1> # Hello *World*! </div> %Content{:type => 'html'} <Content type='html'> :cdata <![CDATA[ <p>iWiW gadzsett</p> <p>iWiW gadzsett</p> ]]> </Content> # saját filter module Haml::Filters::Upcaser include Haml::Filters::Base def render(text) text.upcase end end %h1 <h1> :upcaser FIGYELEM, FIGYELEM! figyelem, figyelem! </h1>
  • 15. Sass
  • 16. Alapok Sass CSS #box #box { margin: 10px margin: 10px; color: #ff0 color: #ff0; } #box #box { :margin 10px margin: 10px; :color #ff0 color: #ff0; } #box #box { :margin 10px margin: 10px; :color #ff0 color: #ff0; } h1 #box h1 { :font-size 0.8em font-size: 0.8em; } a #box h1 a { :text-decoration none text-decoration: none; }
  • 17. Konstansok Sass CSS !highlight = #ccb !normal_text = 12px body body { :font-size = !normal_text font-size: 12px; } em em { :background-color = !highlight background-color: #ccccbb; } em.important em.important { :background-color = !highlight + #333 background-color: #ffffee; :font-size = 1.5 * !normal_text font-size: 18px; }
  • 18. Kommentek Sass CSS /* Fejléc /* Fejléc */ #header #header { :font-size 1em font-size: 1em; } // Ez itt meg bele se kerül a generált css-be /* /* * Ez egy többsoros Ez egy többsoros * quot;hangosquot; komment */ quot;hangosquot; komment #footer { #footer font-size: 0.8em; } :font-size 0.8em // Ez pedig szintén több soros, de nem kerül be a css kódba
  • 19. Bonyolultabb kombinációk Sass CSS #main #main { :width 600px width: 600px; } p, div #main p, #main div { :font-size 1.5em font-size: 1.5em; } a #main p a, #main div a { :font-weight bold font-weight: bold; } img #main p a img, #main div a img { :border 0 border: 0; }
  • 20. Szülő választó Sass CSS a a{ :color #00f color: #00f; } img a img { :border 0 border: 0; } &.disabled a.disabled { :color #444 color: #444; } &:link, &:active, &:visited a:link, a:active, a:visited { :text-decoration none text-decoration: none; } &:hover a:hover { :color #0ff color: #0ff; } img a:hover img { :border 2px solid #0ff border: 2px solid #0ff; } body.admin & body.admin a:hover img { :border-color #f00 border-color: #f00; }
  • 21. Attribútum namespace Sass CSS em em { :font font-size: 14px; :size 14px font-style: italic; :style italic font-family: Verdana, sans-serif; } :family Verdana, sans-serif
  • 22. Újrafelhasználható kódok Sass CSS =clearfix ul.images { display: inline-block display: inline-block; } &:after ul.images:after { content: quot;.quot; content: quot;.quot;; display: block display: block; height: 0 height: 0; clear: both clear: both; visibility: hidden visibility: hidden; } * html & * html ul.images { height: 1px height: 1px; } ul.images +clearfix p strong { =larger-text font-size: 1.2em; } :font-size 1.2em p strong em { p strong font-size: 1.2em; } +larger-text p strong em .important { em font-size: 1.2em; } +larger-text .important +larger-text
  • 23. Paraméterek és kombinálás Sass CSS =hanging-indent(!indentation) p{ text-indent = -!indentation text-indent: -12px; padding-left = !indentation padding-left: 12px; } p +hanging-indent(12px) =float-container #items { +clearfix display: inline-block; } div #items:after { float: left content: quot;.quot;; .clear display: block; clear: both height: 0; clear: both; #items visibility: hidden; } +float-container * html #items { height: 1px; } #items div { float: left; } #items .clear { clear: both; }
  • 24. @import Sass CSS // classes.sass .highlight { .highlight color: #ffe; } :color #ffe @import url(zen.css); @import classes.sass @font-face { font-family: quot;Bitstream Vera Sansquot;; @import zen.css src: url(http://foo.bar/bvs); } // egyéb kukacokat is békénhagyja @font-face :font-family quot;Bitstream Vera Sansquot; :src url(http://foo.bar/bvs)
  • 26. Mi az a Compass? • Egy Sass-re épülő framework • Több ismert CSS framework-öt támogat Sass mixinek segítségével (Blueprint, YUI, 960.gs) • Sok hasznos CSS mintát ad (reset, clearfix, no-bullets, horizontal-list, inline-list, inline-block, tag-cloud, alternating-rows-and-columns, stb.)
  • 27. screen.sass (példa) @import blueprint/screen.sass @import blueprint/modules/grid.sass @import blueprint/modules/colors.sass @import compass/reset.sass @import compass/utilities.sass body.blueprint +blueprint-typography .container +container #header +column(24) h1 :float left #site-actions :float right +horizontal-list +no-bullets #main-content +column(18) +colborder #sidebar +column(5,true) #footer +column(24)
  • 29. Akkor ERB szemét? • A különböző template-ek megélnek egymás mellett • show.html.erb, show.html.haml, feed.xml.builder, feed.xml.haml • Generált ERB kódok maradhatnak, amíg át nem kell írni • Akár kombinálhatóak is
  • 30. És a CSS • Sass nagyon hasonlít CSS-hez • Csak kiszeded a {} és ; karaktereket és valid Sass • html2haml, css2sass
  • 31. Konfigurálhatóság • :escape_html, :supress_eval, :autoclose, :preserve, stb. • :style, :attribute_syntax
  • 32. Telepítés $ git clone git://github.com/nex3/haml.git $ cd haml && rake install; cd .. $ git clone git://github.com/chriseppstein/compass.git $ cd compass && rake install; cd .. $ cd /my/cool/rails/project $ haml --rails . $ compass --rails -f blueprint Compass recommends that you keep your stylesheets in app/stylesheets/ instead of the Sass default location of public/stylesheets/sass/. Is this OK? (Y/n) y Compass recommends that you keep your compiled css in public/stylesheets/ compiled/ instead the Sass default of public/stylesheets/. However, if you're exclusively using Sass, then public/stylesheets/ is recommended. Emit compiled stylesheets to public/stylesheets/compiled? (Y/n) n directory app/stylesheets/ create app/stylesheets/screen.sass create app/stylesheets/print.sass create app/stylesheets/ie.sass create config/initializers/compass.rb create app/views/layouts/application.html.haml
  • 33. További infók • http://haml.hamptoncatlin.com/ • http://haml.hamptoncatlin.com/docs/rdoc/classes/Haml.html • http://haml.hamptoncatlin.com/docs/rdoc/classes/Sass.html • http://wiki.github.com/chriseppstein/compass/ • http://acts-as-architect.blogspot.com/2008/11/compass- primer.html • http://www.blueprintcss.org/