flatrack 1.3.3.alpha.1 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d46bc478b259257db2a9cec0249e7c5c03bfdf9f
4
- data.tar.gz: 722b1bdc2af56bc114fd6e9c5a1f64a09596cebc
3
+ metadata.gz: 4712856b901f1113021c85dcd49feb181318fbc5
4
+ data.tar.gz: 9234ce5891267c17e254b3953bb2219a4e4a2dfe
5
5
  SHA512:
6
- metadata.gz: 3385558c579aaf170cbcc8a3276719780b17628132a6904094664a355d4f88fdb75833a153618b72f2c55174dd19e33e2d4249816b4a4510cb608ebe0ff6b877
7
- data.tar.gz: 3633da3cffd350c0826aa4e41e3d6d76f19840191f236522353f12a71e9a7673c019eadce0606ecb7682bda905380ad56d2abf3f2c6ecac7bcba8ceeb53c3319
6
+ metadata.gz: 39da8a5e1fce769e1d847d74cbdeb8642d484650ffd5a533872ef56a442799ad7ffd1a7f8c24375487541967108ee5b0b7c13567664c59e7e8b3fac8c4d472af
7
+ data.tar.gz: ab7fcf8c901f5613006707a6c23432f8c6723e6ed7010300c55cf503bce952cb14554d3a7442e80e694b5ce5d8936ebd6630cf350fb942ffea7dba60ea3a642b
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.1
1
+ 2.1.3
data/.travis.yml CHANGED
@@ -2,7 +2,15 @@ language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
4
  - 2.1.1
5
+ - 2.1.2
6
+ - 2.1.2
7
+ - 2.2.0-preview1
5
8
  cache: bundler
6
9
  after_success:
7
10
  - bundle exec inch
8
- - bundle exec rubocop
11
+ - bundle exec rubocop
12
+
13
+ matrix:
14
+ fast_finish: true
15
+ allow_failures:
16
+ - rvm: 2.2.0-preview1
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Build Status](http://allthebadges.io/jwaldrip/flatrack/travis.png)](http://allthebadges.io/jwaldrip/flatrack/travis)
6
6
  [![Coverage Status](https://coveralls.io/repos/jwaldrip/flatrack/badge.png?branch=master)](https://coveralls.io/r/jwaldrip/flatrack?branch=master)
7
7
  [![Code Climate](http://allthebadges.io/jwaldrip/flatrack/code_climate.png)](http://allthebadges.io/jwaldrip/flatrack/code_climate)
8
- [![Inline docs](http://inch-pages.github.io/github/jwaldrip/flatrack.png)](http://inch-pages.github.io/github/jwaldrip/flatrack)
8
+ [![Inline docs](http://inch-ci.org/github/jwaldrip/flatrack.png)](http://inch-ci.org/github/jwaldrip/flatrack)
9
9
  [![Inline docs](http://img.shields.io/badge/github-follow-blue.png)](https://github.com/jwaldrip/flatrack)
10
10
 
11
11
  ## About
data/flatrack.gemspec CHANGED
@@ -34,14 +34,14 @@ based routing.
34
34
  spec.add_runtime_dependency 'tilt', '~> 1.1'
35
35
  spec.add_runtime_dependency 'activesupport', ['> 3.2', '< 4.2']
36
36
  spec.add_runtime_dependency 'sass', '~> 3.2.0'
37
- spec.add_runtime_dependency 'sprockets-sass', '~> 1.0'
37
+ spec.add_runtime_dependency 'sprockets-sass', '~> 1.2'
38
38
  spec.add_runtime_dependency 'thor', '~> 0.18'
39
39
  spec.add_runtime_dependency 'coffee-script', '~> 2.2'
40
40
  spec.add_runtime_dependency 'rake', ['> 0.8.7', '< 10.2']
41
41
 
42
42
  # Dev Dependencies
43
43
  spec.add_development_dependency 'bundler', '~> 1.5'
44
- spec.add_development_dependency 'rspec', '~> 2.14'
44
+ spec.add_development_dependency 'rspec', '~> 3.1'
45
45
  spec.add_development_dependency 'guard', '~> 2.5'
46
46
  spec.add_development_dependency 'guard-rspec', '~> 4.2'
47
47
  spec.add_development_dependency 'guard-bundler', '~> 2.0'
@@ -44,7 +44,7 @@ class Flatrack
44
44
  renderer = renderer_for_page(@file)
45
45
  content = renderer.render(view)
46
46
  @view = nil
47
- headers['Content-Type'] = FORMATS[renderer.format.to_sym]
47
+ headers['Content-Type'] = FORMATS[renderer.format.to_s]
48
48
  content
49
49
  end
50
50
 
@@ -0,0 +1,12 @@
1
+ require 'sass'
2
+
3
+ class Flatrack
4
+ module Sass
5
+ extend ActiveSupport::Autoload
6
+
7
+ autoload :SassTemplate
8
+ autoload :ScssTemplate
9
+ autoload :Importer
10
+
11
+ end
12
+ end
@@ -0,0 +1,163 @@
1
+ require 'sass'
2
+
3
+ class Flatrack
4
+ module Sass
5
+ module Functions
6
+ # Using Sprockets::Context#asset_data_uri return a Base64-encoded `data:`
7
+ # URI with the contents of the asset at the specified path.
8
+ #
9
+ # === Examples
10
+ #
11
+ # background: asset-data-uri("image.jpg"); // background: url(data:image/jpeg;base64,...);
12
+ #
13
+ def asset_data_uri(source)
14
+ ::Sass::Script::String.new "url(#{sprockets_context.asset_data_uri(source.value)})"
15
+ end
16
+
17
+ # Using Sprockets::Helpers#asset_path, return the full path
18
+ # for the given +source+ as a Sass String. This supports keyword
19
+ # arguments that mirror the +options+.
20
+ #
21
+ # === Examples
22
+ #
23
+ # background: url(asset-path("image.jpg")); // background: url("/assets/image.jpg");
24
+ # background: url(asset-path("image.jpg", $digest: true)); // background: url("/assets/image-27a8f1f96afd8d4c67a59eb9447f45bd.jpg");
25
+ #
26
+ def asset_path(source, options = {})
27
+ # Work with the Sass::Rails #asset_path API
28
+ if options.respond_to? :value
29
+ kind = options.value
30
+ options = {}
31
+ end
32
+
33
+ if kind && sprockets_context.respond_to?("#{kind}_path")
34
+ ::Sass::Script::String.new sprockets_context.send("#{kind}_path", source.value), :string
35
+ else
36
+ ::Sass::Script::String.new sprockets_context.asset_path(source.value, map_options(options)).to_s, :string
37
+ end
38
+ end
39
+
40
+ # Using Sprockets::Helpers#asset_path, return the url CSS
41
+ # for the given +source+ as a Sass String. This supports keyword
42
+ # arguments that mirror the +options+.
43
+ #
44
+ # === Examples
45
+ #
46
+ # background: asset-url("image.jpg"); // background: url("/assets/image.jpg");
47
+ # background: asset-url("image.jpg", $digest: true); // background: url("/assets/image-27a8f1f96afd8d4c67a59eb9447f45bd.jpg");
48
+ #
49
+ def asset_url(source, options = {})
50
+ ::Sass::Script::String.new "url(#{asset_path(source, options)})"
51
+ end
52
+
53
+ # Using Sprockets::Helpers#image_path, return the full path
54
+ # for the given +source+ as a Sass String. This supports keyword
55
+ # arguments that mirror the +options+.
56
+ #
57
+ # === Examples
58
+ #
59
+ # background: url(image-path("image.jpg")); // background: url("/assets/image.jpg");
60
+ # background: url(image-path("image.jpg", $digest: true)); // background: url("/assets/image-27a8f1f96afd8d4c67a59eb9447f45bd.jpg");
61
+ #
62
+ def image_path(source, options = {})
63
+ ::Sass::Script::String.new sprockets_context.image_path(source.value, map_options(options)).to_s, :string
64
+ end
65
+
66
+ # Using Sprockets::Helpers#image_path, return the url CSS
67
+ # for the given +source+ as a Sass String. This supports keyword
68
+ # arguments that mirror the +options+.
69
+ #
70
+ # === Examples
71
+ #
72
+ # background: image-url("image.jpg"); // background: url("/assets/image.jpg");
73
+ # background: image-url("image.jpg", $digest: true); // background: url("/assets/image-27a8f1f96afd8d4c67a59eb9447f45bd.jpg");
74
+ #
75
+ def image_url(source, options = {}, cache_buster = nil)
76
+ # Work with the Compass #image_url API
77
+ if options.respond_to? :value
78
+ case options.value
79
+ when true
80
+ return image_path source
81
+ else
82
+ options = {}
83
+ end
84
+ end
85
+ ::Sass::Script::String.new "url(#{image_path(source, options)})"
86
+ end
87
+
88
+ # Using Sprockets::Helpers#font_path, return the full path
89
+ # for the given +source+ as a Sass String. This supports keyword
90
+ # arguments that mirror the +options+.
91
+ #
92
+ # === Examples
93
+ #
94
+ # src: url(font-path("font.ttf")); // src: url("/assets/font.ttf");
95
+ # src: url(font-path("font.ttf", $digest: true)); // src: url("/assets/font-27a8f1f96afd8d4c67a59eb9447f45bd.ttf");
96
+ #
97
+ def font_path(source, options = {})
98
+ ::Sass::Script::String.new sprockets_context.font_path(source.value, map_options(options)).to_s, :string
99
+ end
100
+
101
+ # Using Sprockets::Helpers#font_path, return the url CSS
102
+ # for the given +source+ as a Sass String. This supports keyword
103
+ # arguments that mirror the +options+.
104
+ #
105
+ # === Examples
106
+ #
107
+ # src: font-url("font.ttf"); // src: url("/assets/font.ttf");
108
+ # src: font-url("image.jpg", $digest: true); // src: url("/assets/font-27a8f1f96afd8d4c67a59eb9447f45bd.ttf");
109
+ #
110
+ def font_url(source, options = {})
111
+ # Work with the Compass #font_url API
112
+ if options.respond_to? :value
113
+ case options.value
114
+ when true
115
+ return font_path source
116
+ else
117
+ options = {}
118
+ end
119
+ end
120
+ ::Sass::Script::String.new "url(#{font_path(source, options)})"
121
+ end
122
+
123
+ protected
124
+
125
+ # Returns a reference to the Sprocket's context through
126
+ # the importer.
127
+ def sprockets_context # :nodoc:
128
+ options[:custom][:sprockets_context]
129
+ end
130
+
131
+ # Returns an options hash where the keys are symbolized
132
+ # and the values are unwrapped Sass literals.
133
+ def map_options(options = {}) # :nodoc:
134
+ ::Sass::Util.map_hash(options) do |key, value|
135
+ [key.to_sym, value.respond_to?(:value) ? value.value : value]
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
141
+
142
+ module Sass::Script::Functions
143
+ include Flatrack::Sass::Functions
144
+
145
+ # Hack to ensure previous API declarations (by Compass or whatever)
146
+ # don't take precedence.
147
+ [:asset_path, :asset_url, :image_path, :image_url, :font_path, :font_url, :asset_data_uri].each do |method|
148
+ defined?(@signatures) && @signatures.delete(method)
149
+ end
150
+
151
+ declare :asset_path, [:source], :var_kwargs => true
152
+ declare :asset_path, [:source, :kind]
153
+ declare :asset_url, [:source], :var_kwargs => true
154
+ declare :asset_url, [:source, :kind]
155
+ declare :image_path, [:source], :var_kwargs => true
156
+ declare :image_url, [:source], :var_kwargs => true
157
+ declare :image_url, [:source, :only_path]
158
+ declare :image_url, [:source, :only_path, :cache_buster]
159
+ declare :font_path, [:source], :var_kwargs => true
160
+ declare :font_url, [:source], :var_kwargs => true
161
+ declare :font_url, [:source, :only_path]
162
+ declare :asset_data_uri, [:source]
163
+ end
@@ -0,0 +1,142 @@
1
+ require 'sass/importers/base'
2
+ require 'pathname'
3
+
4
+ class Flatrack
5
+ module Sass
6
+ class Importer < ::Sass::Importers::Base
7
+ GLOB = /\*|\[.+\]/
8
+
9
+ # @see Sass::Importers::Base#find_relative
10
+ def find_relative(path, base_path, options)
11
+ if path =~ GLOB
12
+ engine_from_glob(path, base_path, options)
13
+ else
14
+ engine_from_path(path, base_path, options)
15
+ end
16
+ end
17
+
18
+ # @see Sass::Importers::Base#find
19
+ def find(path, options)
20
+ engine_from_path(path, nil, options)
21
+ end
22
+
23
+ # @see Sass::Importers::Base#mtime
24
+ def mtime(path, options)
25
+ if pathname = resolve(path)
26
+ pathname.mtime
27
+ end
28
+ rescue Errno::ENOENT
29
+ nil
30
+ end
31
+
32
+ # @see Sass::Importers::Base#key
33
+ def key(path, options)
34
+ path = Pathname.new(path)
35
+ ["#{self.class.name}:#{path.dirname.expand_path}", path.basename]
36
+ end
37
+
38
+ # @see Sass::Importers::Base#to_s
39
+ def to_s
40
+ "#{self.class.name}:#{context.pathname}"
41
+ end
42
+
43
+ protected
44
+
45
+ # Create a Sass::Engine from the given path.
46
+ def engine_from_path(path, base_path, options)
47
+ context = options[:custom][:sprockets_context]
48
+ pathname = resolve(context, path, base_path) or return nil
49
+ context.depend_on pathname
50
+ ::Sass::Engine.new evaluate(context, pathname), options.merge(
51
+ :filename => pathname.to_s,
52
+ :syntax => syntax(pathname),
53
+ :importer => self
54
+ )
55
+ end
56
+
57
+ # Create a Sass::Engine that will handle importing
58
+ # a glob of files.
59
+ def engine_from_glob(glob, base_path, options)
60
+ context = options[:custom][:sprockets_context]
61
+ imports = resolve_glob(context, glob, base_path).inject('') do |imports, path|
62
+ context.depend_on path
63
+ relative_path = path.relative_path_from Pathname.new(base_path).dirname
64
+ imports << %(@import "#{relative_path}";\n)
65
+ end
66
+ return nil if imports.empty?
67
+ ::Sass::Engine.new imports, options.merge(
68
+ :filename => base_path.to_s,
69
+ :syntax => :scss,
70
+ :importer => self
71
+ )
72
+ end
73
+
74
+ # Finds an asset from the given path. This is where
75
+ # we make Sprockets behave like Sass, and import partial
76
+ # style paths.
77
+ def resolve(context, path, base_path)
78
+ possible_files(context, path, base_path).each do |file|
79
+ context.resolve(file) { |found| return found if context.asset_requirable?(found) }
80
+ end
81
+
82
+ nil
83
+ end
84
+
85
+ # Finds all of the assets using the given glob.
86
+ def resolve_glob(context, glob, base_path)
87
+ base_path = Pathname.new(base_path)
88
+ path_with_glob = base_path.dirname.join(glob).to_s
89
+
90
+ Pathname.glob(path_with_glob).sort.select do |path|
91
+ path != context.pathname && context.asset_requirable?(path)
92
+ end
93
+ end
94
+
95
+ # Returns all of the possible paths (including partial variations)
96
+ # to attempt to resolve with the given path.
97
+ def possible_files(context, path, base_path)
98
+ path = Pathname.new(path)
99
+ base_path = Pathname.new(base_path).dirname
100
+ paths = [ path, partialize_path(path) ]
101
+
102
+ # Find base_path's root
103
+ env_root_paths = context.environment.paths.map {|p| Pathname.new(p) }
104
+ root_path = env_root_paths.detect do |env_root_path|
105
+ base_path.to_s.start_with?(env_root_path.to_s)
106
+ end
107
+ root_path ||= context.root_path
108
+
109
+ # Add the relative path from the root, if necessary
110
+ if path.relative? && base_path != root_path
111
+ relative_path = base_path.relative_path_from(root_path).join path
112
+ paths.unshift(relative_path, partialize_path(relative_path))
113
+ end
114
+
115
+ paths.compact
116
+ end
117
+
118
+ # Returns the partialized version of the given path.
119
+ # Returns nil if the path is already to a partial.
120
+ def partialize_path(path)
121
+ if path.basename.to_s !~ /\A_/
122
+ Pathname.new path.to_s.sub(/([^\/]+)\Z/, '_\1')
123
+ end
124
+ end
125
+
126
+ # Returns the Sass syntax of the given path.
127
+ def syntax(path)
128
+ path.to_s.include?('.sass') ? :sass : :scss
129
+ end
130
+
131
+ # Returns the string to be passed to the Sass engine. We use
132
+ # Sprockets to process the file, but we remove any Sass processors
133
+ # because we need to let the Sass::Engine handle that.
134
+ def evaluate(context, path)
135
+ attributes = context.environment.attributes_for(path)
136
+ processors = context.environment.preprocessors(attributes.content_type) + attributes.engines.reverse
137
+ processors.delete_if { |processor| processor < Tilt::SassTemplate }
138
+ context.evaluate(path, :processors => processors)
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,98 @@
1
+ require 'tilt'
2
+
3
+ class Flatrack
4
+ module Sass
5
+ class SassTemplate < Tilt::SassTemplate
6
+ self.default_mime_type = 'text/css'
7
+
8
+ # A reference to the current Sprockets context
9
+ attr_reader :context
10
+
11
+ # Determines if the Sass functions have been initialized.
12
+ # They can be 'initialized' without actually being added.
13
+ @sass_functions_initialized = false
14
+ class << self
15
+ attr_accessor :sass_functions_initialized
16
+ alias :sass_functions_initialized? :sass_functions_initialized
17
+
18
+ # Templates are initialized once the functions are added.
19
+ def engine_initialized?
20
+ super && sass_functions_initialized?
21
+ end
22
+ end
23
+
24
+ # Add the Sass functions if they haven't already been added.
25
+ def initialize_engine
26
+ super unless self.class.superclass.engine_initialized?
27
+ require 'flatrack/sass/functions'
28
+ end
29
+
30
+ # Define the expected syntax for the template
31
+ def syntax
32
+ :sass
33
+ end
34
+
35
+ # See `Tilt::Template#prepare`.
36
+ def prepare
37
+ @context = nil
38
+ @output = nil
39
+ end
40
+
41
+ # See `Tilt::Template#evaluate`.
42
+ def evaluate(context, locals, &block)
43
+ @output ||= begin
44
+ @context = context
45
+ ::Sass::Engine.new(data, sass_options).render
46
+ rescue ::Sass::SyntaxError => e
47
+ # Annotates exception message with parse line number
48
+ context.__LINE__ = e.sass_backtrace.first[:line]
49
+ raise e
50
+ end
51
+ end
52
+
53
+ protected
54
+
55
+ # Returns a Sprockets-aware cache store for Sass::Engine.
56
+ def cache_store
57
+ return nil if context.environment.cache.nil?
58
+
59
+ if defined?(Sprockets::SassCacheStore)
60
+ Sprockets::SassCacheStore.new context.environment
61
+ else
62
+ CacheStore.new context.environment
63
+ end
64
+ end
65
+
66
+ # Assemble the options for the `Sass::Engine`
67
+ def sass_options
68
+ merge_sass_options(default_sass_options, options).merge(
69
+ :filename => eval_file,
70
+ :line => line,
71
+ :syntax => syntax,
72
+ :cache_store => cache_store,
73
+ :importer => Importer.new,
74
+ :custom => { :sprockets_context => context }
75
+ )
76
+ end
77
+
78
+ # Get the default, global Sass options. Start with Compass's
79
+ # options, if it's available.
80
+ def default_sass_options
81
+ if defined?(Compass)
82
+ merge_sass_options Compass.sass_engine_options.dup, Flatrack.sass_options
83
+ else
84
+ Flatrack.sass_options.dup
85
+ end
86
+ end
87
+
88
+ # Merges two sets of `Sass::Engine` options, prepending
89
+ # the `:load_paths` instead of clobbering them.
90
+ def merge_sass_options(options, other_options)
91
+ if (load_paths = options[:load_paths]) && (other_paths = other_options[:load_paths])
92
+ other_options[:load_paths] = other_paths + load_paths
93
+ end
94
+ options.merge other_options
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,12 @@
1
+ class Flatrack
2
+ module Sass
3
+ class ScssTemplate < SassTemplate
4
+ self.default_mime_type = 'text/css'
5
+
6
+ # Define the expected syntax for the template
7
+ def syntax
8
+ :scss
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  # Version
2
2
  class Flatrack
3
3
  # @private
4
- VERSION = '1.3.3.alpha.1'
4
+ VERSION = '1.3.3'
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -15,6 +15,8 @@ end
15
15
  require 'flatrack'
16
16
  Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
17
17
 
18
+ Object.send(:define_method, :warn){ |*args| }
19
+
18
20
  RSpec.configure do |config|
19
21
  config.run_all_when_everything_filtered = true
20
22
  config.filter_run focus: true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flatrack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3.alpha.1
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Waldrip
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-15 00:00:00.000000000 Z
11
+ date: 2014-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -92,14 +92,14 @@ dependencies:
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '1.0'
95
+ version: '1.2'
96
96
  type: :runtime
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '1.0'
102
+ version: '1.2'
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: thor
105
105
  requirement: !ruby/object:Gem::Requirement
@@ -168,14 +168,14 @@ dependencies:
168
168
  requirements:
169
169
  - - "~>"
170
170
  - !ruby/object:Gem::Version
171
- version: '2.14'
171
+ version: '3.1'
172
172
  type: :development
173
173
  prerelease: false
174
174
  version_requirements: !ruby/object:Gem::Requirement
175
175
  requirements:
176
176
  - - "~>"
177
177
  - !ruby/object:Gem::Version
178
- version: '2.14'
178
+ version: '3.1'
179
179
  - !ruby/object:Gem::Dependency
180
180
  name: guard
181
181
  requirement: !ruby/object:Gem::Requirement
@@ -344,6 +344,11 @@ files:
344
344
  - lib/flatrack/cli/templates/stylesheet.css.scss
345
345
  - lib/flatrack/request.rb
346
346
  - lib/flatrack/response.rb
347
+ - lib/flatrack/sass.rb
348
+ - lib/flatrack/sass/functions.rb
349
+ - lib/flatrack/sass/importer.rb
350
+ - lib/flatrack/sass/sass_template.rb
351
+ - lib/flatrack/sass/scss_template.rb
347
352
  - lib/flatrack/site.rb
348
353
  - lib/flatrack/template.rb
349
354
  - lib/flatrack/template/erubis.rb
@@ -412,9 +417,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
412
417
  version: 1.9.3
413
418
  required_rubygems_version: !ruby/object:Gem::Requirement
414
419
  requirements:
415
- - - ">"
420
+ - - ">="
416
421
  - !ruby/object:Gem::Version
417
- version: 1.3.1
422
+ version: '0'
418
423
  requirements: []
419
424
  rubyforge_project:
420
425
  rubygems_version: 2.2.2