css-annotated 0.1.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.
File without changes
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
@@ -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.
@@ -0,0 +1,10 @@
1
+ Usage:
2
+ css-annotate [options] filename
3
+
4
+ Options:
5
+ --all Show all styles (default, only commented styles)
6
+ --syntax [name]\tEither sass or scss (default)
7
+
8
+
9
+ http://cloud.github.com/downloads/assaf/css-annotate/Your%20CSS,%20annotated.png
10
+
@@ -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
+ 0.1.0
@@ -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] = true if ARGV.delete("--all")
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
+ --all Show all styles (default, only commented styles)
19
+ --syntax [name] Either sass or scss (default)
20
+
21
+ TEXT
22
+ exit -1
23
+ end
@@ -0,0 +1,23 @@
1
+ $: << File.dirname(__FILE__) + "/lib"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "css-annotated"
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 "haml", "~>3.0"
23
+ 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,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: css-annotated
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.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: haml
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ version: "3.0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: Uses in-line docs to map the stylesheet. Supports CSS and SCSS.
37
+ email: assaf@labnotes.org
38
+ executables:
39
+ - css-annotate
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - README.rdoc
44
+ - CHANGELOG
45
+ files:
46
+ - bin/css-annotate
47
+ - lib/css/annotate/style.scss
48
+ - lib/css/annotate/template.erb
49
+ - lib/css/annotate.rb
50
+ - lib/css-annotate.rb
51
+ - CHANGELOG
52
+ - VERSION
53
+ - MIT-LICENSE
54
+ - README.rdoc
55
+ - Rakefile
56
+ - Gemfile
57
+ - css-annotated.gemspec
58
+ has_rdoc: true
59
+ homepage: http://github.com/assaf/css-annotated
60
+ licenses: []
61
+
62
+ post_install_message: To get started, run the command css-annotate
63
+ rdoc_options:
64
+ - --title
65
+ - css-annotated 0.1.0
66
+ - --main
67
+ - README.rdoc
68
+ - --webcvs
69
+ - http://github.com/assaf/css-annotated
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 57
78
+ segments:
79
+ - 1
80
+ - 8
81
+ - 7
82
+ version: 1.8.7
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ requirements: []
93
+
94
+ rubyforge_project:
95
+ rubygems_version: 1.3.7
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: The Annotated CSS tells you which style to use where.
99
+ test_files: []
100
+