pictopus 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Intridea, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,73 @@
1
+ = Pictopus
2
+
3
+ Pictopus is a Rails developer tool that allows you to use ImageMagick to
4
+ automatically generate gradient images to use in your design. It is
5
+ implemented using Rails Engines for the routing and simply runs ImageMagick
6
+ through the command line (using the 'convert' command).
7
+
8
+ == Installation
9
+
10
+ Pictopus is available as a gem on Gemcutter.
11
+
12
+ gem install pictopus
13
+
14
+ To include it in your Rails application, add this to your <tt>development.rb</tt>
15
+ file (NOTE: It is <b>not</b> recommended to include the Pictopus gem in
16
+ your production environment).
17
+
18
+ config.gem 'pictopus'
19
+
20
+ == Usage
21
+
22
+ If you have ImageMagick installed in your Rails app, you can create
23
+ arbitrary gradient images just by naming them as a URL. They will
24
+ automatically be created by ImageMagick and cached to your public
25
+ directory, meaning that the generation happens once. You can then
26
+ check them into your repository and your production environment
27
+ will treat them like any other image.
28
+
29
+ To create a gradient using Pictopus, just query a path like this:
30
+
31
+ /images/pictopus/gradient/fff.000.v.100.png
32
+
33
+ In this case, a 1x100 image with a vertical white to black gradient
34
+ would be created. The structure of the image filename is:
35
+
36
+ :start_color.:end_color.:orientation.:size.:format
37
+
38
+ For a more complete description of the options:
39
+
40
+ * <tt>:start_color</tt> - The color for the top (or left) of the gradient.
41
+ * <tt>:end_color</tt> - The color for the bottom (or right) of the gradient.
42
+ * <tt>:orientation</tt> - "v" for a vertical gradient (top to bottom) or
43
+ "h" for a horizontal one.
44
+ * <tt>:size</tt> - The size of the image. If only one number is supplied,
45
+ the image will be 1 pixel wide or high depending on orientation. To create
46
+ a multi-dimensional image simply specify it in <tt>wxh</tt> for example
47
+ <tt>50x100</tt>.
48
+
49
+ == Colors
50
+
51
+ Colors are described in web hex code, with acceptable formats including
52
+ <tt>RRGGBB</tt>, <tt>RGB</tt>, and <tt>RRGGBBAA</tt> (for <tt>.png</tt>
53
+ images only).
54
+
55
+ == Future
56
+
57
+ While this is a ridiculously simple tool for the time being, it is helpful
58
+ for me in rapidly prototyping websites without getting bogged down in
59
+ Photoshop. In the future, I hope to bring together more powerful functionality,
60
+ perhaps drawing inspiration from the AJAX Spinner Generator and other
61
+ similar sites to create additional "commands".
62
+
63
+ == Note on Patches/Pull Requests
64
+
65
+ * Fork the project.
66
+ * Make your feature addition or bug fix.
67
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
68
+ * Commit, do not mess with Rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
69
+ * Send us a pull request. Bonus points for topic branches.
70
+
71
+ == Copyright
72
+
73
+ Copyright (c) 2009 Michael Bleigh. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "pictopus"
8
+ gem.summary = %Q{A Rails Engine for dynamically generating images for your application design.}
9
+ gem.description = %Q{A Rails Engine to dynamically generate images for your application while in development mode.}
10
+ gem.email = "michael@intridea.com"
11
+ gem.homepage = "http://github.com/intridea/pictopus"
12
+ gem.authors = ["Michael Bleigh"]
13
+ gem.add_development_dependency "rspec"
14
+ gem.add_development_dependency "remarkable"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ if File.exist?('VERSION')
41
+ version = File.read('VERSION')
42
+ else
43
+ version = ""
44
+ end
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "pictopus #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,10 @@
1
+ class PictopusController < ApplicationController
2
+ def gradient
3
+ @opts = {}
4
+ Pictopus::Gradient::OPTION_KEYS.each{|k| @opts[k] = params[k]}
5
+
6
+ Pictopus::Gradient.new(@opts).run!
7
+ redirect_to request.request_uri
8
+ end
9
+ end
10
+
@@ -0,0 +1,5 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ map.with_options(:name_prefix => 'pictopus_', :controller => 'pictopus') do |pictopus|
3
+ pictopus.gradient '/images/pictopus/gradient/:start_color.:end_color.:orientation.:size.:format', :action => 'gradient'
4
+ end
5
+ end
data/lib/pictopus.rb ADDED
@@ -0,0 +1,33 @@
1
+ module Pictopus
2
+ class CommandLineError < StandardError; end
3
+
4
+ class << self
5
+ def options
6
+ @options ||= {
7
+ :command_path => nil,
8
+ :log => true,
9
+ :swallow_stderr => true,
10
+ :log_command => true
11
+ }
12
+ end
13
+
14
+ def run(cmd, params="", expected_outcodes = 0)
15
+ command = %Q[#{path_for_command(cmd)} #{params}].gsub(/\s+/, " ")
16
+ command = "#{command} 2>#{bit_bucket}" if Pictopus.options[:swallow_stderr]
17
+ Rails.logger.info(command) if Pictopus.options[:log_command]
18
+ output = `#{command}`
19
+ unless Array(expected_outcodes).include?($?.exitstatus)
20
+ raise Pictopus::CommandLineError, "Error while running #{cmd}"
21
+ end
22
+ end
23
+
24
+ def path_for_command(command)
25
+ path = [options[:command_path], command].compact!
26
+ File.join(*path)
27
+ end
28
+
29
+ def bit_bucket #:nodoc:
30
+ File.exists?("/dev/null") ? "/dev/null" : "NUL"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,98 @@
1
+ require 'pictopus'
2
+
3
+ module Pictopus
4
+ class Gradient
5
+ OPTION_KEYS = [:start_color, :end_color, :orientation, :size, :format]
6
+
7
+ # Provide some default options for
8
+ # generating gradients. You shouldn't
9
+ # ever really see this unless you're
10
+ # hacking on something custom.
11
+ def self.default_options
12
+ @options ||= {
13
+ :size => '100x100',
14
+ :format => 'png',
15
+ :orientation => 'vertical',
16
+ :start_color => 'fff',
17
+ :end_color => '000'
18
+ }
19
+ end
20
+
21
+ # Create a new Gradient object and provide
22
+ # options. The available options are enumerated
23
+ # in OPTION_KEYS.
24
+ def initialize(options = {})
25
+ @options = self.class.default_options.merge(options)
26
+ end
27
+
28
+ # Convert this object to a string of command line arguments
29
+ # acceptable by ImageMagick.
30
+ def to_args
31
+ args = []
32
+ args << "-size #{parse_size(size)}"
33
+ args << "gradient:#{parse_color(start_color)}-#{parse_color(end_color)}"
34
+ args << "-rotate -90" if horizontal?
35
+ args << File.join(output_directory, file_name)
36
+ args.join(' ')
37
+ end
38
+
39
+ # Run the actual command to generate the image
40
+ # for this instance.
41
+ def run!
42
+ Pictopus.run('convert', self.to_args)
43
+ end
44
+
45
+ OPTION_KEYS.each do |opt|
46
+ class_eval <<-RUBY
47
+ def #{opt}
48
+ @options[#{opt.inspect}]
49
+ end
50
+
51
+ def #{opt}=(value)
52
+ @options[#{opt.inspect}] = value
53
+ end
54
+ RUBY
55
+ end
56
+
57
+ # True if the image is set to be a vertical gradient.
58
+ def vertical?
59
+ %w(v vertical).include?(orientation)
60
+ end
61
+
62
+ # True if the image is set to be a horizontal gradient.
63
+ def horizontal?
64
+ %w(h horizontal).include?(orientation)
65
+ end
66
+
67
+ def output_directory # :nodoc:
68
+ File.join(Rails.root, 'public', 'images', 'pictopus', 'gradient')
69
+ end
70
+
71
+ def file_name # :nodoc:
72
+ [start_color, end_color, orientation, size, format].join('.')
73
+ end
74
+
75
+ protected
76
+
77
+ def parse_color(color_string)
78
+ if color_string =~ /[0-9a-f]{3}/i ||
79
+ color_string =~ /[0-9a-f]{6}/i ||
80
+ color_string =~ /[0-9a-f]{8}/i
81
+ "##{color_string}".downcase
82
+ end
83
+ end
84
+
85
+ def parse_size(size_string)
86
+ dimensions = size_string.split('x')
87
+
88
+ case dimensions.size
89
+ when 2
90
+ dimensions.reverse! if horizontal?
91
+ when 1
92
+ dimensions.unshift('1')
93
+ end
94
+
95
+ dimensions.join('x')
96
+ end
97
+ end
98
+ end
data/pictopus.gemspec ADDED
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{pictopus}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Michael Bleigh"]
12
+ s.date = %q{2009-10-27}
13
+ s.description = %q{A Rails Engine to dynamically generate images for your application while in development mode.}
14
+ s.email = %q{michael@intridea.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "app/controllers/pictopus_controller.rb",
27
+ "config/pictopus_routes.rb",
28
+ "lib/pictopus.rb",
29
+ "lib/pictopus/gradient.rb",
30
+ "pictopus.gemspec",
31
+ "rails/init.rb",
32
+ "spec/controllers/pictopus_controller_spec.rb",
33
+ "spec/pictopus/gradient_spec.rb",
34
+ "spec/pictopus_spec.rb",
35
+ "spec/spec.opts",
36
+ "spec/spec_helper.rb"
37
+ ]
38
+ s.homepage = %q{http://github.com/intridea/pictopus}
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.5}
42
+ s.summary = %q{A Rails Engine for dynamically generating images for your application design.}
43
+ s.test_files = [
44
+ "spec/controllers/pictopus_controller_spec.rb",
45
+ "spec/pictopus/gradient_spec.rb",
46
+ "spec/pictopus_spec.rb",
47
+ "spec/spec_helper.rb"
48
+ ]
49
+
50
+ if s.respond_to? :specification_version then
51
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
+ s.specification_version = 3
53
+
54
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
55
+ s.add_development_dependency(%q<rspec>, [">= 0"])
56
+ s.add_development_dependency(%q<remarkable>, [">= 0"])
57
+ else
58
+ s.add_dependency(%q<rspec>, [">= 0"])
59
+ s.add_dependency(%q<remarkable>, [">= 0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<rspec>, [">= 0"])
63
+ s.add_dependency(%q<remarkable>, [">= 0"])
64
+ end
65
+ end
66
+
data/rails/init.rb ADDED
@@ -0,0 +1,19 @@
1
+ class ActionController::Routing::RouteSet
2
+ def load_routes_with_pictopus!
3
+ pictopus_routes = File.join(File.dirname(__FILE__),
4
+ *%w[.. config pictopus_routes.rb])
5
+ unless configuration_files.include? pictopus_routes
6
+ add_configuration_file(pictopus_routes)
7
+ end
8
+ load_routes_without_pictopus!
9
+ end
10
+
11
+ alias_method_chain :load_routes!, :pictopus
12
+ end
13
+
14
+ require 'pictopus'
15
+
16
+ if Rails.env == 'test'
17
+ config.gem 'rspec', :lib => false
18
+ config.gem 'remarkable', :lib => false
19
+ end
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe PictopusController do
4
+ should_route :get, '/images/pictopus/gradient/fff.000.v.100.png',
5
+ :controller => 'pictopus',
6
+ :action => 'gradient',
7
+ :start_color => 'fff',
8
+ :end_color => '000',
9
+ :orientation => 'v',
10
+ :size => '100',
11
+ :format => 'png'
12
+
13
+ describe '#gradient' do
14
+ before do
15
+ @opts = {
16
+ :start_color => 'f00',
17
+ :end_color => '00f',
18
+ :size => '50',
19
+ :orientation => 'h',
20
+ :format => 'jpg'
21
+ }
22
+ end
23
+
24
+ it 'should create a Pictopus::Gradient for the provided params' do
25
+ Pictopus::Gradient.should_receive(:new).with(@opts).and_return(mock('Pictopus::Gradient', :run! => true))
26
+ get :gradient, @opts.dup
27
+ end
28
+
29
+ it 'should call run! on the gradient' do
30
+ @g = Pictopus::Gradient.new(@opts)
31
+ Pictopus::Gradient.stub!(:new).and_return(@g)
32
+ @g.should_receive(:run!).and_return(true)
33
+ get :gradient, @opts.dup
34
+ end
35
+
36
+ it 'should redirect to itself (since the image will be generated)' do
37
+ get :gradient, @opts.dup
38
+ response.should redirect_to request.request_uri
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,50 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Pictopus::Gradient do
4
+ it 'should have setters and getters for each of the options' do
5
+ @g = Pictopus::Gradient.new
6
+
7
+ Pictopus::Gradient::OPTION_KEYS.each do |opt|
8
+ @g.should respond_to(opt)
9
+ @g.should respond_to("#{opt}=")
10
+
11
+ @g.send("#{opt}=", 'test')
12
+ @g.send(opt).should == 'test'
13
+ end
14
+ end
15
+
16
+ describe '#to_args' do
17
+ before do
18
+ @g = Pictopus::Gradient.new(
19
+ :start_color => 'aaa',
20
+ :end_color => 'bb33ff',
21
+ :orientation => 'v',
22
+ :size => '30x40',
23
+ :format => 'gif'
24
+ )
25
+ end
26
+
27
+ it 'should add the colors to the gradient commands' do
28
+ @g.to_args.should be_include('gradient:#aaa-#bb33ff')
29
+ end
30
+
31
+ it 'should add the size to the options' do
32
+ @g.to_args.should be_include('-size 30x40')
33
+ end
34
+
35
+ it 'should set size correctly for vertical' do
36
+ @g.size = '50'
37
+ @g.to_args.should be_include('-size 1x50')
38
+ end
39
+
40
+ it 'should flip dimensions for horizontal' do
41
+ @g.orientation = 'horizontal'
42
+ @g.to_args.should be_include('-size 40x30')
43
+ end
44
+
45
+ it 'should add -rotate for horizontal' do
46
+ @g.orientation = 'horizontal'
47
+ @g.to_args.should be_include('-rotate -90')
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Pictopus" do
4
+
5
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,16 @@
1
+ begin
2
+ require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
3
+ rescue LoadError
4
+ puts "You need to install rspec in your base app"
5
+ exit
6
+ end
7
+
8
+ require 'pictopus'
9
+ require 'spec'
10
+ require 'spec/autorun'
11
+
12
+ require 'remarkable_rails'
13
+
14
+ Spec::Runner.configure do |config|
15
+
16
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pictopus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Bleigh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-27 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: remarkable
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: A Rails Engine to dynamically generate images for your application while in development mode.
36
+ email: michael@intridea.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - app/controllers/pictopus_controller.rb
52
+ - config/pictopus_routes.rb
53
+ - lib/pictopus.rb
54
+ - lib/pictopus/gradient.rb
55
+ - pictopus.gemspec
56
+ - rails/init.rb
57
+ - spec/controllers/pictopus_controller_spec.rb
58
+ - spec/pictopus/gradient_spec.rb
59
+ - spec/pictopus_spec.rb
60
+ - spec/spec.opts
61
+ - spec/spec_helper.rb
62
+ has_rdoc: true
63
+ homepage: http://github.com/intridea/pictopus
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options:
68
+ - --charset=UTF-8
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ requirements: []
84
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.3.5
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: A Rails Engine for dynamically generating images for your application design.
90
+ test_files:
91
+ - spec/controllers/pictopus_controller_spec.rb
92
+ - spec/pictopus/gradient_spec.rb
93
+ - spec/pictopus_spec.rb
94
+ - spec/spec_helper.rb