Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit b638816bd641fc98adb5f7c148b55d39da5aba0e @sferik committed Mar 17, 2012
Showing with 1,219 additions and 0 deletions.
  1. +7 −0 .gitignore
  2. +17 −0 Gemfile
  3. +99 −0 Gemfile.lock
  4. +20 −0 MIT-LICENSE
  5. +3 −0 README.rdoc
  6. +40 −0 Rakefile
  7. 0 app/assets/images/hyperimage/.gitkeep
  8. +15 −0 app/assets/javascripts/hyperimage/application.js
  9. +13 −0 app/assets/stylesheets/hyperimage/application.css
  10. +4 −0 app/controllers/hyperimage/application_controller.rb
  11. +47 −0 app/controllers/hyperimage/images_controller.rb
  12. +4 −0 app/helpers/hyperimage/application_helper.rb
  13. +54 −0 app/models/hyperimage/image.rb
  14. +14 −0 app/views/layouts/hyperimage/application.html.erb
  15. +5 −0 config/routes.rb
  16. +24 −0 hyperimage.gemspec
  17. +4 −0 lib/hyperimage.rb
  18. +5 −0 lib/hyperimage/engine.rb
  19. +3 −0 lib/hyperimage/version.rb
  20. +4 −0 lib/tasks/hyperimage_tasks.rake
  21. +8 −0 script/rails
  22. +261 −0 test/dummy/README.rdoc
  23. +7 −0 test/dummy/Rakefile
  24. BIN test/dummy/app/assets/images/cradle.gif
  25. BIN test/dummy/app/assets/images/donkey.bmp
  26. BIN test/dummy/app/assets/images/donkey.jpg
  27. BIN test/dummy/app/assets/images/donkey.png
  28. BIN test/dummy/app/assets/images/llama.gif
  29. BIN test/dummy/app/assets/images/nyan.gif
  30. BIN test/dummy/app/assets/images/owl.gif
  31. BIN test/dummy/app/assets/images/owl/0.png
  32. BIN test/dummy/app/assets/images/owl/1.png
  33. BIN test/dummy/app/assets/images/owl/2.png
  34. BIN test/dummy/app/assets/images/owl/3.png
  35. BIN test/dummy/app/assets/images/water.gif
  36. +15 −0 test/dummy/app/assets/javascripts/application.js
  37. +13 −0 test/dummy/app/assets/stylesheets/application.css
  38. +3 −0 test/dummy/app/controllers/application_controller.rb
  39. +2 −0 test/dummy/app/helpers/application_helper.rb
  40. 0 test/dummy/app/mailers/.gitkeep
  41. 0 test/dummy/app/models/.gitkeep
  42. +14 −0 test/dummy/app/views/layouts/application.html.erb
  43. +4 −0 test/dummy/config.ru
  44. +56 −0 test/dummy/config/application.rb
  45. +10 −0 test/dummy/config/boot.rb
  46. +25 −0 test/dummy/config/database.yml
  47. +5 −0 test/dummy/config/environment.rb
  48. +37 −0 test/dummy/config/environments/development.rb
  49. +67 −0 test/dummy/config/environments/production.rb
  50. +37 −0 test/dummy/config/environments/test.rb
  51. +7 −0 test/dummy/config/initializers/backtrace_silencers.rb
  52. +15 −0 test/dummy/config/initializers/inflections.rb
  53. +5 −0 test/dummy/config/initializers/mime_types.rb
  54. +7 −0 test/dummy/config/initializers/secret_token.rb
  55. +8 −0 test/dummy/config/initializers/session_store.rb
  56. +14 −0 test/dummy/config/initializers/wrap_parameters.rb
  57. +5 −0 test/dummy/config/locales/en.yml
  58. +4 −0 test/dummy/config/routes.rb
  59. 0 test/dummy/lib/assets/.gitkeep
  60. 0 test/dummy/log/.gitkeep
  61. +26 −0 test/dummy/public/404.html
  62. +26 −0 test/dummy/public/422.html
  63. +25 −0 test/dummy/public/500.html
  64. 0 test/dummy/public/favicon.ico
  65. +6 −0 test/dummy/script/rails
  66. +34 −0 test/functional/hyperimage/images_controller_test.rb
  67. +7 −0 test/hyperimage_test.rb
  68. +10 −0 test/integration/navigation_test.rb
  69. +10 −0 test/test_helper.rb
  70. +64 −0 test/unit/hyperimage/image_test.rb
@@ -0,0 +1,7 @@
+.bundle/
+log/*.log
+pkg/
+test/dummy/db/*.sqlite3
+test/dummy/log/*.log
+test/dummy/tmp/
+test/dummy/.sass-cache
17 Gemfile
@@ -0,0 +1,17 @@
+source "http://rubygems.org"
+
+# Declare your gem's dependencies in hyperimage.gemspec.
+# Bundler will treat runtime dependencies like base dependencies, and
+# development dependencies will be added by default to the :development group.
+gemspec
+
+# jquery-rails is used by the dummy application
+gem "jquery-rails"
+
+# Declare any dependencies that are still in development here instead of in
+# your gemspec. These might include edge Rails or gems from your path or
+# Git. Remember to move these dependencies to your gemspec before releasing
+# your gem to rubygems.org.
+
+# To use debugger
+# gem 'ruby-debug19', :require => 'ruby-debug'
@@ -0,0 +1,99 @@
+PATH
+ remote: .
+ specs:
+ hyperimage (0.0.1)
+ rails (~> 3.2.2)
+ rmagick
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (3.2.2)
+ actionpack (= 3.2.2)
+ mail (~> 2.4.0)
+ actionpack (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ journey (~> 1.0.1)
+ rack (~> 1.4.0)
+ rack-cache (~> 1.1)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.1.2)
+ activemodel (3.2.2)
+ activesupport (= 3.2.2)
+ builder (~> 3.0.0)
+ activerecord (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
+ arel (~> 3.0.2)
+ tzinfo (~> 0.3.29)
+ activeresource (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
+ activesupport (3.2.2)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ arel (3.0.2)
+ builder (3.0.0)
+ erubis (2.7.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ journey (1.0.3)
+ jquery-rails (2.0.1)
+ railties (>= 3.2.0, < 5.0)
+ thor (~> 0.14)
+ json (1.6.5)
+ mail (2.4.4)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.17.2)
+ multi_json (1.1.0)
+ polyglot (0.3.3)
+ rack (1.4.1)
+ rack-cache (1.2)
+ rack (>= 0.4)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.2.2)
+ actionmailer (= 3.2.2)
+ actionpack (= 3.2.2)
+ activerecord (= 3.2.2)
+ activeresource (= 3.2.2)
+ activesupport (= 3.2.2)
+ bundler (~> 1.0)
+ railties (= 3.2.2)
+ railties (3.2.2)
+ actionpack (= 3.2.2)
+ activesupport (= 3.2.2)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ rmagick (2.13.1)
+ sprockets (2.1.2)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.5)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.32)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ hyperimage!
+ jquery-rails
+ sqlite3
@@ -0,0 +1,20 @@
+Copyright 2012 YOURNAME
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
+= Hyperimage
+
+This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,40 @@
+#!/usr/bin/env rake
+begin
+ require 'bundler/setup'
+rescue LoadError
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
+end
+begin
+ require 'rdoc/task'
+rescue LoadError
+ require 'rdoc/rdoc'
+ require 'rake/rdoctask'
+ RDoc::Task = Rake::RDocTask
+end
+
+RDoc::Task.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'Hyperimage'
+ rdoc.options << '--line-numbers'
+ rdoc.rdoc_files.include('README.rdoc')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
+load 'rails/tasks/engine.rake'
+
+
+
+Bundler::GemHelper.install_tasks
+
+require 'rake/testtask'
+
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = false
+end
+
+
+task :default => :test
No changes.
@@ -0,0 +1,15 @@
+// This is a manifest file that'll be compiled into application.js, which will include all the files
+// listed below.
+//
+// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
+// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
+//
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// the compiled file.
+//
+// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
+// GO AFTER THE REQUIRES BELOW.
+//
+//= require jquery
+//= require jquery_ujs
+//= require_tree .
@@ -0,0 +1,13 @@
+/*
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
+ * listed below.
+ *
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
+ *
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
+ * compiled file, but it's generally better to create a new file per style scope.
+ *
+ *= require_self
+ *= require_tree .
+*/
@@ -0,0 +1,4 @@
+module Hyperimage
+ class ApplicationController < ActionController::Base
+ end
+end
@@ -0,0 +1,47 @@
+require 'RMagick'
+
+module Hyperimage
+
+ class ImagesController < Hyperimage::ApplicationController
+
+ def show
+ # Return HTTP 404 if no resource exists
+ raise ActionController::RoutingError.new('Not Found') unless Hyperimage::Image.exist?(params[:resource])
+
+ # If there's a GIF, select it (since it could have multiple frames);
+ # otherwise, pick the first image.
+ if Hyperimage::Image.exists?(params[:resource], 'gif')
+ source = Hyperimage::Image.first(params[:resource], 'gif')
+ else
+ source = Hyperimage::Image.first(params[:resource])
+ end
+
+ source_file = Magick::Image::read(source)
+
+ # If no frame is explicitly passed, default to the first (zeroth) frame
+ frame = params[:frame].to_i
+
+ # Return HTTP 404 if frame is out of range
+ raise ActionController::RoutingError.new('Not Found') unless (0..(source_file.length - 1)).include?(frame)
+
+ # Try to fetch the image
+ @image = Hyperimage::Image.first(params[:resource], params[:format], frame)
+
+ if @image.nil? # We need to generate the image
+ if source_file.length > 1
+ path = Hyperimage::Image.root.join(params[:resource])
+ Dir.mkdir(path) unless File.exists?(path)
+ @image = path.join([frame, params[:format]].join('.'))
+ else
+ @image = Hyperimage::Image.root.join([params[:resource], params[:format]].join('.'))
+ end
+ source_file[frame].write(@image) { self.quality = 100}
+ end
+
+ mime_type = Mime::Type.lookup_by_extension(File.extname(@image).sub('.', ''))
+ send_file @image, :type => mime_type.to_s, :disposition => 'inline'
+ end
+
+ end
+
+end
@@ -0,0 +1,4 @@
+module Hyperimage
+ module ApplicationHelper
+ end
+end
@@ -0,0 +1,54 @@
+module Hyperimage
+
+ class Image
+
+ class << self
+
+ def root
+ @@root ||= Rails.root.join('app', 'assets', 'images')
+ end
+
+ def exist?(name, format=nil, frame=nil)
+ !!self.first(name, format, frame)
+ end
+ alias :exists? :exist?
+
+ def first(name, format=nil, frame=nil)
+ self.all(name, format, frame).first
+ end
+
+ def all(name, format=nil, frame=nil)
+ # Fetch all files matching the name
+ images = self.files(name)
+ if format
+ # Filter out files that don't match the format
+ images = images.select do |file|
+ File.fnmatch("*.#{format}", file)
+ end
+ if frame
+ # Filter out files that don't match the frame
+ images = images.select do |file|
+ File.fnmatch("#{self.root}/#{name}/#{frame}.#{format}", file)
+ end
+ end
+ end
+ return images
+ end
+
+ protected
+
+ # Given name: 'foo'
+ # Returns all files that match foo.* or foo/*
+ def files(name)
+ self.glob(name, '.') + self.glob(name, '/')
+ end
+
+ def glob(name, connector='.')
+ Dir.glob(self.root.join([name, '*'].join(connector)))
+ end
+
+ end
+
+ end
+
+end
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Hyperimage</title>
+ <%= stylesheet_link_tag "hyperimage/application", :media => "all" %>
+ <%= javascript_include_tag "hyperimage/application" %>
+ <%= csrf_meta_tags %>
+</head>
+<body>
+
+<%= yield %>
+
+</body>
+</html>
@@ -0,0 +1,5 @@
+Hyperimage::Engine.routes.draw do
+
+ get 'images/:resource.:format' => 'images#show', :as => 'images'
+
+end
@@ -0,0 +1,24 @@
+$:.push File.expand_path("../lib", __FILE__)
+
+# Maintain your gem's version:
+require "hyperimage/version"
+
+# Describe your gem and declare its dependencies:
+Gem::Specification.new do |s|
+ s.name = "hyperimage"
+ s.version = Hyperimage::VERSION
+ s.authors = ["Erik Michaels-Ober"]
+ s.email = ["sferik@gmail.com"]
+ s.homepage = "https://github.com/sferik/mwrc2012-app"
+ s.summary = "Convert images!"
+ s.description = "It's awesome!"
+
+ s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
+ s.test_files = Dir["test/**/*"]
+
+ s.add_dependency "rails", "~> 3.2.2"
+ s.add_dependency "rmagick"
+ # s.add_dependency "jquery-rails"
+
+ s.add_development_dependency "sqlite3"
+end
@@ -0,0 +1,4 @@
+require "hyperimage/engine"
+
+module Hyperimage
+end
@@ -0,0 +1,5 @@
+module Hyperimage
+ class Engine < ::Rails::Engine
+ isolate_namespace Hyperimage
+ end
+end
@@ -0,0 +1,3 @@
+module Hyperimage
+ VERSION = "0.0.1"
+end
Oops, something went wrong.

0 comments on commit b638816

Please sign in to comment.