fleek 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 884b03aa70459e2e884df0bab9996bafe4d1d1f9
4
+ data.tar.gz: cb0c5cad5ca5e8511394e0a6342c84cfb43b626f
5
+ SHA512:
6
+ metadata.gz: 9479ddc8f413a79bb9555d864a0d06b72c0969add4347f9673e66d7e670ce3a1ae7dd2663d799025a9d646ac884a71a12cfef2d55a0cf2195e482e3ada933a01
7
+ data.tar.gz: c5cd7f8b0541cfa6373794193db4d496ee8fdc09cba3611846b628bdc11541763290ebb46c22b750f75768b78e93b4317461511e7eb4dc5c513df5355ef259de
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fleek.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # Fleek
2
+
3
+ Fleek makes sure your styles stay hot.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ group :development do
11
+ gem 'fleek'
12
+ end
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ ## Usage
20
+
21
+ Whenever you save a CSS file, fleek will recompile it in the background and update the page. Magic!
22
+
23
+ ## Contributing
24
+
25
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Shopify/fleek.
26
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fleek"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/fleek.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fleek/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fleek"
8
+ spec.version = Fleek::VERSION
9
+ spec.authors = ["Bouke van der Bijl"]
10
+ spec.email = ["bouke@shopify.com"]
11
+
12
+ spec.summary = %q{Fleek keeps your styles hot}
13
+ spec.description = %q{Fleek automatically injects any updates stylesheets when you change and save a file. This allows for faster iteration when working in CSS or any variant of it.}
14
+ spec.homepage = "https://github.com/Shopify/fleek"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'actioncable', '>= 5.0.0.beta3', '< 5.1'
22
+ spec.add_dependency 'actionview', '>= 5.0.0.beta3', '< 5.1'
23
+ spec.add_dependency 'listen', '~> 3.0.5'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.11"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest", "~> 5.0"
28
+ end
data/lib/fleek.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'fleek/version'
2
+ require 'fleek/connection'
3
+ require 'fleek/server'
4
+
5
+ module Fleek
6
+ end
7
+
8
+ require 'fleek/railtie' if defined?(Rails)
@@ -0,0 +1,32 @@
1
+ require 'action_cable'
2
+ require 'concurrent'
3
+
4
+ module Fleek
5
+ class Connection < ActionCable::Connection::Base
6
+ attr_reader :assets
7
+
8
+ delegate :helpers, to: :server
9
+
10
+ def initialize(*args)
11
+ super
12
+ @assets = Concurrent::Array.new
13
+ end
14
+
15
+ def receive(message)
16
+ data = ActiveSupport::JSON.decode(message)
17
+ if data['identifier'] == 'register_assets'
18
+ assets.push(*data['assets'])
19
+ end
20
+ end
21
+
22
+ def check_assets
23
+ assets.each do |asset|
24
+ transmit({
25
+ identifier: 'asset_updated',
26
+ asset: asset,
27
+ new_url: helpers.path_to_stylesheet(asset, debug: false)
28
+ }.to_json)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ module Fleek
2
+ class Helpers < ActionView::Base
3
+ def initialize(env)
4
+ @env = env
5
+ end
6
+
7
+ def assets_environment
8
+ @env
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails'
2
+ require 'fleek/server'
3
+ require 'fleek/style_injector'
4
+
5
+ module Fleek
6
+ class Railtie < Rails::Engine
7
+ config.after_initialize do |app|
8
+ app.routes.prepend do
9
+ mount Fleek::Server.new(app.assets) => '/.fleek-connection', internal: true
10
+ end
11
+
12
+ ActiveSupport.on_load(:action_view) do
13
+ include Fleek::StyleInjector
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,33 @@
1
+ require 'action_cable'
2
+ require 'fleek/server/configuration'
3
+ require 'fleek/helpers'
4
+
5
+ module Fleek
6
+ class Server < ActionCable::Server::Base
7
+ attr_reader :helpers
8
+
9
+ def initialize(env)
10
+ super()
11
+ @env = env
12
+ @helpers = Fleek::Helpers.new(env)
13
+ @listener = Listen.to(*@env.paths, latency: 0.1, wait_for_delay: 0.1) do |modified, added, removed|
14
+ rebuild
15
+ end
16
+ @listener.start
17
+ end
18
+
19
+ def self.config
20
+ Fleek::Server::Configuration
21
+ end
22
+
23
+ def config
24
+ self.class.config
25
+ end
26
+
27
+ def rebuild
28
+ connections.map do |connection|
29
+ connection.send_async(:check_assets)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,46 @@
1
+ require 'action_cable'
2
+ require 'fleek/connection'
3
+
4
+ module Fleek
5
+ class Server < ActionCable::Server::Base
6
+ class Configuration
7
+ class << self
8
+ def url
9
+ nil
10
+ end
11
+
12
+ def mount_path
13
+ '/.well-known/flee'
14
+ end
15
+
16
+ def logger
17
+ if defined?(::Rails)
18
+ ::Rails.logger
19
+ else
20
+ @_logger ||= Logger.new(STDERR)
21
+ end
22
+ end
23
+
24
+ def disable_request_forgery_protection
25
+ true
26
+ end
27
+
28
+ def connection_class
29
+ Fleek::Connection
30
+ end
31
+
32
+ def pubsub_adapter
33
+ ActionCable::SubscriptionAdapter::Inline
34
+ end
35
+
36
+ def worker_pool_size
37
+ 100
38
+ end
39
+
40
+ def log_tags
41
+ []
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,30 @@
1
+ module Fleek
2
+ module StyleInjector
3
+ def stylesheet_link_tag(*sources)
4
+ options = sources.extract_options!.stringify_keys
5
+ sources.map { |source|
6
+ options['original_source'] = source
7
+ options['debug'] = false
8
+ super source, options
9
+ }.join("\n").html_safe + javascript_tag do
10
+ <<-JS.html_safe
11
+ (function(){
12
+ var ws = new WebSocket((location.protocol === "https:" ? "wss:" : "ws:") + "//" + location.host + "/.fleek-connection");
13
+ ws.onopen = function() {
14
+ ws.send(JSON.stringify({
15
+ "identifier": "register_assets",
16
+ "assets": #{sources.to_json},
17
+ }));
18
+ };
19
+ ws.onmessage = function(event) {
20
+ var msg = JSON.parse(event.data);
21
+ if (msg.identifier == 'asset_updated') {
22
+ document.querySelector("link[original_source='" + msg.asset + "']").href = msg.new_url;
23
+ }
24
+ };
25
+ })();
26
+ JS
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Fleek
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fleek
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Bouke van der Bijl
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actioncable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.0.beta3
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 5.0.0.beta3
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: actionview
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 5.0.0.beta3
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '5.1'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 5.0.0.beta3
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '5.1'
53
+ - !ruby/object:Gem::Dependency
54
+ name: listen
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: 3.0.5
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: 3.0.5
67
+ - !ruby/object:Gem::Dependency
68
+ name: bundler
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '1.11'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '1.11'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rake
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '10.0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '10.0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: minitest
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '5.0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '5.0'
109
+ description: Fleek automatically injects any updates stylesheets when you change and
110
+ save a file. This allows for faster iteration when working in CSS or any variant
111
+ of it.
112
+ email:
113
+ - bouke@shopify.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - README.md
121
+ - Rakefile
122
+ - bin/console
123
+ - bin/setup
124
+ - fleek.gemspec
125
+ - lib/fleek.rb
126
+ - lib/fleek/connection.rb
127
+ - lib/fleek/helpers.rb
128
+ - lib/fleek/railtie.rb
129
+ - lib/fleek/server.rb
130
+ - lib/fleek/server/configuration.rb
131
+ - lib/fleek/style_injector.rb
132
+ - lib/fleek/version.rb
133
+ homepage: https://github.com/Shopify/fleek
134
+ licenses: []
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.4.5
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Fleek keeps your styles hot
156
+ test_files: []