css-annotate 1.0.0

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.
data/CHANGELOG ADDED
@@ -0,0 +1,10 @@
1
+ 2010-11-11 version 1.0.0
2
+
3
+ Changed options so --commented shows only commented rules.
4
+
5
+ Included Compass in dependencies.
6
+
7
+
8
+ 2010-11-11 version 0.1.0
9
+
10
+ The first release
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+ gemspec
3
+
4
+ group :development do
5
+ gem "thin"
6
+ gem "compass"
7
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Assaf Arkin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,9 @@
1
+ Usage:
2
+ css-annotate [options] filename
3
+
4
+ Options:
5
+ --commented Show only rules preceded by a comment
6
+ --syntax [name] Either sass or scss (default)
7
+
8
+
9
+ http://labnotes.org/wp-content/uploads/2010/11/Your-CSS-annotated.png
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ require "rake/testtask"
2
+
3
+ spec = Gem::Specification.load(Dir["*.gemspec"].first)
4
+
5
+ desc "Build the Gem"
6
+ task :build do
7
+ sh "gem build #{spec.name}.gemspec"
8
+ end
9
+
10
+ desc "Install #{spec.name} locally"
11
+ task :install=>:build do
12
+ sudo = "sudo" unless File.writable?( Gem::ConfigMap[:bindir])
13
+ sh "#{sudo} gem install #{spec.name}-#{spec.version}.gem"
14
+ end
15
+
16
+ desc "Push new release to gemcutter and git tag"
17
+ task :push=>["test", "build"] do
18
+ sh "git push"
19
+ puts "Tagging version #{spec.version} .."
20
+ sh "git tag v#{spec.version}"
21
+ sh "git push --tag"
22
+ puts "Building and pushing gem .."
23
+ sh "gem push #{spec.name}-#{spec.version}.gem"
24
+ end
25
+
26
+ desc "Run all tests"
27
+ Rake::TestTask.new do |task|
28
+ task.test_files = FileList['test/**/*_test.rb']
29
+ if Rake.application.options.trace
30
+ #task.warning = true
31
+ task.verbose = true
32
+ elsif Rake.application.options.silent
33
+ task.ruby_opts << "-W0"
34
+ else
35
+ task.verbose = true
36
+ end
37
+ task.ruby_opts << "-I."
38
+ end
39
+
40
+ task :clobber do
41
+ rm_rf %w{*.gem}
42
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/bin/css-annotate ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
+ require "css/annotate"
4
+ if filename = ARGV[0]
5
+ options = {}
6
+ if (i = ARGV.index("--syntax")) && ARGV[i+1]
7
+ options[:syntax] = ARGV[i + 1].to_sym
8
+ ARGV[i,2] = []
9
+ end
10
+ options[:all] = !ARGV.delete("--commented")
11
+ $stdout << CSS::Annotate.new(ARGV[0], options).to_html
12
+ else
13
+ print <<-TEXT
14
+ Usage:
15
+ css-annotate [options] filename
16
+
17
+ Options:
18
+ --commented Show only rules preceded by a comment
19
+ --syntax [name] Either sass or scss (default)
20
+
21
+ TEXT
22
+ exit -1
23
+ end
@@ -0,0 +1,24 @@
1
+ $: << File.dirname(__FILE__) + "/lib"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "css-annotate"
5
+ spec.version = IO.read("VERSION")
6
+ spec.author = "Assaf Arkin"
7
+ spec.email = "assaf@labnotes.org"
8
+ spec.homepage = "http://github.com/assaf/#{spec.name}"
9
+ spec.summary = "The Annotated CSS tells you which style to use where."
10
+ spec.description = "Uses in-line docs to map the stylesheet. Supports CSS and SCSS."
11
+ spec.post_install_message = "To get started, run the command css-annotate"
12
+
13
+ spec.files = Dir["{bin,lib,test}/**/*", "CHANGELOG", "VERSION", "MIT-LICENSE", "README.rdoc", "Rakefile", "Gemfile", "*.gemspec"]
14
+ spec.executable = "css-annotate"
15
+
16
+ spec.has_rdoc = true
17
+ spec.extra_rdoc_files = "README.rdoc", "CHANGELOG"
18
+ spec.rdoc_options = "--title", "#{spec.name} #{spec.version}", "--main", "README.rdoc",
19
+ "--webcvs", "http://github.com/assaf/#{spec.name}"
20
+
21
+ spec.required_ruby_version = '>= 1.8.7'
22
+ spec.add_dependency "compass", "~>0.10"
23
+ spec.add_dependency "haml", "~>3.0"
24
+ end
@@ -0,0 +1 @@
1
+ require "css/annotate"
@@ -0,0 +1,80 @@
1
+ require "haml"
2
+ require "sass/engine"
3
+ require "compass"
4
+ require "erb"
5
+ require "cgi"
6
+
7
+ module CSS
8
+ class Annotate
9
+
10
+ DEFAULT_OPTIONS = { :syntax=>:scss }
11
+
12
+ def initialize(filename, options = {})
13
+ @filename = filename
14
+ @options = DEFAULT_OPTIONS.merge(options)
15
+ paths = @options[:load_paths] || []
16
+ paths.push File.dirname(@filename)
17
+ paths.concat Compass::Frameworks::ALL.map { |framework| framework.stylesheets_directory }
18
+ @options[:load_paths] = paths
19
+ end
20
+
21
+ attr_reader :filename, :options, :rows
22
+
23
+ def annotate
24
+ $stderr << options.inspect
25
+ engine = Sass::Engine.new(IO.read(filename), options)
26
+ tree = engine.to_tree
27
+ tree.perform!(Sass::Environment.new)
28
+ resolve_rules tree
29
+ @rows = to_rows(tree)
30
+ end
31
+
32
+ def h(raw)
33
+ CGI.escapeHTML(raw.to_s)
34
+ end
35
+
36
+ def to_html
37
+ rows = annotate
38
+ ERB.new(IO.read(File.dirname(__FILE__) + "/annotate/template.erb")).run(binding)
39
+ end
40
+
41
+ def styles
42
+ Sass::Engine.new(IO.read(File.dirname(__FILE__) + "/annotate/style.scss"), :syntax=>:scss).render
43
+ end
44
+
45
+ protected
46
+
47
+ def resolve_rules(parent)
48
+ parent.children.each do |node|
49
+ if node.respond_to?(:parsed_rules)
50
+ rules = parent.respond_to?(:resolved_rules) ? parent.resolved_rules : nil
51
+ node.resolved_rules = node.parsed_rules.resolve_parent_refs(rules)
52
+ resolve_rules node
53
+ end
54
+ end
55
+ end
56
+
57
+ def to_rows(parent)
58
+ rows = []
59
+ nodes = parent.children
60
+ nodes.each_with_index do |node, i|
61
+ if Sass::Tree::RuleNode === node
62
+ if i > 0 && (prev = nodes[i - 1]) && Sass::Tree::CommentNode === prev
63
+ comment = prev.value.gsub(/(^\/\*\s*|\s*\*\/$)/, "")
64
+ end
65
+ if comment || options[:all]
66
+ selector = (node.resolved_rules || node.parsed_rules).to_a.to_s
67
+ style = "#{selector} {\n"
68
+ style << node.children.select { |child| Sass::Tree::PropNode === child }.
69
+ map { |prop| " #{prop.resolved_name}: #{prop.resolved_value};" }.join("\n")
70
+ style << "}\n"
71
+ rows << { :comment=>comment, :selector=>selector, :style=>style }
72
+ end
73
+ end
74
+ rows.concat to_rows(node) if node.has_children
75
+ end
76
+ rows
77
+ end
78
+
79
+ end
80
+ end
@@ -0,0 +1,56 @@
1
+ body {
2
+ margin: 0;
3
+ padding: 0;
4
+ font-family: "Helvetica";
5
+ }
6
+ /* Place on annotation table */
7
+ table.annotated {
8
+ width: 100%;
9
+ margin: 0;
10
+ padding: 0;
11
+ border-collapse: collapse;
12
+ border-bottom: 1px solid #ccc;
13
+
14
+ /* Apply to column that contains CSS selector/comment */
15
+ td.comment {
16
+ vertical-align: top;
17
+ padding: 0.3em 2em 0.6em 1em;
18
+
19
+ h2 {
20
+ font-size: 12pt;
21
+ margin: 0 0 0.1em 0;
22
+ color: #444;
23
+ }
24
+
25
+ blockquote {
26
+ padding: 0;
27
+ margin: 0;
28
+ }
29
+ }
30
+
31
+ /* Apply to column that contains CSS style */
32
+ td.code {
33
+ background: #eef;
34
+ vertical-align: top;
35
+ padding: 0.3em 1em 0.6em 2em;
36
+ border-left: 1px solid #ccc;
37
+ }
38
+
39
+ tr:hover td {
40
+ background: #ddf;
41
+ }
42
+ }
43
+ .footer {
44
+ padding: 1em 1em;
45
+ color: #888;
46
+
47
+ /* Use this to style filename in footer */
48
+ .filename {
49
+ border: 1px solid #eee;
50
+ padding: 0 0.3em;
51
+ }
52
+ a {
53
+ text-decoration: none;
54
+ color: #000;
55
+ }
56
+ }
@@ -0,0 +1,23 @@
1
+ <html>
2
+ <head>
3
+ <title>Your CSS, annotated</title>
4
+ <style><%= styles %></style>
5
+ </head>
6
+ <body>
7
+ <table class="annotated">
8
+ <% rows.each do |row| %>
9
+ <tr>
10
+ <td class="comment">
11
+ <h2><%= h row[:selector] %></h2>
12
+ <blockquote><%= h row[:comment] %></blockquote>
13
+ </div></td>
14
+ <td class="code"><pre><%= h row[:style]%></pre></td>
15
+ </tr>
16
+ <% end %>
17
+ <table>
18
+ <div class="footer">
19
+ Generated from <span class="filename"><%= filename %></span> on
20
+ <%= Time.now.strftime("%c") %> by <a href="http://github.com/assaf/css-annotate">CSS Annotate</a>
21
+ </div>
22
+ </body>
23
+ </html>
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: css-annotate
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Assaf Arkin
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-11 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: compass
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 31
30
+ segments:
31
+ - 0
32
+ - 10
33
+ version: "0.10"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: haml
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 7
45
+ segments:
46
+ - 3
47
+ - 0
48
+ version: "3.0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ description: Uses in-line docs to map the stylesheet. Supports CSS and SCSS.
52
+ email: assaf@labnotes.org
53
+ executables:
54
+ - css-annotate
55
+ extensions: []
56
+
57
+ extra_rdoc_files:
58
+ - README.rdoc
59
+ - CHANGELOG
60
+ files:
61
+ - bin/css-annotate
62
+ - lib/css/annotate/style.scss
63
+ - lib/css/annotate/template.erb
64
+ - lib/css/annotate.rb
65
+ - lib/css-annotate.rb
66
+ - CHANGELOG
67
+ - VERSION
68
+ - MIT-LICENSE
69
+ - README.rdoc
70
+ - Rakefile
71
+ - Gemfile
72
+ - css-annotate.gemspec
73
+ has_rdoc: true
74
+ homepage: http://github.com/assaf/css-annotate
75
+ licenses: []
76
+
77
+ post_install_message: To get started, run the command css-annotate
78
+ rdoc_options:
79
+ - --title
80
+ - css-annotate 1.0.0
81
+ - --main
82
+ - README.rdoc
83
+ - --webcvs
84
+ - http://github.com/assaf/css-annotate
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 57
93
+ segments:
94
+ - 1
95
+ - 8
96
+ - 7
97
+ version: 1.8.7
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ requirements: []
108
+
109
+ rubyforge_project:
110
+ rubygems_version: 1.3.7
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: The Annotated CSS tells you which style to use where.
114
+ test_files: []
115
+