csswaxer 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (8) hide show
  1. data/LICENSE +21 -0
  2. data/README.md +34 -0
  3. data/Rakefile +3 -0
  4. data/VERSION +1 -0
  5. data/bin/csswaxer +17 -0
  6. data/lib/csswaxer.rb +97 -0
  7. data/lib/example.css +35 -0
  8. metadata +71 -0
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ === Ruby CSS Waxer License
2
+
3
+ Copyright (c) 2010 Claudio Baccigalupo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # RadioTagMap #
2
+
3
+ Ruby command that prettifies CSS files grouping lines by property rather than by selector
4
+
5
+ ## Installation ##
6
+
7
+ gem install csswaxer
8
+
9
+ ## Documentation ##
10
+
11
+ [http://rdoc.info/projects/claudiob/csswaxer](http://rdoc.info/projects/claudiob/csswaxer)
12
+
13
+ ## Examples ##
14
+
15
+ ### To create a KML map according to compare current 'Rock' and 'Country' songs
16
+
17
+ require 'radiotagmap'
18
+ Radiotagmap::update_kml '/tmp/overlay.kml' [['Country','Alt-Country']]
19
+
20
+ ## To do ##
21
+
22
+ * Accept CSS files with commands split on multiple lines
23
+ * Accept local CSS files, not only remote ones
24
+ * Accept different media types, not only screen
25
+ * Contain every possible CSS property, well organized
26
+
27
+ ## History ##
28
+
29
+ v0.0.1 2010/03/28
30
+ First commit that only works on CSS files with one-line style.
31
+
32
+ ## Copyright ##
33
+
34
+ Copyright (c) 2010 Claudio Baccigalupo. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'lib/csswaxer'
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/csswaxer ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ ## CSS Waxer is a command line interface for making CSS files more readable
3
+ ##
4
+ ## Usage: csswaxer [FILE or URL]
5
+ ##
6
+ ## Renders the waxed CSS file. Redirect the output to a file, if needed.
7
+ ##
8
+ ##
9
+
10
+ require 'csswaxer'
11
+
12
+ if ARGV.length < 1
13
+ puts "Usage: csswaxer [FILE or URL]."
14
+ exit
15
+ end
16
+
17
+ CssWaxer::wax(ARGV[0])
data/lib/csswaxer.rb ADDED
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Author:: Claudio Baccigalupo
4
+ # Copyright:: Copyright (c) 2010 - see LICENSE file
5
+
6
+ require 'css_parser'
7
+
8
+ module CssWaxer
9
+ class << self
10
+
11
+ # include CssParser
12
+ # Return a waxed version of a dirty CSS file, either local or remote
13
+ def wax(dirty_css)
14
+ # Open either a local or a remote file depending on the path
15
+ parser = CssParser::Parser.new
16
+ if dirty_css =~ /^https?:\/\/\S+$/i then
17
+ parser.load_remote! dirty_css
18
+ else
19
+ parser.load_file! dirty_css
20
+ end
21
+ # Track values that appear for each property to avoid duplication
22
+ appeared_values = {}
23
+ unrecognized_properties = []
24
+ css_properties = css_families.values.flatten
25
+ css_properties.each{|property| appeared_values[property] = []}
26
+ # Parse every selector and every rule in the stylesheet
27
+ parser.each_selector(:screen).each do |selector|
28
+ selector[:rules].each_selector do |selectors, declarations, specificity|
29
+ selector[:rules].each_declaration do |property, value, importance|
30
+ # Clean recognized properties, leave untouched the remaining ones
31
+ if css_properties.include?(property) && !value.nil?
32
+ if same_value = appeared_values[property].assoc(value)
33
+ same_value << selectors
34
+ else
35
+ appeared_values[property] << [value, selectors]
36
+ end
37
+ else
38
+ unrecognized_properties << [property, value, selectors]
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ css_families.each do |family, properties|
45
+ next if properties.all?{|property| appeared_values[property].empty?}
46
+ puts titleize(family)
47
+ properties.each do |property|
48
+ next if appeared_values[property].empty?
49
+ puts "\n/* #{property} */"
50
+ appeared_values[property].each do |p|
51
+ value = p.shift
52
+ puts "#{p.join(", ")}\t{#{property}: #{value}}"
53
+ end
54
+ end
55
+ end
56
+
57
+ unless unrecognized_properties.empty?
58
+ puts titleize("others")
59
+ unrecognized_properties.each do |property, value, selectors|
60
+ puts "#{selectors}\t{#{property}: #{value}}"
61
+ end
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ def titleize(title)
68
+ "\n/* #{'*'*73} */\n/* #{title.upcase}#{' '*(73-title.upcase.length)} */\n/* #{'*'*73} */\n"
69
+ end
70
+
71
+ def css_families
72
+ # Based on the list from http://www.eskimo.com/~bloo/indexdot/css/
73
+ {
74
+ 'Typography' => %w{font-family font-size font-style font-variant font-weight font font-size-adjust font-stretch},
75
+ 'Text' => %w{word-spacing letter-spacing white-space word-wrap text-align text-align-last text-decoration text-transform text-shadow text-indent text-underline-position},
76
+ 'Colors' => %w{color background-color layer-background-color border-top-color border-right-color border-bottom-color border-left-color border-color scrollbar-face-color scrollbar-arrow-color scrollbar-base-color scrollbar-shadow-color scrollbar-darkshadow-color scrollbar-highlight-color scrollbar-3dlight-color scrollbar-track-color outline-color},
77
+ 'Backgrounds' => %w{layer-background-image background-image background-repeat background-attachment background-position background-position-x background-position-y background},
78
+ 'Outlines' => %w{outline-style outline-width outline},
79
+ 'Lists' => %w{marker-offset list-style-type list-style-position list-style-image list-style},
80
+ 'Tables' => %w{border-collapse border-spacing caption-side empty-cells speak-header table-layout},
81
+ 'Layout' => %w{display visibility position float clear},
82
+ 'Sizes' => %w{width min-width max-width line-height height min-height max-height},
83
+ 'Positions' => %w{top right bottom left vertical-align overflow overflow-x overflow-y text-overflow clip z-index},
84
+ 'Margins' => %w{margin-top margin-right margin-bottom margin-left margin},
85
+ 'Paddings' => %w{padding-top padding-right padding-bottom padding-left padding},
86
+ 'Borders' => %w{border-top border-right border-bottom border-left border-top-width border-right-width border-bottom-width border-left-width border-width border-top-style border-right-style border-bottom-style border-left-style border-style border},
87
+ 'Dynamic' => %w{accelerator cursor filter behavior zoom},
88
+ 'Generated' =>%w{content counter-reset counter-increment include-source quotes},
89
+ 'International' => %w{unicode-bidi direction ruby-align ruby-overhang ruby-position line-break word-break writing-mode ime-mode text-justify text-autospace text-kashida-space layout-flow layout-grid-mode layout-grid-type layout-grid-line layout-grid-char layout-grid-char-spacing layout-grid },
90
+ 'Printing' => %w{page-break-before page-break-inside page-break-after page size marks widows orphans},
91
+ 'Aural' => %w{volume stress richness azimuth elevation voice-family speak-punctuation speak-numeral speak pitch-range pitch speech-rate play-during pause-before pause-after pause cue-before cue-after cue},
92
+ 'Opera' => %w{-replace -set-link-source -use-link-source},
93
+ 'Mozilla' => %w{-moz-binding -moz-border-radius -moz-border-radius-topleft -moz-border-radius-topright -moz-border-radius-bottomright -moz-border-radius-bottomleft -moz-border-top-colors -moz-border-right-colors -moz-border-bottom-colors -moz-border-left-colors -moz-opacity -moz-outline -moz-outline-color -moz-outline-style -moz-outline-width -moz-user-focus -moz-user-input -moz-user-modify -moz-user-select},
94
+ }
95
+ end
96
+ end
97
+ end
data/lib/example.css ADDED
@@ -0,0 +1,35 @@
1
+ a {line-height:12px}
2
+ b {font-size:12px;}
3
+ c, d {line-height: 12px}
4
+ .e#f {line-height: 12px; font-weight: bold}
5
+ g h {line-height: 12px; font-weight: bold;}
6
+ i {line-height: .1em; font-weight: bold}
7
+ j[k] {line-height: normal}
8
+ lmn {line-height: 12px }
9
+ o > p {line-heigddht: 12px }
10
+
11
+ /* Outputs to:
12
+ /* ************************************************************************** *
13
+ /* TYPOGRAPHY *
14
+ /* ************************************************************************** *
15
+
16
+ /* font-size *
17
+ b {font-size: 12px}
18
+
19
+ /* font-weight *
20
+ .e#f, g h, i {font-weight: bold}
21
+
22
+ /* ************************************************************************** *
23
+ /* SIZES *
24
+ /* ************************************************************************** *
25
+
26
+ /* line-height *
27
+ a, c, d, .e#f, g h, lmn {line-height: 12px}
28
+ i {line-height: .1em}
29
+ j[k] {line-height: normal}
30
+
31
+ /* ************************************************************************** *
32
+ /* OTHERS *
33
+ /* ************************************************************************** *
34
+ o > p {line-heigddht: 12px}
35
+ */
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: csswaxer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Claudio Baccigalupo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-03-28 00:00:00 +01:00
13
+ default_executable: csswaxer
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: css_parser
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.1
24
+ version:
25
+ description: CSS files are written with a focus on selectors, so that all properties related to a tag, class or id are grouped together. This makes it hard to a have a clear overview of the style; for instance which colors and fonts are used in the whole site. CSS Waxer reorganizes CSS files focusing on properties, so that every font-related property is packed together, followed by colors, backgrounds, layouts and so on.
26
+ email: claudiob@gmail.com
27
+ executables:
28
+ - csswaxer
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.md
34
+ files:
35
+ - README.md
36
+ - Rakefile
37
+ - LICENSE
38
+ - VERSION
39
+ - bin/csswaxer
40
+ - lib/csswaxer.rb
41
+ - lib/example.css
42
+ has_rdoc: true
43
+ homepage: http://github.com/claudiob/csswaxer
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --charset=UTF-8
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.5
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: "Command-line tool that makes stylesheet files more readable, grouping lines by property (typography, color, layout, \xE2\x80\xA6) rather than by selector"
70
+ test_files: []
71
+