hugh 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Andy Rossmeissl
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,13 @@
1
+ = hugh
2
+
3
+ Rails (2.x - 3.x) hue picker form helper
4
+
5
+ == Installation
6
+
7
+ * Add the gem to your Rails app, either through an initializer (Rails 2.x with rake gems:install) or its Gemfile (Rails 3 with bundle install).
8
+ * Use the hugh_assets generator to add the necessary javascript libraries to your app.
9
+
10
+ == Copyright
11
+
12
+ Copyright (c) 2010 Andy Rossmeissl. See LICENSE for details.
13
+
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "hugh"
8
+ gem.summary = %Q{Rails 2/3 hue picker form helper}
9
+ gem.description = %Q{A slider for picking a color hue built with Scriptaculous and Prototype}
10
+ gem.email = "andy@rossmeissl.net"
11
+ gem.homepage = "http://github.com/rossmeissl/hugh"
12
+ gem.authors = ["Andy Rossmeissl"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/test_*.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "hugh #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,51 @@
1
+ if defined?(Rails) && Rails::VERSION::MAJOR >= 3
2
+
3
+ class HughAssetsGenerator < Rails::Generators::Base
4
+
5
+ include Rails::Generators::Actions
6
+
7
+ def create_hugh_file
8
+ empty_directory('public/javascripts')
9
+ copy_file(
10
+ File.join(File.dirname(__FILE__), 'templates', 'hugh.js'),
11
+ 'public/javascripts/hugh.js'
12
+ )
13
+ empty_directory('public/stylesheets/images/hugh')
14
+ copy_file(
15
+ File.join(File.dirname(__FILE__), 'templates', 'hugh.css'),
16
+ 'public/stylesheets/hugh.css'
17
+ )
18
+ copy_file(
19
+ File.join(File.dirname(__FILE__), 'templates', 'spectrum.png'),
20
+ 'public/stylesheets/images/hugh/spectrum.png'
21
+ )
22
+ copy_file(
23
+ File.join(File.dirname(__FILE__), 'templates', 'handle.png'),
24
+ 'public/stylesheets/images/hugh/handle.png'
25
+ )
26
+ readme(File.join(File.dirname(__FILE__), 'templates', 'NOTES'))
27
+ end
28
+
29
+ end
30
+
31
+ else
32
+
33
+ class HughAssetsGenerator < Rails::Generator::Base
34
+
35
+ def manifest
36
+ record do |m|
37
+ m.directory('public/javascripts')
38
+ m.file('hugh.js', 'public/javascripts/hugh.js')
39
+ m.directory('public/stylesheets/images/hugh')
40
+ m.file('hugh.css', 'public/stylesheets/hugh.css')
41
+ m.file('spectrum.png', 'public/stylesheets/images/hugh/spectrum.png')
42
+ m.file('handle.png', 'public/stylesheets/images/hugh/handle.png')
43
+ m.readme('NOTES')
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
51
+
@@ -0,0 +1,9 @@
1
+ [hugh] Hugh assets have been installed in public/javascripts.
2
+ [hugh] Your application (or at least relevant views) must include Prototype, Scriptaculous, and Scriptaculous's Slider library (Control.Slider in slider.js)
3
+ [hugh] Please ensure the following is present your application layout:
4
+
5
+ javascript_include_tag 'hugh'
6
+ stylesheet_link_tag 'hugh'
7
+
8
+ [hugh] Thanks.
9
+
@@ -0,0 +1,12 @@
1
+ .hugh-track {
2
+ width: 260px;
3
+ height: 21px;
4
+ background: url(images/hugh/spectrum.png) no-repeat 2px center;
5
+ }
6
+
7
+ .hugh-handle {
8
+ width: 5px;
9
+ height: 21px;
10
+ background: url(images/hugh/handle.png) no-repeat;
11
+ cursor: W-resize;
12
+ }
@@ -0,0 +1,64 @@
1
+ var foo;
2
+ var Hugh = Class.create({
3
+ initialize: function(el) {
4
+ this.el = $(el);
5
+ this.track = new Element('div', { 'class': 'hugh hugh-track' });
6
+ this.handle = new Element('div', { 'class': 'hugh hugh-handle' });
7
+ this.track.insert({ bottom: this.handle });
8
+ this.el.insert({ after: this.track });
9
+ this.numFromHex = function(hex) {
10
+ red = parseInt(hex.substr(0, 2), 16);
11
+ green = parseInt(hex.substr(2, 2), 16);
12
+ blue = parseInt(hex.substr(4, 2), 16);
13
+ if (red == 255 && green == 0) return blue;
14
+ else if (green == 0 && blue == 255) return 256 + 255 - red;
15
+ else if (red == 0 && blue == 255) return 512 + green;
16
+ else if (red == 0 && green == 255) return 768 + 255 - blue;
17
+ else if (green == 255 && blue == 0) return 1024 + red;
18
+ else if (red == 255 && blue == 0) return 1280 + 255 - green;
19
+ }
20
+ this.slider = new Control.Slider(this.handle, this.track, {
21
+ hugh: this,
22
+ range: $R(0, 1535),
23
+ sliderValue: this.numFromHex($F(this.el)),
24
+ onChange: function(num, slider) {
25
+ if (num < 256) {
26
+ red = 255;
27
+ green = 0;
28
+ blue = num.round() % 256;
29
+ }
30
+ else if (num < 512) {
31
+ red = 255 - (num.round() % 256);
32
+ green = 0;
33
+ blue = 255;
34
+ }
35
+ else if (num < 768) {
36
+ red = 0;
37
+ green = num.round() % 256;
38
+ blue = 255;
39
+ }
40
+ else if (num < 1024) {
41
+ red = 0;
42
+ green = 255;
43
+ blue = 255 - (num.round() % 256);
44
+ }
45
+ else if (num < 1280) {
46
+ red = num.round() % 256;
47
+ green = 255;
48
+ blue = 0;
49
+ }
50
+ else if (num < 1536) {
51
+ red = 255;
52
+ green = 255 - (num.round() % 256);
53
+ blue = 0;
54
+ }
55
+ slider.options.hugh.rgb = [red, green, blue];
56
+ slider.options.hugh.hex = slider.options.hugh.colorToHex(red, green, blue);
57
+ slider.options.hugh.el.value = slider.options.hugh.hex;
58
+ }
59
+ });
60
+ this.colorToHex = function(red, green, blue) {
61
+ return red.toColorPart() + green.toColorPart() + blue.toColorPart();
62
+ };
63
+ }
64
+ });
data/hugh.gemspec ADDED
@@ -0,0 +1,63 @@
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{hugh}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Andy Rossmeissl"]
12
+ s.date = %q{2010-05-17}
13
+ s.description = %q{A slider for picking a color hue built with Scriptaculous and Prototype}
14
+ s.email = %q{andy@rossmeissl.net}
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
+ "generators/hugh_assets/hugh_assets_generator.rb",
27
+ "generators/hugh_assets/templates/NOTES",
28
+ "generators/hugh_assets/templates/handle.png",
29
+ "generators/hugh_assets/templates/hugh.css",
30
+ "generators/hugh_assets/templates/hugh.js",
31
+ "generators/hugh_assets/templates/spectrum.png",
32
+ "hugh.gemspec",
33
+ "lib/hugh.rb",
34
+ "lib/hugh/helpers.rb",
35
+ "lib/hugh/railtie.rb",
36
+ "rails/init.rb",
37
+ "test/helper.rb",
38
+ "test/test_hugh.rb"
39
+ ]
40
+ s.homepage = %q{http://github.com/rossmeissl/hugh}
41
+ s.rdoc_options = ["--charset=UTF-8"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = %q{1.3.6}
44
+ s.summary = %q{Rails 2/3 hue picker form helper}
45
+ s.test_files = [
46
+ "test/helper.rb",
47
+ "test/test_hugh.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<thoughtbot-shoulda>, [">= 0"])
56
+ else
57
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
61
+ end
62
+ end
63
+
data/lib/hugh.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'hugh/railtie' if defined?(Rails) && Rails::VERSION::MAJOR >= 3
2
+
3
+ module Hugh
4
+ autoload 'Helpers', 'hugh/helpers'
5
+ end
6
+
7
+ ActionView::Base.send :include, Hugh::Helpers
@@ -0,0 +1,34 @@
1
+ module Hugh
2
+ module Helpers
3
+ def self.included(base)
4
+ ::ActionView::Helpers::InstanceTag.send :include, InstanceTag
5
+ ::ActionView::Helpers::FormBuilder.send :include, FormBuilder
6
+ end
7
+
8
+ def hue_picker(object, method, options = {}, html_options = {})
9
+ instance_tag = ::ActionView::Helpers::InstanceTag.new(object, method, self, options.delete(:object))
10
+ instance_tag.to_hue_picker_tag(html_options) + javascript_tag(instance_tag.to_hue_picker_js(html_options))
11
+ end
12
+
13
+ module InstanceTag
14
+ def to_hue_picker_tag(html_options)
15
+ html_options = html_options.stringify_keys
16
+ add_default_name_and_id(html_options)
17
+ value = value(object)
18
+ hidden_field_tag('', value, html_options)
19
+ end
20
+
21
+ def to_hue_picker_js(html_options)
22
+ html_options = html_options.stringify_keys
23
+ add_default_name_and_id(html_options)
24
+ "#{tag_id}_hue_picker = new Hugh('#{tag_id}')"
25
+ end
26
+ end
27
+
28
+ module FormBuilder
29
+ def hue_picker(method, options = {}, html_options = {})
30
+ @template.hue_picker(@object_name, method, options.merge(:object => @object), html_options)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,18 @@
1
+ require 'hugh'
2
+ require 'rails'
3
+
4
+ module Hugh
5
+ class Railtie < Rails::Railtie
6
+
7
+ GEM_ROOT = File.join(File.dirname(__FILE__), '..', '..')
8
+
9
+ initializer 'hugh.initialization' do
10
+ require File.join(GEM_ROOT, 'rails', 'init')
11
+ end
12
+
13
+ generators do
14
+ require File.join(GEM_ROOT, 'generators', 'hugh_assets_generator')
15
+ end
16
+
17
+ end
18
+ end
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'hugh'
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'hugh'
8
+
9
+ class Test::Unit::TestCase
10
+ end
data/test/test_hugh.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestHugh < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hugh
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Andy Rossmeissl
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-17 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ description: A slider for picking a color hue built with Scriptaculous and Prototype
33
+ email: andy@rossmeissl.net
34
+ executables: []
35
+
36
+ extensions: []
37
+
38
+ extra_rdoc_files:
39
+ - LICENSE
40
+ - README.rdoc
41
+ files:
42
+ - .document
43
+ - .gitignore
44
+ - LICENSE
45
+ - README.rdoc
46
+ - Rakefile
47
+ - VERSION
48
+ - generators/hugh_assets/hugh_assets_generator.rb
49
+ - generators/hugh_assets/templates/NOTES
50
+ - generators/hugh_assets/templates/handle.png
51
+ - generators/hugh_assets/templates/hugh.css
52
+ - generators/hugh_assets/templates/hugh.js
53
+ - generators/hugh_assets/templates/spectrum.png
54
+ - hugh.gemspec
55
+ - lib/hugh.rb
56
+ - lib/hugh/helpers.rb
57
+ - lib/hugh/railtie.rb
58
+ - rails/init.rb
59
+ - test/helper.rb
60
+ - test/test_hugh.rb
61
+ has_rdoc: true
62
+ homepage: http://github.com/rossmeissl/hugh
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options:
67
+ - --charset=UTF-8
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project:
87
+ rubygems_version: 1.3.6
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Rails 2/3 hue picker form helper
91
+ test_files:
92
+ - test/helper.rb
93
+ - test/test_hugh.rb