remote-sass 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -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,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Joe Ellis
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.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Remote::Sass
2
+
3
+ RemoteSass is a small gem that allows Sass to import remote sass/scss stylsheets over HTTP/S. With this, you can set up a central server to serve your stylesheet assets and share css among your many applications.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'remote-sass'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install remote-sass
18
+
19
+ ## Usage
20
+
21
+ You'll need a couple of things for this to work:
22
+
23
+ 1. You need a remote server capable of serving sass/scss assets
24
+ 2. You need to tell RemoteSass where that server is located (preferably somewhere in an initializer file before your app starts up), ex:
25
+
26
+ RemoteSass.location = "http://remote-server.com/path/to/assets/"
27
+
28
+ From this, RemoteSass will add your remote server as the last part of Sass's lookup path. When importing, Sass will initially look for the file at the filesystem level first; if it finds the file, no extra connection is made. If it fails to find a matching file, it will try to make a remote connnection to your defined server to find the file.
29
+
30
+ Example:
31
+
32
+ @import "css/colors";
33
+
34
+ Sass will first try locally find a sass/scss file at "css/colors". Failing this, it will look to RemoteSass to connect and import from http://remote-server.com/css/colors". Be aware of this look up order in case Sass doesn't seem to be loading the file you want.
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,15 @@
1
+ require "remote-sass/version"
2
+ require "remote-sass/importer"
3
+
4
+ module RemoteSass
5
+ class << self
6
+ def location
7
+ @location
8
+ end
9
+
10
+ def location= location
11
+ @location = location
12
+ Sass.load_paths << Sass::Importers::HTTP.new(location)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,105 @@
1
+ require 'sass'
2
+ require 'net/http'
3
+ require 'time'
4
+
5
+ module Sass
6
+ module Importers
7
+ class HTTP < Base
8
+ def initialize root
9
+ @root = URI.parse root
10
+
11
+ unless scheme_allowed? @root
12
+ raise ArgumentError, "Absolute HTTP URIs only"
13
+ end
14
+ end
15
+
16
+ def find_relative uri, base, options
17
+ _find @root + base + uri, options
18
+ end
19
+
20
+ def find uri, options
21
+ _find @root + uri, options
22
+ end
23
+
24
+ def mtime uri, options
25
+ uri = URI.parse uri
26
+ return unless scheme_allowed? uri
27
+ Net::HTTP.start(uri.host, uri.port) do |http|
28
+ response = http.head uri.request_uri
29
+
30
+ if response.is_a?(Net::HTTPOK) && response['Last-Modified']
31
+ Time.parse response['Last-Modified']
32
+ elsif response.is_a? Net::HTTPOK
33
+ # we must assume that it just changed
34
+ Time.now
35
+ else
36
+ nil
37
+ end
38
+ end
39
+ end
40
+
41
+ def key(uri, options)
42
+ [self.class.name, uri]
43
+ end
44
+
45
+ def to_s
46
+ @root.to_s
47
+ end
48
+
49
+ protected
50
+
51
+ def extensions
52
+ {'.sass' => :sass, '.scss' => :scss}
53
+ end
54
+
55
+ private
56
+
57
+ def scheme_allowed? uri
58
+ uri.absolute? && (uri.scheme == 'http' || uri.scheme == 'https')
59
+ end
60
+
61
+ def exists? uri
62
+ Net::HTTP.start(uri.host, uri.port) do |http|
63
+ http.head(uri.request_uri).is_a? Net::HTTPOK
64
+ end
65
+ end
66
+
67
+ def get_syntax uri
68
+ # determine the syntax being used
69
+ ext = File.extname uri.path
70
+ syntax = extensions[ext]
71
+
72
+ # this must not be the full path: try another
73
+ if syntax.nil?
74
+ ext, syntax = extensions.find do |possible_ext, possible_syntax|
75
+ new_uri = uri.dup
76
+ new_uri.path += possible_ext
77
+ exists? new_uri
78
+ end
79
+ return if syntax.nil?
80
+ uri.path += ext
81
+ end
82
+ syntax
83
+ end
84
+
85
+ def _find uri, options
86
+ raise ArgumentError, "Absolute HTTP URIs only" unless scheme_allowed? uri
87
+
88
+ syntax = get_syntax uri
89
+
90
+ # fetch the content
91
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
92
+ response = http.get uri.request_uri
93
+ response.value
94
+
95
+ options[:importer] = self
96
+ options[:filename] = uri.to_s
97
+ options[:syntax] = syntax
98
+ Sass::Engine.new response.body, options
99
+ end
100
+ # rescue
101
+ # nil
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,5 @@
1
+ module Remote
2
+ module Sass
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'remote-sass/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "remote-sass"
8
+ gem.version = Remote::Sass::VERSION
9
+ gem.authors = ["Joe Ellis"]
10
+ gem.email = ["joe@joeellis.la"]
11
+ gem.description = "Import remote stylesheets with Sass."
12
+ gem.summary = "Allows the ability to fetch remote SASS/SCSS stylesheets over http(s)"
13
+ gem.homepage = "https://github.com/joeellis/remote-sass"
14
+
15
+ gem.files = `git ls-files`.split "\n"
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.required_ruby_version = ">= 1.9.2"
20
+ gem.add_runtime_dependency "sass", "~> 3.2"
21
+ gem.add_development_dependency "rspec", "~> 2.8"
22
+ end
@@ -0,0 +1,62 @@
1
+ require 'remote-sass'
2
+ require 'ostruct'
3
+
4
+ describe RemoteSass do
5
+ it "can define a server location" do
6
+ RemoteSass.location = "http://example.com"
7
+ RemoteSass.location.should == "http://example.com"
8
+ end
9
+ end
10
+
11
+ describe "Sass Importer" do
12
+ before do
13
+ @importer = Sass::Importers::HTTP.new "http://example.com"
14
+ end
15
+
16
+ it "can return a unique key for Sass caching purposes" do
17
+ # http://sass-lang.com/docs/yardoc/Sass/Importers/Base.html#key-instance_method
18
+
19
+ @importer.key("http://example.com", {}).should == ["Sass::Importers::HTTP", "http://example.com"]
20
+ end
21
+
22
+ it "can make a remote connection for absolute urls" do
23
+ uri = URI.parse "http://example.com/style.scss"
24
+ http = mock :http
25
+ options = { importer: @importer, filename: uri.to_s, syntax: :scss }
26
+ response = OpenStruct.new :body => "scss code"
27
+
28
+ Net::HTTP.should_receive(:start).with(uri.host, uri.port, :use_ssl => false).and_yield http
29
+ http.should_receive(:get).and_return response
30
+ Sass::Engine.should_receive(:new).with response.body, options
31
+
32
+ @importer.send :_find, uri, {}
33
+ end
34
+
35
+ it "can make a remote connection for absolute https urls" do
36
+ Net::HTTP.should_receive :start
37
+
38
+ @importer.send :_find, URI.parse("https://example.com/style.scss"), {}
39
+ end
40
+
41
+ it "should raise any error when connecting with other protocols" do
42
+ lambda {
43
+ @importer.send :_find, URI.parse("ftp://example.com/style.scss"), {}
44
+ }.should raise_error(ArgumentError)
45
+ end
46
+
47
+ it "should raise any error unless given an absolute url" do
48
+ lambda {
49
+ @importer.send :_find, URI.parse("www.example.com/style.scss"), {}
50
+ }.should raise_error(ArgumentError)
51
+ end
52
+
53
+ it "can figure out the correct syntax for a given url" do
54
+ @importer.send(:get_syntax, URI.parse("http://example.com/css/style.scss")).should == :scss
55
+ @importer.send(:get_syntax, URI.parse("http://example.com/css/style.sass")).should == :sass
56
+ end
57
+
58
+ it "can figure the correct syntax for a given url even if the extension is left off" do
59
+ @importer.should_receive(:exists?).and_return true
60
+ @importer.send(:get_syntax, URI.parse("http://example.com/css/style")).should == :sass
61
+ end
62
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: remote-sass
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Joe Ellis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-24 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sass
16
+ requirement: &70108778713980 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70108778713980
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70108778713520 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '2.8'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70108778713520
36
+ description: Import remote stylesheets with Sass.
37
+ email:
38
+ - joe@joeellis.la
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .DS_Store
44
+ - .gitignore
45
+ - Gemfile
46
+ - LICENSE.txt
47
+ - README.md
48
+ - Rakefile
49
+ - lib/.DS_Store
50
+ - lib/remote-sass.rb
51
+ - lib/remote-sass/importer.rb
52
+ - lib/remote-sass/version.rb
53
+ - remote-sass.gemspec
54
+ - spec/remote-sass-spec.rb
55
+ homepage: https://github.com/joeellis/remote-sass
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: 1.9.2
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.10
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Allows the ability to fetch remote SASS/SCSS stylesheets over http(s)
79
+ test_files:
80
+ - spec/remote-sass-spec.rb