sass-images 0.0.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: 4cec2f538cf81ce0bcac31b4fb0f93c0fe04bdc1
4
+ data.tar.gz: 2c60f1a19a7b764ac75061810857a2b47f8eeff1
5
+ SHA512:
6
+ metadata.gz: d19efd65bae2486a0ea76e8df3a9dee681bd67408e6db1285565fd5d52087226abc1a90430e575df0bab5b4a2a0b74a44fee838d0d0a20cc4a3c1e56e2adecc1
7
+ data.tar.gz: e9955b7c138f11f5ed5a0364b011a5aab1580ce5c63de2ce1d6465634dcf20f8ce4f3177b095fe5c85d75085240e0093e7076d7f724509c4b266227338fc5035
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/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format documentation
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ sass-images
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - rbx-18mode
5
+ - rbx-19mode
6
+ - jruby-19mode
7
+ - jruby-18mode
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'guard'
4
+ gem 'guard-rspec'
5
+ gem 'guard-bundler'
6
+
7
+ # Specify your gem's dependencies in sass-images.gemspec
8
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,13 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
10
+ guard 'bundler' do
11
+ watch('Gemfile')
12
+ watch(/^.+\\.gemspec/)
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Josep Jaume Rey Peroy
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,30 @@
1
+ # Sass::Images
2
+ [![Build Status](https://travis-ci.org/codegram/sass-images.png?branch=master)](https://travis-ci.org/codegram/sass-images)
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ gem 'sass-images', github: 'codegram/sass-images'
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ ## Usage
15
+
16
+ This gem adds new sass helpers especially made to deal with image properties.
17
+
18
+ Right now it includes:
19
+
20
+ * `image-width($path)`: Returns the width (px) of an image
21
+ * `image-height($path)`: Returns the height (px) of an image
22
+ * `inline-image($path)`: Returns an inlined Data URI scheme of an image
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new do |t|
5
+ t.pattern = "spec/**/*_spec.rb"
6
+ end
7
+
8
+ task :default => :spec
@@ -0,0 +1,16 @@
1
+ require "sass/images/version"
2
+ require "sass/images/functions"
3
+
4
+ module Sass
5
+ module Images
6
+ def self.path_resolver=(resolver)
7
+ @path_resolver = resolver
8
+ end
9
+
10
+ def self.path_resolver
11
+ @path_resolver || lambda{ |path| path }
12
+ end
13
+ end
14
+ end
15
+
16
+ require "sass/images/railtie"
@@ -0,0 +1,31 @@
1
+ require 'mini_magick'
2
+ require 'sass'
3
+ require_relative 'image'
4
+
5
+ module Sass::Images
6
+ module Functions
7
+ def image_width(path)
8
+ image = Image.new(resolve_path path)
9
+ Sass::Script::Number.new image.width, ['px']
10
+ end
11
+
12
+ def image_height(path)
13
+ image = Image.new(resolve_path path)
14
+ Sass::Script::Number.new image.height, ['px']
15
+ end
16
+
17
+ def inline_image(path)
18
+ image = Image.new(resolve_path path)
19
+ data_uri = "data:#{image.content_type};base64,#{image.base64}"
20
+ Sass::Script::String.new "url(#{data_uri})", :string
21
+ end
22
+
23
+ private
24
+
25
+ def resolve_path(path)
26
+ Sass::Images.path_resolver.call(path.value)
27
+ end
28
+ end
29
+ end
30
+
31
+ Sass::Script::Functions.send :include, Sass::Images::Functions
@@ -0,0 +1,30 @@
1
+ require 'mime/types'
2
+ require 'base64'
3
+
4
+ class Sass::Images::Image
5
+ def initialize(path)
6
+ @path = path
7
+ end
8
+
9
+ def width
10
+ metadata[:width]
11
+ end
12
+
13
+ def height
14
+ metadata[:height]
15
+ end
16
+
17
+ def base64
18
+ Base64.encode64(File.read(@path)).gsub("\n", '')
19
+ end
20
+
21
+ def content_type
22
+ MIME::Types.type_for(@path)[0].content_type.force_encoding 'UTF-8'
23
+ end
24
+
25
+ private
26
+
27
+ def metadata
28
+ @metadata ||= MiniMagick::Image.open(@path)
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ class Sass::Images::Railtie < Rails::Railtie
2
+ initializer 'sass-images' do
3
+ Sass::Images.path_resolver = lambda do |path|
4
+ Rails.application.assets.find_asset(path).pathname
5
+ end
6
+ end
7
+ end if defined?(Rails)
@@ -0,0 +1,5 @@
1
+ module Sass
2
+ module Images
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -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 'sass/images/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sass-images"
8
+ spec.version = Sass::Images::VERSION
9
+ spec.authors = ["Josep Jaume Rey Peroy"]
10
+ spec.email = ["josepjaume@gmail.com"]
11
+ spec.description = %q{A sass helper that knows how to deal with images}
12
+ spec.summary = %q{A sass helper that knows how to deal with images}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "sass"
22
+ spec.add_runtime_dependency "mini_magick"
23
+ spec.add_runtime_dependency "mime-types"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ end
Binary file
@@ -0,0 +1,36 @@
1
+ require_relative '../../../spec_helper'
2
+
3
+ describe Sass::Images::Functions do
4
+ subject do
5
+ klass = Class.new do
6
+ include Sass::Images::Functions
7
+ end
8
+ klass.new
9
+ end
10
+
11
+ let(:image) do
12
+ Sass::Script::String.new "spec/assets/ed.jpg", :string
13
+ end
14
+
15
+ describe "image_width" do
16
+ it "returns a correct width" do
17
+ width = subject.image_width(image)
18
+ expect(width.to_s).to eq('228px')
19
+ end
20
+ end
21
+
22
+ describe "image_height" do
23
+ it "returns a correct height" do
24
+ height = subject.image_height(image)
25
+ expect(height.to_s).to eq('218px')
26
+ end
27
+ end
28
+
29
+ describe "inline_image" do
30
+ it "returns a data URI scheme" do
31
+ inline = subject.inline_image(image)
32
+ expect(inline.value).to match(/^url\(data:image\/jpeg;base64.*\)$/)
33
+ expect(inline.value)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require_relative '../../../spec_helper'
2
+ require 'base64'
3
+
4
+ describe Sass::Images::Image do
5
+ let(:path){ 'spec/assets/ed.jpg' }
6
+ subject do
7
+ Sass::Images::Image.new(path)
8
+ end
9
+
10
+ describe "#width" do
11
+ it "returns a correct width" do
12
+ expect(subject.width).to eq(228)
13
+ end
14
+ end
15
+
16
+ describe "#height" do
17
+ it "returns a correct height" do
18
+ expect(subject.height).to eq(218)
19
+ end
20
+ end
21
+
22
+ describe "#content_type" do
23
+ it "returns a correct content type" do
24
+ expect(subject.content_type).to eq('image/jpeg')
25
+ end
26
+ end
27
+
28
+ describe "#base64" do
29
+ it "returns a base64 encoded version of a file" do
30
+ decoded = Base64.decode64(subject.base64).force_encoding 'UTF-8'
31
+ original = File.read(path)
32
+
33
+ expect(decoded).to eq(original)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1 @@
1
+ require 'sass/images'
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sass-images
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Josep Jaume Rey Peroy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sass
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mini_magick
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mime-types
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A sass helper that knows how to deal with images
98
+ email:
99
+ - josepjaume@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .rspec
106
+ - .ruby-gemset
107
+ - .ruby-version
108
+ - .travis.yml
109
+ - Gemfile
110
+ - Guardfile
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - lib/sass/images.rb
115
+ - lib/sass/images/functions.rb
116
+ - lib/sass/images/image.rb
117
+ - lib/sass/images/railtie.rb
118
+ - lib/sass/images/version.rb
119
+ - sass-images.gemspec
120
+ - spec/assets/ed.jpg
121
+ - spec/lib/sass/images/functions_spec.rb
122
+ - spec/lib/sass/images/image_spec.rb
123
+ - spec/spec_helper.rb
124
+ homepage: ''
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.0.2
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: A sass helper that knows how to deal with images
148
+ test_files:
149
+ - spec/assets/ed.jpg
150
+ - spec/lib/sass/images/functions_spec.rb
151
+ - spec/lib/sass/images/image_spec.rb
152
+ - spec/spec_helper.rb