visionmedia-css 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+
2
+ === 0.0.2 / 2008-12-12
3
+
4
+ * Forgot the commander gem dependency :)
5
+
6
+ === 0.0.1 / 2008-12-12
7
+
8
+ * Initial release
@@ -0,0 +1,17 @@
1
+ bin/css
2
+ History.rdoc
3
+ lib/css/version.rb
4
+ lib/css/watcher.rb
5
+ lib/css.rb
6
+ Manifest
7
+ Rakefile
8
+ README.rdoc
9
+ spec/css_spec.rb
10
+ spec/fixtures/style.css
11
+ spec/spec_helper.rb
12
+ tasks/docs.rake
13
+ tasks/gemspec.rake
14
+ tasks/spec.rake
15
+ test/index.html
16
+ test/style.css
17
+ Todo.rdoc
@@ -0,0 +1,50 @@
1
+
2
+ = CSS
3
+
4
+ Stylesheet task automation such as realtime editing.
5
+
6
+ == Examples:
7
+
8
+ Currently the only feature provided by the css rubygem is to monitor
9
+ changes made to a file, refresh browser(s) specified, while keeping
10
+ your text editor in focus. To do this simply invoke the 'css' command
11
+ like so:
12
+
13
+ $ css watch path/to/style.css
14
+
15
+ $ css watch path/to/style.css --browsers safari,firefox,opera --interval 10
16
+
17
+ Keep in mind if you are going to watch several browsers at one time,
18
+ you better have extra monitors :). The only requirement in your stylesheet file is to
19
+ have a watch url such as below which can be placed anywhere in the document:
20
+
21
+ /* watch: file:///Users/tjholowaychuk/Scripts/gems/css/test/index.html */
22
+
23
+ == Known Issues:
24
+
25
+ * Mac OS only, sorry windowz ;)
26
+
27
+ == License:
28
+
29
+ (The MIT License)
30
+
31
+ Copyright (c) 2008 TJ Holowaychuk
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining
34
+ a copy of this software and associated documentation files (the
35
+ 'Software'), to deal in the Software without restriction, including
36
+ without limitation the rights to use, copy, modify, merge, publish,
37
+ distribute, sublicense, an d/or sell copies of the Software, and to
38
+ permit persons to whom the Software is furnished to do so, subject to
39
+ the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be
42
+ included in all copies or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
45
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
46
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
47
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
48
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
49
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
50
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,12 @@
1
+
2
+ %w( rubygems rake echoe ./lib/css.rb ).each { |lib| require lib }
3
+
4
+ Echoe.new("css", CSS::VERSION::STRING) do |p|
5
+ p.author = "TJ Holowaychuk"
6
+ p.email = "tj@vision-media.ca"
7
+ p.summary = "Stylesheet task automation such as realtime editing"
8
+ p.url = "http://github.com/visionmedia/css"
9
+ p.runtime_dependencies = ["visionmedia-commander >=2.1.1"]
10
+ end
11
+
12
+ Dir['tasks/**/*.rake'].sort.each { |lib| load lib }
@@ -0,0 +1,12 @@
1
+
2
+ == Major:
3
+
4
+ * Nothing
5
+
6
+ == Minor:
7
+
8
+ * Nothing
9
+
10
+ == Brainstorming:
11
+
12
+ * Nothing
data/bin/css ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'commander'
5
+ require 'css'
6
+
7
+ program :name, 'css'
8
+ program :version, CSS::VERSION::STRING
9
+ program :description, 'Stylesheet task automation such as realtime editing.'
10
+
11
+ command :watch do |c|
12
+ c.syntax = 'css watch <file>'
13
+ c.summary = 'Watch a stylesheet for changes, auto-refreshing browsers'
14
+ c.description = 'Watch a stylesheet for changes, auto-refreshing browsers specified by the --browsers option'
15
+ c.example 'Watch a stylesheet with Safari and Firefox', 'css watch style.css --browsers safari,firefox'
16
+ c.option '--browsers BROWSERS', Array, 'Specify the browsers to watch, defaults to Safari'
17
+ c.option '--interval SECONDS', Integer, 'Interval in seconds for checking the modification time of the stylesheet watched. Defaults to 2'
18
+ c.option '--debug', 'Run in debug mode'
19
+ c.when_called do |args, options|
20
+ include CSS::Watcher
21
+ raise 'Stylesheet required' if args.empty?
22
+ raise '%s is not a valid stylesheet' % args.first unless File.file?(args.first)
23
+ stylesheet = args.first
24
+ interval = options.interval || 2
25
+ browsers = options.browsers || ['safari']
26
+ say '... Watching %s for modifications every %s seconds' % [stylesheet, interval]
27
+ say '... Press CTRL + C to terminate process'
28
+ url = get_url_from_stylesheet stylesheet
29
+ log 'url', url if options.debug
30
+ loop do
31
+ if stylesheet_has_changed? stylesheet
32
+ log 'refresh', browsers.join(', ') if options.debug
33
+ refresh_browsers_to_url browsers, url
34
+ end
35
+ sleep interval
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{css}
5
+ s.version = "0.0.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["TJ Holowaychuk"]
9
+ s.date = %q{2008-12-12}
10
+ s.default_executable = %q{css}
11
+ s.description = %q{Stylesheet task automation such as realtime editing}
12
+ s.email = %q{tj@vision-media.ca}
13
+ s.executables = ["css"]
14
+ s.extra_rdoc_files = ["bin/css", "lib/css/version.rb", "lib/css/watcher.rb", "lib/css.rb", "README.rdoc", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
15
+ s.files = ["bin/css", "History.rdoc", "lib/css/version.rb", "lib/css/watcher.rb", "lib/css.rb", "Manifest", "Rakefile", "README.rdoc", "spec/css_spec.rb", "spec/fixtures/style.css", "spec/spec_helper.rb", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake", "test/index.html", "test/style.css", "Todo.rdoc", "css.gemspec"]
16
+ s.has_rdoc = true
17
+ s.homepage = %q{http://github.com/visionmedia/css}
18
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Css", "--main", "README.rdoc"]
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{css}
21
+ s.rubygems_version = %q{1.3.1}
22
+ s.summary = %q{Stylesheet task automation such as realtime editing}
23
+
24
+ if s.respond_to? :specification_version then
25
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
+ s.specification_version = 2
27
+
28
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
29
+ s.add_runtime_dependency(%q<visionmedia-commander>, [">= 2.1.1"])
30
+ s.add_development_dependency(%q<echoe>, [">= 0"])
31
+ else
32
+ s.add_dependency(%q<visionmedia-commander>, [">= 2.1.1"])
33
+ s.add_dependency(%q<echoe>, [">= 0"])
34
+ end
35
+ else
36
+ s.add_dependency(%q<visionmedia-commander>, [">= 2.1.1"])
37
+ s.add_dependency(%q<echoe>, [">= 0"])
38
+ end
39
+ end
@@ -0,0 +1,27 @@
1
+ #--
2
+ # Copyright (c) 2008 TJ Holowaychuk
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ $:.unshift File.dirname(__FILE__)
25
+
26
+ require 'css/version'
27
+ require 'css/watcher'
@@ -0,0 +1,7 @@
1
+
2
+ module CSS
3
+ module VERSION #:nodoc:
4
+ MAJOR, MINOR, TINY = [0, 0, 2]
5
+ STRING = [MAJOR, MINOR, TINY].join '.'
6
+ end
7
+ end
@@ -0,0 +1,53 @@
1
+
2
+ module CSS
3
+
4
+ ##
5
+ # = Watcher
6
+ #
7
+ # The stylesheet watcher is in charge of monitoring
8
+ # modifications made to a specific stylesheet, then refreshing
9
+ # browsers appropriately while keeping your text editor in focus.
10
+
11
+ module Watcher
12
+
13
+ class Error < StandardError; end
14
+ class NoWatchURLError < StandardError; end
15
+
16
+ ##
17
+ # When the stylesheet was last checked for modifications.
18
+
19
+ @@last_checked = 0
20
+
21
+ module_function
22
+
23
+ ##
24
+ # Parse url from _file_. This should be in the format
25
+ # of /* watch: http://example.com/path/ */ which is then
26
+ # used as the page to refresh to.
27
+
28
+ def get_url_from_stylesheet file
29
+ url = $1.strip if File.read(file).match /watch: +((https?|file):\/\/.*?)\*\//i
30
+ raise NoWatchURLError, "No '/* watch: url */' found in #{file}" if url.nil?
31
+ url
32
+ end
33
+
34
+ ##
35
+ # Refresh all _browsers_ to the specified _url_.
36
+
37
+ def refresh_browsers_to_url browsers, url
38
+ browsers.each do |browser|
39
+ system 'open -a %s %s --background' % [browser, url]
40
+ end
41
+ end
42
+
43
+ ##
44
+ # Check if a stylesheet has been modified within the
45
+ # last interval checked.
46
+
47
+ def stylesheet_has_changed? file
48
+ status = File.new(file).mtime.to_i > @@last_checked
49
+ @@last_checked = Time.now.to_i
50
+ status
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,11 @@
1
+
2
+ describe "Watcher" do
3
+ it "should parse watch: url from a file" do
4
+ url = CSS::Watcher.get_url_from_stylesheet File.dirname(__FILE__) + '/fixtures/style.css'
5
+ url.should eql('http://example.com/whatever/something.ext')
6
+ end
7
+
8
+ it "should raise an error when no watch url is found" do
9
+ lambda { CSS::Watcher.get_url_from_stylesheet __FILE__ }.should raise_error(CSS::Watcher::NoWatchURLError)
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+
2
+ /* watch: http://example.com/whatever/something.ext */
3
+
4
+ body {
5
+ /* lame */
6
+ }
@@ -0,0 +1,2 @@
1
+
2
+ require 'css'
@@ -0,0 +1,13 @@
1
+
2
+ namespace :docs do
3
+
4
+ desc 'Remove rdoc products'
5
+ task :remove => [:clobber_docs]
6
+
7
+ desc 'Build docs, and open in browser for viewing (specify BROWSER)'
8
+ task :open => [:docs] do
9
+ browser = ENV["BROWSER"] || "safari"
10
+ sh "open -a #{browser} doc/index.html"
11
+ end
12
+
13
+ end
@@ -0,0 +1,3 @@
1
+
2
+ desc 'Build gemspec file'
3
+ task :gemspec => [:build_gemspec]
@@ -0,0 +1,25 @@
1
+
2
+ require 'spec/rake/spectask'
3
+
4
+ desc "Run all specifications"
5
+ Spec::Rake::SpecTask.new(:spec) do |t|
6
+ t.libs << "lib"
7
+ t.spec_opts = ["--color", "--require", "spec/spec_helper.rb"]
8
+ end
9
+
10
+ namespace :spec do
11
+
12
+ desc "Run all specifications verbosely"
13
+ Spec::Rake::SpecTask.new(:verbose) do |t|
14
+ t.libs << "lib"
15
+ t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
16
+ end
17
+
18
+ desc "Run specific specification verbosely (specify SPEC)"
19
+ Spec::Rake::SpecTask.new(:select) do |t|
20
+ t.libs << "lib"
21
+ t.spec_files = [ENV["SPEC"]]
22
+ t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
23
+ end
24
+
25
+ end
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml">
4
+ <head>
5
+ <title>CSS Watcher Test</title>
6
+ <link rel="stylesheet" href="style.css" type="text/css" media="screen" charset="utf-8" />
7
+ </head>
8
+ <body>
9
+ <div id="content">
10
+ <h1>Heading</h1>
11
+ <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in repreest laborum.</p>
12
+ <h2>Heading 2</h2>
13
+ <p class="double">Sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute ir</p>
14
+ <p class="double">Sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute ir</p>
15
+ <div class="clear"></div>
16
+ </div>
17
+ </body>
18
+ </html>
@@ -0,0 +1,50 @@
1
+
2
+ /* watch: file:///Users/tjholowaychuk/Scripts/gems/css/test/index.html */
3
+
4
+ body {
5
+ margin: 30px;
6
+ font: 12px "Arial";
7
+ color: #888;
8
+ }
9
+ h1, h2, h3 {
10
+ margin-top: 35px;
11
+ font: 30px "Lucida Grande";
12
+ font-weight: normal;
13
+ color: #000;
14
+ text-shadow: 1px 1px 2px #C4C4C4;
15
+ -webkit-transition-properties: color;
16
+ -webkit-transition-duration: 0.3s;
17
+ -webkit-transition-timing-function: ease-in-out;
18
+ }
19
+ h1:hover, h2:hover, h3:hover {
20
+ color: red;
21
+ }
22
+ h2 {
23
+ font-size: 20px;
24
+ }
25
+ p {
26
+ line-height: 1.5;
27
+ width: 40%;
28
+ -webkit-transition-properties: color, padding, -webkit-transform;
29
+ -webkit-transition-duration: 0.3s;
30
+ -webkit-transition-timing-function: ease-in-out;
31
+ }
32
+ p:hover {
33
+ padding: 10px 25px;
34
+ color: #000;
35
+ -webkit-transform: rotate(360deg) scale(1.2);
36
+ }
37
+ p.double {
38
+ float: left;
39
+ padding-right: 20px;
40
+ width: 19%;
41
+ font-size: 11px;
42
+ }
43
+ .clear {
44
+ display: block;
45
+ clear: both;
46
+ }
47
+ #content {
48
+ padding: 0 25px 20px 25px;
49
+ border: 1px solid #eee;
50
+ }
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: visionmedia-css
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - TJ Holowaychuk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-12 00:00:00 -08:00
13
+ default_executable: css
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: visionmedia-commander
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.1.1
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: echoe
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "0"
32
+ version:
33
+ description: Stylesheet task automation such as realtime editing
34
+ email: tj@vision-media.ca
35
+ executables:
36
+ - css
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - bin/css
41
+ - lib/css/version.rb
42
+ - lib/css/watcher.rb
43
+ - lib/css.rb
44
+ - README.rdoc
45
+ - tasks/docs.rake
46
+ - tasks/gemspec.rake
47
+ - tasks/spec.rake
48
+ files:
49
+ - bin/css
50
+ - History.rdoc
51
+ - lib/css/version.rb
52
+ - lib/css/watcher.rb
53
+ - lib/css.rb
54
+ - Manifest
55
+ - Rakefile
56
+ - README.rdoc
57
+ - spec/css_spec.rb
58
+ - spec/fixtures/style.css
59
+ - spec/spec_helper.rb
60
+ - tasks/docs.rake
61
+ - tasks/gemspec.rake
62
+ - tasks/spec.rake
63
+ - test/index.html
64
+ - test/style.css
65
+ - Todo.rdoc
66
+ - css.gemspec
67
+ has_rdoc: true
68
+ homepage: http://github.com/visionmedia/css
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --line-numbers
72
+ - --inline-source
73
+ - --title
74
+ - Css
75
+ - --main
76
+ - README.rdoc
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "1.2"
90
+ version:
91
+ requirements: []
92
+
93
+ rubyforge_project: css
94
+ rubygems_version: 1.2.0
95
+ signing_key:
96
+ specification_version: 2
97
+ summary: Stylesheet task automation such as realtime editing
98
+ test_files: []
99
+