css-annotate 1.3.0 → 2.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 +11 -0
- data/README.rdoc +27 -2
- data/VERSION +1 -1
- data/bin/css-annotate +15 -14
- data/css-annotate.gemspec +0 -1
- data/lib/css/annotate.rb +42 -18
- data/lib/css/annotate/style.scss +11 -2
- data/lib/css/annotate/template.erb +19 -18
- metadata +10 -25
data/CHANGELOG
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
2010-11-21 version 2.0.0
|
2
|
+
|
3
|
+
Rack support! Mount css-annotate in your Web app to serve annotated
|
4
|
+
CSS/SCSS/SASS along the originals. See README for examples.
|
5
|
+
|
6
|
+
|
7
|
+
If no commented styles, show all styles by default.
|
8
|
+
|
9
|
+
Remove dependency on Compass, but absolutely use Compass when installed.
|
10
|
+
|
11
|
+
|
1
12
|
2010-11-18 version 1.3.0
|
2
13
|
|
3
14
|
By default only show commented styles (the ones that matter).
|
data/README.rdoc
CHANGED
@@ -9,9 +9,34 @@
|
|
9
9
|
-s --server Run a Web server
|
10
10
|
--syntax [name] Either sass or scss (default)
|
11
11
|
|
12
|
-
|
12
|
+
CSS annotate single file and pipe to browser:
|
13
13
|
css-annotate lib/css/annotate/style.scss | bcat
|
14
|
-
|
14
|
+
|
15
|
+
Run as server on port 8080, annotate files in public/stylesheets:
|
16
|
+
css-annotate --server public/stylesheets
|
17
|
+
open http://localhost:8080/main.css
|
18
|
+
|
19
|
+
|
20
|
+
== Mount To Your App
|
21
|
+
|
22
|
+
You can mount css-annotate in your Web app (Rails 3.x, Padrino, etc) to serve
|
23
|
+
annotated versions of all CSS, SCSS and SASS files. For example, to mount all
|
24
|
+
files from public/stylesheets under the path /stylesheets/annotated:
|
25
|
+
|
26
|
+
mount CSS::Annotate.new=>"/stylesheets/annotated"
|
27
|
+
|
28
|
+
With yout browser, you can now access the CSS file /stylesheets/screen.css and
|
29
|
+
its annotated version from /stylesheets/annotated/screen.css.
|
30
|
+
|
31
|
+
To mount files from a different path, pass it as the sole argument to
|
32
|
+
CSS::Annotate. For example:
|
33
|
+
|
34
|
+
mount CSS::Annotate.new("app/views/stylesheets")=>"/stylesheets/annotated"
|
35
|
+
|
36
|
+
With your browser, you can now access the annotated SCSS file
|
37
|
+
/stylesheets/annotated/screen.scss. Note that both filename and extension must
|
38
|
+
match the file you want annotated.
|
39
|
+
|
15
40
|
|
16
41
|
== Screenshot
|
17
42
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.0
|
data/bin/css-annotate
CHANGED
@@ -18,21 +18,12 @@ end
|
|
18
18
|
if filename = ARGV[0]
|
19
19
|
if server
|
20
20
|
require "rack"
|
21
|
-
app = lambda do |env|
|
22
|
-
request = Rack::Request.new(env)
|
23
|
-
if request.path == "/"
|
24
|
-
html = CSS::Annotate.new(filename, options).to_html
|
25
|
-
[200, { "Content-Type"=>"text/html", "Content-Length"=>html.length.to_s }, [html]]
|
26
|
-
else
|
27
|
-
[404, {}, "Not found"]
|
28
|
-
end
|
29
|
-
end
|
30
21
|
trap(:INT) { exit! }
|
31
22
|
trap(:QUIT) { exit! }
|
32
23
|
server = Rack::Handler.default
|
33
|
-
server.run
|
24
|
+
server.run CSS::Annotate.new(filename), :Host=>"127.0.0.1", :Port=>port || 8080
|
34
25
|
else
|
35
|
-
$stdout << CSS::Annotate.new(
|
26
|
+
$stdout << CSS::Annotate.new(options).to_html(filename)
|
36
27
|
end
|
37
28
|
else
|
38
29
|
print <<-TEXT
|
@@ -45,9 +36,19 @@ Options:
|
|
45
36
|
-s --server Run a Web server
|
46
37
|
--syntax [name] Either sass or scss (default)
|
47
38
|
|
48
|
-
|
49
|
-
css-annotate lib/css/annotate/style.scss | bcat
|
50
|
-
|
39
|
+
CSS annotate single file and pipe to browser:
|
40
|
+
$ css-annotate lib/css/annotate/style.scss | bcat
|
41
|
+
|
42
|
+
Run as server on port 8080, annotate files in public/stylesheets:
|
43
|
+
$ css-annotate --server public/stylesheets
|
44
|
+
$ open http://localhost:8080/main.css
|
45
|
+
|
46
|
+
Mount to your Web app, annotate all files in app/view/stylesheets, access them
|
47
|
+
from /stylesheets/annotated:
|
48
|
+
Application.routes.draw do
|
49
|
+
mount CSS::Annotate.new("app/views/stylesheets")=>"/stylesheets/annotated"
|
50
|
+
end
|
51
|
+
$ open http://localhost:3000/stylesheets/annotated/screen.scss
|
51
52
|
|
52
53
|
TEXT
|
53
54
|
exit -1
|
data/css-annotate.gemspec
CHANGED
data/lib/css/annotate.rb
CHANGED
@@ -1,52 +1,76 @@
|
|
1
1
|
require "haml"
|
2
2
|
require "sass/engine"
|
3
|
-
require "compass"
|
4
3
|
require "erb"
|
5
4
|
require "cgi"
|
5
|
+
require "rack"
|
6
6
|
|
7
7
|
module CSS
|
8
8
|
class Annotate
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
# @param [Hash, String, nil] options Hash with options, just the path, or
|
11
|
+
# nil
|
12
|
+
# @options options [String] path Path to your CSS/SCSS/SASS source files
|
13
|
+
# @options options [Array<String>] load_paths Additional paths for loading
|
14
|
+
# CSS files
|
15
|
+
# @options options [Boolean] all If nil, true show all styles (with buttons to
|
16
|
+
# show only commented); if false show only commented styles.
|
17
|
+
def initialize(options = nil)
|
18
|
+
@options = String === options ? { :path=>options } : options ? options.clone : {}
|
19
|
+
@options[:path] ||= "public/stylesheets/"
|
20
|
+
paths =[@options[:path]]
|
21
|
+
paths.concat Compass::Frameworks::ALL.map { |framework| framework.stylesheets_directory } if defined?(Compass)
|
16
22
|
@options[:load_paths] = paths
|
17
|
-
@options[:
|
23
|
+
@options[:all] = true unless @options.has_key?(:all)
|
18
24
|
end
|
19
25
|
|
20
|
-
attr_reader :
|
26
|
+
attr_reader :options, :rows
|
21
27
|
|
22
|
-
|
23
|
-
|
28
|
+
# Annotate the named file. Sets and returns rows.
|
29
|
+
def annotate(filename)
|
30
|
+
engine = Sass::Engine.new(IO.read(filename), options.merge(:syntax=>guess_syntax(filename)))
|
24
31
|
tree = engine.to_tree
|
25
32
|
tree.perform!(Sass::Environment.new)
|
26
33
|
resolve_rules tree
|
27
34
|
@rows = to_rows(tree)
|
28
35
|
end
|
29
36
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
def to_html
|
35
|
-
rows = annotate
|
37
|
+
# Annotate the named file, returns HTML document.
|
38
|
+
def to_html(filename)
|
39
|
+
rows = annotate(filename)
|
36
40
|
ERB.new(IO.read(File.dirname(__FILE__) + "/annotate/template.erb")).result(binding)
|
37
41
|
rescue Sass::SyntaxError=>error
|
38
42
|
error = Sass::SyntaxError.exception_to_css error, @options.merge(:full_exception=>true)
|
39
43
|
ERB.new(IO.read(File.dirname(__FILE__) + "/annotate/template.erb")).result(binding)
|
40
44
|
end
|
41
45
|
|
46
|
+
# ERB template uses this to HTML escape content.
|
47
|
+
def h(raw)
|
48
|
+
CGI.escapeHTML(raw.to_s)
|
49
|
+
end
|
50
|
+
|
51
|
+
# ERB template uses this to obtain our own stylesheet.
|
42
52
|
def styles
|
43
53
|
Sass::Engine.new(IO.read(File.dirname(__FILE__) + "/annotate/style.scss"), :syntax=>:scss).render
|
44
54
|
end
|
45
|
-
|
55
|
+
|
56
|
+
# EBB template uses this to determine if it should show all, or just
|
57
|
+
# commented, styles.
|
46
58
|
def all?
|
47
59
|
!!options[:all]
|
48
60
|
end
|
49
61
|
|
62
|
+
def call(env)
|
63
|
+
request = Rack::Request.new(env)
|
64
|
+
filename = request.path_info.split("/").last
|
65
|
+
filename = File.expand_path(filename, @options[:path]) if filename
|
66
|
+
if filename && File.exist?(filename)
|
67
|
+
html = to_html(filename)
|
68
|
+
[200, { "Content-Type"=>"text/html", "Content-Length"=>html.length.to_s }, [html]]
|
69
|
+
else
|
70
|
+
[404, { "Content-Type"=>"text/plain" }, ["Could not find '#{filename}'"]]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
50
74
|
protected
|
51
75
|
|
52
76
|
def resolve_rules(parent)
|
data/lib/css/annotate/style.scss
CHANGED
@@ -30,6 +30,15 @@ h3, h4, h5, h6 {
|
|
30
30
|
right: 1em;
|
31
31
|
top: 0.3em;
|
32
32
|
font-size: 90%;
|
33
|
+
a {
|
34
|
+
color: #261a3b;
|
35
|
+
text-decoration: none;
|
36
|
+
font-weight: bold;
|
37
|
+
background: #fff;
|
38
|
+
padding: 2px 6px;
|
39
|
+
-moz-border-radius: 4px;
|
40
|
+
-webkit-border-radius: 4px;
|
41
|
+
}
|
33
42
|
/* Link to show all rules */
|
34
43
|
[rel="show"] { display: none }
|
35
44
|
/* Link to show only commented rules */
|
@@ -71,7 +80,7 @@ table.annotated {
|
|
71
80
|
/* Apply to column that contains CSS style */
|
72
81
|
td.style {
|
73
82
|
width: 40em;
|
74
|
-
background: #
|
83
|
+
background: #f5f5ff;
|
75
84
|
vertical-align: top;
|
76
85
|
padding: 1em 1em 1em 2em;
|
77
86
|
border-left: 1px solid #ccc;
|
@@ -80,7 +89,7 @@ table.annotated {
|
|
80
89
|
}
|
81
90
|
|
82
91
|
&:hover td {
|
83
|
-
background: #
|
92
|
+
background: #f5f5ff;
|
84
93
|
}
|
85
94
|
}
|
86
95
|
}
|
@@ -2,24 +2,6 @@
|
|
2
2
|
<head>
|
3
3
|
<title>Your CSS, annotated</title>
|
4
4
|
<style><%= styles %><%= error %></style>
|
5
|
-
<% if all? %>
|
6
|
-
<script type="text/javascript">
|
7
|
-
function toggle(show) {
|
8
|
-
var styles = document.styleSheets[0];
|
9
|
-
var rules = styles.cssRules || styles.rules;
|
10
|
-
for (var i in rules) {
|
11
|
-
var rule = rules[i];
|
12
|
-
if (rule.selectorText == "table.annotated tr")
|
13
|
-
rule.style.display = show ? "table-row" : "none";
|
14
|
-
if (rule.selectorText == ".toggle [rel=\"show\"]")
|
15
|
-
rule.style.display = show ? "none" : "inherit";
|
16
|
-
if (rule.selectorText == ".toggle [rel=\"hide\"]")
|
17
|
-
rule.style.display = show ? "inherit" : "none";
|
18
|
-
}
|
19
|
-
}
|
20
|
-
toggle(false);
|
21
|
-
</script>
|
22
|
-
<% end %>
|
23
5
|
</head>
|
24
6
|
<body>
|
25
7
|
<% if rows %>
|
@@ -45,5 +27,24 @@
|
|
45
27
|
Generated from <span class="filename"><%= filename %></span> on
|
46
28
|
<%= Time.now.strftime("%c") %> by <a href="http://github.com/assaf/css-annotate">CSS Annotate</a>
|
47
29
|
</div>
|
30
|
+
<% if all? %>
|
31
|
+
<script type="text/javascript">
|
32
|
+
function toggle(show) {
|
33
|
+
var styles = document.styleSheets[0];
|
34
|
+
var rules = styles.cssRules || styles.rules;
|
35
|
+
for (var i in rules) {
|
36
|
+
var rule = rules[i];
|
37
|
+
if (rule.selectorText == "table.annotated tr")
|
38
|
+
rule.style.display = show ? "table-row" : "none";
|
39
|
+
if (rule.selectorText == ".toggle [rel=\"show\"]")
|
40
|
+
rule.style.display = show ? "none" : "inherit";
|
41
|
+
if (rule.selectorText == ".toggle [rel=\"hide\"]")
|
42
|
+
rule.style.display = show ? "inherit" : "none";
|
43
|
+
}
|
44
|
+
}
|
45
|
+
var commented = document.getElementsByClassName("commented");
|
46
|
+
toggle(commented.length == 0);
|
47
|
+
</script>
|
48
|
+
<% end %>
|
48
49
|
</body>
|
49
50
|
</html>
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: css-annotate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
|
-
-
|
8
|
-
- 3
|
7
|
+
- 2
|
9
8
|
- 0
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 2.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Assaf Arkin
|
@@ -15,28 +15,13 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-21 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
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
21
|
- !ruby/object:Gem::Dependency
|
37
22
|
name: haml
|
38
23
|
prerelease: false
|
39
|
-
requirement: &
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
40
25
|
none: false
|
41
26
|
requirements:
|
42
27
|
- - ~>
|
@@ -47,11 +32,11 @@ dependencies:
|
|
47
32
|
- 0
|
48
33
|
version: "3.0"
|
49
34
|
type: :runtime
|
50
|
-
version_requirements: *
|
35
|
+
version_requirements: *id001
|
51
36
|
- !ruby/object:Gem::Dependency
|
52
37
|
name: rack
|
53
38
|
prerelease: false
|
54
|
-
requirement: &
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
55
40
|
none: false
|
56
41
|
requirements:
|
57
42
|
- - ~>
|
@@ -62,7 +47,7 @@ dependencies:
|
|
62
47
|
- 1
|
63
48
|
version: "1.1"
|
64
49
|
type: :runtime
|
65
|
-
version_requirements: *
|
50
|
+
version_requirements: *id002
|
66
51
|
description: Uses in-line docs to map the stylesheet. Supports CSS and SCSS.
|
67
52
|
email: assaf@labnotes.org
|
68
53
|
executables:
|
@@ -92,7 +77,7 @@ licenses: []
|
|
92
77
|
post_install_message: To get started, run the command css-annotate
|
93
78
|
rdoc_options:
|
94
79
|
- --title
|
95
|
-
- css-annotate
|
80
|
+
- css-annotate 2.0.0
|
96
81
|
- --main
|
97
82
|
- README.rdoc
|
98
83
|
- --webcvs
|