Skip to content
Browse files

Release v1.0

  • Loading branch information...
1 parent c487be3 commit 23ebe72a96dc2aa3281f440ea72a904d18a9fb75 @elia committed May 15, 2012
Showing with 54 additions and 13 deletions.
  1. +7 −2 README.md
  2. +13 −8 dimensions-rails.gemspec
  3. +33 −2 lib/dimensions-rails.rb
  4. +1 −1 lib/dimensions-rails/version.rb
View
9 README.md
@@ -1,6 +1,11 @@
# Dimensions::Rails
-TODO: Write a gem description
+Use [dimensions](http://github.com/sstephenson/dimensions) by [@sstephenson](http://github.com/sstephenson) to add automatic images size and improve browser rendering.
+
+### How this improves browser rendering?
+
+See: https://developers.google.com/speed/docs/best-practices/rendering#SpecifyImageDimensions
+
## Installation
@@ -18,7 +23,7 @@ Or install it yourself as:
## Usage
-TODO: Write usage instructions here
+Just use the `image_tag` rails helper as usual, the `:size` options will be magically added by `dimensions-rails` elves!
## Contributing
View
21 dimensions-rails.gemspec
@@ -1,17 +1,22 @@
-# -*- encoding: utf-8 -*-
+# coding: utf-8
require File.expand_path('../lib/dimensions-rails/version', __FILE__)
Gem::Specification.new do |gem|
- gem.authors = ["Elia Schito"]
- gem.email = ["elia@schito.me"]
- gem.description = %q{TODO: Write a gem description}
- gem.summary = %q{TODO: Write a gem summary}
- gem.homepage = ""
+ gem.authors = ['Elia Schito']
+ gem.email = ['elia@schito.me']
+ gem.description = %q{Use dimensions by @sstephenson to add automatic images size and improve browser rendering}
+ gem.summary = %q{Improve browser rendering adding the size to <img> tags}
+ gem.homepage = 'http://elia.github.com/dimensions-rails'
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
- gem.name = "dimensions-rails"
- gem.require_paths = ["lib"]
+ gem.name = 'dimensions-rails'
+ gem.require_paths = ['lib']
gem.version = Dimensions::Rails::VERSION
+
+ gem.add_runtime_dependency 'dimensions'
+ gem.add_runtime_dependency 'railties', '~> 3.0'
+ gem.add_runtime_dependency 'actionpack', '~> 3.0'
+ gem.add_runtime_dependency 'activesupport', '~> 3.0'
end
View
35 lib/dimensions-rails.rb
@@ -1,7 +1,38 @@
-require "dimensions-rails/version"
+require 'dimensions-rails/version'
+require 'active_support/ordered_options'
+require 'rails/railtie'
+require 'dimensions'
module Dimensions
module Rails
- # Your code goes here...
+
+ module Helper
+
+ # Use dimensions by @sstephenson to add automatic images size and improve browser rendering.
+ #
+ # How this improves browser rendering?
+ # https://developers.google.com/speed/docs/best-practices/rendering#SpecifyImageDimensions
+ #
+ def image_tag source, options = {}
+ unless options[:size]
+ fs_path = asset_paths.asset_for(source, nil)
+ options[:width], options[:height] = ::Dimensions.dimensions(fs_path)
+ end
+ super
+ end
+
+ end
+
+ class Railtie < ::Rails::Railtie
+ config.dimensions = ActiveSupport::OrderedOptions.new
+ config.dimensions.add_size_by_default = true
+
+
+ initializer 'dimensions.initialize' do
+ ActiveSupport.on_load(:action_view) do
+ include ::Dimensions::Rails::Helper
+ end
+ end
+ end
end
end
View
2 lib/dimensions-rails/version.rb
@@ -1,5 +1,5 @@
module Dimensions
module Rails
- VERSION = "0.0.1"
+ VERSION = '1.0'
end
end

0 comments on commit 23ebe72

Please sign in to comment.
Something went wrong with that request. Please try again.