root/dotfiles/vim/cho45/sortcss @ 16024

Revision 16024, 1.9 kB (checked in by cho45, 5 years ago)

dotfiles 更新

  • Property svn:executable set to *
Line 
1#!/usr/bin/env ruby
2#
3# secondlife - http://rails2u.com/
4# distributed under the MIT licence.
5#
6
7CSS_ORDER = %w(
8display
9float
10clear
11position
12top
13right
14bottom
15left
16font
17font-family
18font-style
19font-variant
20font-weight
21font-stretch
22font-size
23font-size-adjust
24visibility
25z-index
26direction
27unicode-bidi
28width
29min-width
30max-width
31height
32min-height
33max-height
34line-height
35vertical-align
36overflow
37clip
38margin
39margin-top
40margin-right
41margin-bottom
42margin-left
43padding
44padding-top
45padding-right
46padding-bottom
47padding-left
48border
49border-style
50border-color
51border-width
52border-top
53border-bottom
54border-right
55border-left
56border-top-style
57border-right-style
58border-bottom-style
59border-left-style
60border-top-color
61border-right-color
62border-bottom-color
63border-left-color
64border-top-width
65border-right-width
66border-bottom-width
67border-left-width
68outline
69content
70compact
71run-in
72quotes
73marker-offset
74list-style
75list-style-type
76list-style-image
77list-style-position
78size
79marks
80page-break-before
81page-break-after
82page-break-inside
83page
84orphans
85widows
86background
87background-color
88background-image
89background-repeat
90background-attachment
91background-position
92color
93text-indent
94text-align
95text-decoration
96text-shadow
97letter-spacing
98word-spacing
99text-transform
100white-space
101table-layout
102empty-cells
103speak-header
104cursor
105volume
106speak
107pause-before
108pause-after
109pause
110cue-before
111cue-after
112cue
113play-during
114azimuth
115elevation
116speech-rate
117voice-family
118pitch
119pitch-range
120stress
121richness
122speak-punctuation
123speak-numeral
124)
125
126def property_order(line)
127        if m = line.match(/^\s*_?(.+?)\s*:/)
128                CSS_ORDER.each_with_index do |property, index|
129                        return index if property == m[1].downcase
130                end
131        end
132        if line.include? '{'
133                return -1
134        elsif line.include? '}'
135                return CSS_ORDER.length + 2
136        end
137        CSS_ORDER.length + 1
138end
139
140result = ARGF.read.gsub(%r{/\*([^*]*)\*/}m, '').to_a.map {|l| l.chomp.sub(/\s*:\s*/, ": ") }.sort_by do |line|
141        property_order line
142end
143
144puts result.join("\n")
Note: See TracBrowser for help on using the browser.