Top Banner
Asset Pipeline 天龍國 Developer Assets 管理法 1 1 星期日, 4月 15, 2012
30

Asset pipeline osdc

May 07, 2015

Download

Technology

wildjcrt
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Asset pipeline   osdc

Asset Pipeline天龍國 Developer 的 Assets 管理法

1

1星期日, 4月 15, 2012

Page 2: Asset pipeline   osdc

github.com/xdite

xdite

Xdite Cheng

2

2星期日, 4月 15, 2012

Page 3: Asset pipeline   osdc

PIXNETgithub.com/wildjcrtwildjcrt

Ruby TaiwanRailsTuesday

小蟹

3

3星期日, 4月 15, 2012

Page 4: Asset pipeline   osdc

Assets

▪CSS

▪ JavaScript

▪ Image

4

4星期日, 4月 15, 2012

Page 5: Asset pipeline   osdc

Asset = 次等公民

5

5星期日, 4月 15, 2012

Page 6: Asset pipeline   osdc

public/• icon-01.png

• icon-02.png

• jquery.js

• logo.png

• main.css

• reset.css

• tinymce/

• ....

6

6星期日, 4月 15, 2012

Page 7: Asset pipeline   osdc

Asset 管理上需要面對的問題

▪Optimization Issue

▪Outdate

▪Hard to write maintainable code

7

7星期日, 4月 15, 2012

Page 8: Asset pipeline   osdc

Optimization Issue

▪Compress / Trim

▪CSS Sprite

▪Development / Deploy

▪CDN / clear cache

8

8星期日, 4月 15, 2012

Page 9: Asset pipeline   osdc

Outdate

▪ jQuery

▪ jQuery UI

▪ Bootstrap

▪ TinyMCE

▪ ....

9

9星期日, 4月 15, 2012

Page 10: Asset pipeline   osdc

Maintain Issue

#header{ ... }#header nav.main{ ... }#header nav.main a{ ...}#header nav.main a:hover{...}

不覺得這樣寫很囉嗦的請舉手

10

10星期日, 4月 15, 2012

Page 11: Asset pipeline   osdc

Maintain Issue

11

▪ JavaScript

11星期日, 4月 15, 2012

Page 12: Asset pipeline   osdc

Asset PipelineSince Rails 3.1

12

12星期日, 4月 15, 2012

Page 13: Asset pipeline   osdc

以一個全新的角度去管理 Asset

13

13星期日, 4月 15, 2012

Page 14: Asset pipeline   osdc

Asset Pipeline 提供

▪Optimization Mechanism

▪Organization Rules

▪ Asset Version Control

▪Write assets in other language

14

14星期日, 4月 15, 2012

Page 15: Asset pipeline   osdc

這麼神?

15

15星期日, 4月 15, 2012

Page 16: Asset pipeline   osdc

Optimization

▪Compress / Trim

▪CSS Sprite

▪Development / Deploy

▪CDN / clear cache內建 Best Practices,Deploy 時自動完成

16

16星期日, 4月 15, 2012

Page 17: Asset pipeline   osdc

Organization Rules▪ vendor/assets/

▫ jQuery, TinyMCE, Bootstrap...

▪ lib/assets/

▫ utility

▪ app/assets

▫main, sidebar, font,

17

17星期日, 4月 15, 2012

Page 18: Asset pipeline   osdc

Organization Rules

/* *= require bootstrap *= require sidebar *= require common *= require_self *= require_tree .*/

一律視為 /assets 下檔案掛起來

18

18星期日, 4月 15, 2012

Page 19: Asset pipeline   osdc

Asset Version Control▪ Bundler => Asset As Gem

▫Gemfilegem "jquery-rails"gem "tinymce-rails"gem "bootstrap", "1.4.1"

○ application.js//= require jquery//= require jquery_ujs//= require bootstrap//= require tinymce

19

19星期日, 4月 15, 2012

Page 20: Asset pipeline   osdc

Front-end Meta Languages

▪CoffeeScript

▪ Sass / SCSS

▫Compass

20

20星期日, 4月 15, 2012

Page 21: Asset pipeline   osdc

CoffeeScript

class Animal constructor: (@name) ->

move: (meters) -> alert @name + " moved #{meters}m."

class Snake extends Animal move: -> alert "Slithering..." super 5

21

21星期日, 4月 15, 2012

Page 22: Asset pipeline   osdc

CoffeeScript

▪ avoid the“bad parts”

▫ avoid global variable / function

▫使用 -> 和 indent (縮排)

▫容易偵測 syntax error

22

22星期日, 4月 15, 2012

Page 23: Asset pipeline   osdc

Sass / SCSS

#header{ ... }#header nav.main{ ... }#header nav.main a{ ...}#header nav.main a:hover{...}

23

23星期日, 4月 15, 2012

Page 24: Asset pipeline   osdc

Sass / SCSS

▪We should do this way

#header{ nav.main{ a{ &:hover{ } } }}

24

24星期日, 4月 15, 2012

Page 25: Asset pipeline   osdc

Compass

▪CSS Authoring Framework

▫ Blueprint

▫ 960

▫ fancy buttons

▫CSS3 Pie

25

25星期日, 4月 15, 2012

Page 26: Asset pipeline   osdc

Compass

▪ Features

▫ replace-text

▫ border-radius

▫ gradient

▫ sprite

26

26星期日, 4月 15, 2012

Page 27: Asset pipeline   osdc

Organize SCSS

▪ by default block ( header / footer / sidebar )

▪ by special block

▪ by feature

▪ by (Rails) controller

▪ by page specific

27

27星期日, 4月 15, 2012

Page 28: Asset pipeline   osdc

Compass and bootstrap

▪main.css

28

@import "bootstrap";

// config variables first and import compass$base-font-size: 16px;$base-line-height: 24px;$relative-font-sizing: false;@import "compass";

@import "module/mixins";@import "module/box";@import "module/modal"; // override bootstrap modal effect

@import "partial/header";@import "partial/sidebar-items";@import "partial/sidebar-tools";@import "partial/sidebar";

28星期日, 4月 15, 2012

Page 30: Asset pipeline   osdc

Thanks

30

30星期日, 4月 15, 2012