magico 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in magico.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Michael Rykov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Magico
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'magico'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install magico
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'eventmachine'
4
+ require 'em-websocket'
5
+ require 'fssm'
6
+
7
+ root_path = File.expand_path(ARGV[0] || '.', Dir.pwd)
8
+
9
+ EM.run {
10
+ SKIP_PARTS = %w(erb scss)
11
+ ws_opts = { :host => "0.0.0.0", :port => 8787 }
12
+ @clients = []
13
+
14
+ EventMachine::WebSocket.start(ws_opts) do |ws|
15
+ ws.onopen { puts "Connection open"; @clients << ws }
16
+ ws.onclose { puts "Connection closed"; @clients.delete(ws) }
17
+ end
18
+
19
+ Thread.new do
20
+ onChange = lambda { |base, relative|
21
+ parts = File.basename(relative).split('.') - SKIP_PARTS
22
+ @clients.each { |ws| ws.send(parts.join('.')) }
23
+ }
24
+
25
+ FSSM.monitor(root_path, '**/*css*') do
26
+ update(&onChange)
27
+ create(&onChange)
28
+ end
29
+ end
30
+
31
+ puts "Magico is watching and waiting #{root_path}/..."
32
+ }
@@ -0,0 +1,9 @@
1
+ module Magico
2
+ require 'magico/version'
3
+
4
+ if ::Rails.version < "3.1"
5
+ raise StandardError, "Magico needs Rails 3.1 or later"
6
+ else
7
+ Engine = Class.new(::Rails::Engine)
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Magico
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/magico/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Michael Rykov"]
6
+ gem.email = ["michael@gemfury.com"]
7
+ gem.description = %q{Live stylesheet updates for Rails}
8
+ gem.summary = %q{Instantly autoupdate stylesheets}
9
+ gem.homepage = "https://www.github.com/gemfury/magico"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "magico"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Magico::VERSION
17
+
18
+ gem.add_runtime_dependency 'eventmachine', '>= 0.12.0'
19
+ gem.add_runtime_dependency 'em-websocket', '~> 0.3.0'
20
+ gem.add_runtime_dependency 'fssm', '~> 0.2.0'
21
+ end
@@ -0,0 +1,46 @@
1
+ /*globals console jQuery */
2
+
3
+ /* Magico: CSS Autorefresh server */
4
+
5
+ Magico = {
6
+ connect: function() {
7
+ var klass = window.WebSocket || window.MozWebSocket;
8
+ if(!klass) {
9
+ console.log('Magico is not compatible with your browser');
10
+ } else {
11
+ var socket = new klass('ws://localhost:8787/');
12
+ socket.onopen = function () {
13
+ console.log("Connected to Magico server!");
14
+ };
15
+
16
+ socket.onmessage = function(message) {
17
+ var files = message.data.split(','); // TODO: Use JSON
18
+ var filter = new RegExp("(" + files.join('|') + ")");
19
+ Magico.reloadStylesheets(filter);
20
+ };
21
+ }
22
+ },
23
+
24
+ reloadStylesheets: function(filter) {
25
+ var assetId = new Date().getTime();
26
+
27
+ if(!filter) {
28
+ console.log("Reloading styles @ " + assetId);
29
+ }
30
+
31
+ jQuery('link').each(function() {
32
+ var elem = $(this);
33
+ if(elem.attr('rel') === 'stylesheet') {
34
+ // Update the href with a new timestamp
35
+ var href = elem.attr('href');
36
+ if(!filter || href.match(filter)) {
37
+ elem.attr('href', href.replace(/\d+$/, assetId));
38
+ if(filter) console.log("Updated " + href);
39
+ }
40
+ }
41
+ });
42
+ }
43
+ };
44
+
45
+ /* Connect to Magico: CSS Autorefresh server */
46
+ Magico.connect();
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: magico
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Rykov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: eventmachine
16
+ requirement: &70223421332840 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.12.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70223421332840
25
+ - !ruby/object:Gem::Dependency
26
+ name: em-websocket
27
+ requirement: &70223421332340 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.3.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70223421332340
36
+ - !ruby/object:Gem::Dependency
37
+ name: fssm
38
+ requirement: &70223421331860 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.2.0
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70223421331860
47
+ description: Live stylesheet updates for Rails
48
+ email:
49
+ - michael@gemfury.com
50
+ executables:
51
+ - magico
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - Gemfile
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - bin/magico
61
+ - lib/magico.rb
62
+ - lib/magico/version.rb
63
+ - magico.gemspec
64
+ - vendor/assets/javascripts/magico.js
65
+ homepage: https://www.github.com/gemfury/magico
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.11
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Instantly autoupdate stylesheets
89
+ test_files: []