ready for relase

This commit is contained in:
tdreyno 2009-12-13 12:02:24 -08:00
parent 8401b051da
commit 97397489c9
121 changed files with 1762 additions and 463 deletions

View file

@ -12,6 +12,8 @@ gem "rack-test"
gem "yui-compressor"
gem "haml"
gem "compass", "0.10.0.pre2"
gem "compass-colors"
gem "fancy-buttons"
gem "json_pure"
gem "smusher"
gem "compass-slickmap"

View file

@ -68,6 +68,7 @@ module Middleman
end
include StaticRender
@@layout = nil
def self.page(url, options={}, &block)
layout = @@layout
layout = options[:layout] if !options[:layout].nil?

View file

@ -1,5 +1,7 @@
require "sass"
require "compass"
require "compass-colors"
require "fancy-buttons"
begin
require "yui/compressor"

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -10,30 +10,30 @@ module Bundler
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/configuration-1.1.0/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/json_pure-1.2.0/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/json_pure-1.2.0/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/extlib-0.9.13/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/extlib-0.9.13/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/extlib-0.9.14/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/extlib-0.9.14/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/json-1.2.0/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/json-1.2.0/ext/json/ext")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/json-1.2.0/ext")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/json-1.2.0/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/yui-compressor-0.9.1/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/yui-compressor-0.9.1/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/rack-1.0.1/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/rack-1.0.1/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/shotgun-0.4/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/shotgun-0.4/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/rack-test-0.5.3/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/rack-test-0.5.3/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/sinatra-0.9.4/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/sinatra-0.9.4/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/yui-compressor-0.9.1/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/yui-compressor-0.9.1/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/rake-0.8.7/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/rake-0.8.7/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/launchy-0.3.3/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/launchy-0.3.3/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/sprockets-1.0.2/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/sprockets-1.0.2/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/shotgun-0.4/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/shotgun-0.4/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/haml-2.2.15/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/haml-2.2.15/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/sprockets-1.0.2/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/sprockets-1.0.2/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/diff-lcs-1.1.2/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/diff-lcs-1.1.2/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/highline-1.5.1/bin")
@ -46,10 +46,14 @@ module Bundler
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/compass-0.10.0.pre2/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/compass-slickmap-0.2.3/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/compass-slickmap-0.2.3/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/compass-colors-0.3.1/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/compass-colors-0.3.1/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/smusher-0.4.2/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/smusher-0.4.2/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/sinatra-content-for-0.2/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/sinatra-content-for-0.2/lib")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/fancy-buttons-0.3.6/bin")
$LOAD_PATH.unshift File.expand_path("#{dir}/gems/fancy-buttons-0.3.6/lib")
@gemfile = "#{dir}/../../../../Gemfile"
@ -60,28 +64,28 @@ module Bundler
@bundled_specs["configuration"].loaded_from = "#{dir}/specifications/configuration-1.1.0.gemspec"
@bundled_specs["json_pure"] = eval(File.read("#{dir}/specifications/json_pure-1.2.0.gemspec"))
@bundled_specs["json_pure"].loaded_from = "#{dir}/specifications/json_pure-1.2.0.gemspec"
@bundled_specs["extlib"] = eval(File.read("#{dir}/specifications/extlib-0.9.13.gemspec"))
@bundled_specs["extlib"].loaded_from = "#{dir}/specifications/extlib-0.9.13.gemspec"
@bundled_specs["extlib"] = eval(File.read("#{dir}/specifications/extlib-0.9.14.gemspec"))
@bundled_specs["extlib"].loaded_from = "#{dir}/specifications/extlib-0.9.14.gemspec"
@bundled_specs["json"] = eval(File.read("#{dir}/specifications/json-1.2.0.gemspec"))
@bundled_specs["json"].loaded_from = "#{dir}/specifications/json-1.2.0.gemspec"
@bundled_specs["yui-compressor"] = eval(File.read("#{dir}/specifications/yui-compressor-0.9.1.gemspec"))
@bundled_specs["yui-compressor"].loaded_from = "#{dir}/specifications/yui-compressor-0.9.1.gemspec"
@bundled_specs["rack"] = eval(File.read("#{dir}/specifications/rack-1.0.1.gemspec"))
@bundled_specs["rack"].loaded_from = "#{dir}/specifications/rack-1.0.1.gemspec"
@bundled_specs["shotgun"] = eval(File.read("#{dir}/specifications/shotgun-0.4.gemspec"))
@bundled_specs["shotgun"].loaded_from = "#{dir}/specifications/shotgun-0.4.gemspec"
@bundled_specs["rack-test"] = eval(File.read("#{dir}/specifications/rack-test-0.5.3.gemspec"))
@bundled_specs["rack-test"].loaded_from = "#{dir}/specifications/rack-test-0.5.3.gemspec"
@bundled_specs["sinatra"] = eval(File.read("#{dir}/specifications/sinatra-0.9.4.gemspec"))
@bundled_specs["sinatra"].loaded_from = "#{dir}/specifications/sinatra-0.9.4.gemspec"
@bundled_specs["yui-compressor"] = eval(File.read("#{dir}/specifications/yui-compressor-0.9.1.gemspec"))
@bundled_specs["yui-compressor"].loaded_from = "#{dir}/specifications/yui-compressor-0.9.1.gemspec"
@bundled_specs["rake"] = eval(File.read("#{dir}/specifications/rake-0.8.7.gemspec"))
@bundled_specs["rake"].loaded_from = "#{dir}/specifications/rake-0.8.7.gemspec"
@bundled_specs["launchy"] = eval(File.read("#{dir}/specifications/launchy-0.3.3.gemspec"))
@bundled_specs["launchy"].loaded_from = "#{dir}/specifications/launchy-0.3.3.gemspec"
@bundled_specs["sprockets"] = eval(File.read("#{dir}/specifications/sprockets-1.0.2.gemspec"))
@bundled_specs["sprockets"].loaded_from = "#{dir}/specifications/sprockets-1.0.2.gemspec"
@bundled_specs["shotgun"] = eval(File.read("#{dir}/specifications/shotgun-0.4.gemspec"))
@bundled_specs["shotgun"].loaded_from = "#{dir}/specifications/shotgun-0.4.gemspec"
@bundled_specs["haml"] = eval(File.read("#{dir}/specifications/haml-2.2.15.gemspec"))
@bundled_specs["haml"].loaded_from = "#{dir}/specifications/haml-2.2.15.gemspec"
@bundled_specs["sprockets"] = eval(File.read("#{dir}/specifications/sprockets-1.0.2.gemspec"))
@bundled_specs["sprockets"].loaded_from = "#{dir}/specifications/sprockets-1.0.2.gemspec"
@bundled_specs["diff-lcs"] = eval(File.read("#{dir}/specifications/diff-lcs-1.1.2.gemspec"))
@bundled_specs["diff-lcs"].loaded_from = "#{dir}/specifications/diff-lcs-1.1.2.gemspec"
@bundled_specs["highline"] = eval(File.read("#{dir}/specifications/highline-1.5.1.gemspec"))
@ -94,10 +98,14 @@ module Bundler
@bundled_specs["compass"].loaded_from = "#{dir}/specifications/compass-0.10.0.pre2.gemspec"
@bundled_specs["compass-slickmap"] = eval(File.read("#{dir}/specifications/compass-slickmap-0.2.3.gemspec"))
@bundled_specs["compass-slickmap"].loaded_from = "#{dir}/specifications/compass-slickmap-0.2.3.gemspec"
@bundled_specs["compass-colors"] = eval(File.read("#{dir}/specifications/compass-colors-0.3.1.gemspec"))
@bundled_specs["compass-colors"].loaded_from = "#{dir}/specifications/compass-colors-0.3.1.gemspec"
@bundled_specs["smusher"] = eval(File.read("#{dir}/specifications/smusher-0.4.2.gemspec"))
@bundled_specs["smusher"].loaded_from = "#{dir}/specifications/smusher-0.4.2.gemspec"
@bundled_specs["sinatra-content-for"] = eval(File.read("#{dir}/specifications/sinatra-content-for-0.2.gemspec"))
@bundled_specs["sinatra-content-for"].loaded_from = "#{dir}/specifications/sinatra-content-for-0.2.gemspec"
@bundled_specs["fancy-buttons"] = eval(File.read("#{dir}/specifications/fancy-buttons-0.3.6.gemspec"))
@bundled_specs["fancy-buttons"].loaded_from = "#{dir}/specifications/fancy-buttons-0.3.6.gemspec"
def self.add_specs_to_loaded_specs
Gem.loaded_specs.merge! @bundled_specs

View file

@ -0,0 +1,50 @@
Compass Colors
==============
This compass extension provides support for working with colors in Sass and generating color themes for use on your website.
Installing
==========
sudo gem install chriseppstein-compass-colors
To install a theme into your existing compass project, add the following to your compass configuration file:
require 'compass-colors'
Then run this command:
compass -f colors -p <Theme Name>
The _theme.sass partial can then be imported into your stylesheets and the color constants can be used.
@import theme.sass
Supported Color Themes
======================
With all of these themes, you must pick a base color and the theme takes it from there:
* Basic/Monochromatic (basic)
* Complementary (complementary)
* Triadic (triadic)
* Split Complementary (split_complement)
* Analogous (analogous)
Sass Functions Provided
=======================
* `lighten(color, percentage)` - Create a color lighter by the percent amount provided.
* `darken(color, percentage)` - Create a color darker by the percent amount provided.
* `saturate(color, percentage)` - Increase the saturation of a color by the percent amount provided.
* `desaturate(color, percentage)` - Decrease the saturation of a color by the percent amount provided.
* `hue(color)` - Extract the hue from the color in degrees (0-360). Suitable to be passed as the first argument of hsl.
* `saturation(color)` - Extract the saturation from the color in percent (0-100). Suitable to be passed as the second argument of hsl.
* `luminosity(color)` - Extract the luminosity from the color in percent (0-100). Suitable to be passed as the third argument of hsl.
* `mix(color1, color2, percentage)` - Create a new color by mixing two colors together. Percentage (0-100) is optional, and indicates how
much of color2 should be mixed into color1.
* `grayscale(color)` - Create a gray color by mapping the color provided to the grayscale.
* `adjust_hue(color, degrees)` - Add the number of degrees provided to the hue of the color keeping luminosity and saturation constant.
Degrees can be negative.
* `complement(color)` - Returns the compliment of the color provided.

View file

@ -0,0 +1,26 @@
begin
require 'jeweler'
Jeweler::Tasks.new do |gemspec|
gemspec.name = "compass-colors"
gemspec.summary = "Color Support for Compass & Sass"
gemspec.email = "chris@eppsteins.net"
gemspec.homepage = "http://compass-style.org"
gemspec.description = "Sass Extensions and color theme templates to make working with colors easier and more maintainable."
gemspec.authors = ["Chris Eppstein"]
gemspec.has_rdoc = false
gemspec.add_dependency('compass', '>= 0.8.7')
gemspec.files = []
gemspec.files << "README.markdown"
gemspec.files << "LICENSE.markdown"
gemspec.files << "VERSION.yml"
gemspec.files << "Rakefile"
gemspec.files += Dir.glob("example/**/*")
gemspec.files -= Dir.glob("example/**/*.css")
gemspec.files -= Dir.glob("example/*/extensions/**")
gemspec.files += Dir.glob("lib/**/*")
gemspec.files += Dir.glob("spec/**/*")
gemspec.files += Dir.glob("templates/**/*.*")
end
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end

View file

@ -0,0 +1,5 @@
---
:build:
:major: 0
:minor: 3
:patch: 1

View file

@ -0,0 +1,13 @@
# Require any additional compass plugins here.
require File.join(File.dirname(__FILE__), '..', 'lib', 'compass-colors')
project_type = :stand_alone
# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "stylesheets"
sass_dir = "src"
images_dir = "images"
extensions_dir = "extensions"
output_style = :compact
# To enable relative paths to assets via compass helper functions. Uncomment:
relative_assets = true

View file

@ -0,0 +1,38 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Color Example</title>
<link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" charset="utf-8">
</head>
<body id="split-compliment">
<div class="base">
<div class="lighter">
&nbsp;
</div>
<div class="darker">
&nbsp;
</div>
&nbsp;
</div>
<div class="complement-support">
<div class="lighter">
&nbsp;
</div>
<div class="darker">
&nbsp;
</div>
&nbsp;
</div>
<div class="complement-accent">
<div class="lighter">
&nbsp;
</div>
<div class="darker">
&nbsp;
</div>
&nbsp;
</div>
</body>
</html>

View file

@ -0,0 +1,28 @@
// In theory the lightness and saturation values of corresponding colors should not change.
// In reality, these values should be adjusted to create a more pleasant color combination.
// There is not any mathematical formula for this, but you can use the lighten, darken,
// saturate and desaturate functions to adjust your main colors.
!base_color ||= red
!complement_support_color = adjust_hue(!base_color, 180 + 30)
!complement_accent_color = adjust_hue(!base_color, 180 - 30)
!base_dark_color = darken(!base_color, 25)
!base_darker_color = darken(!base_color, 50)
!base_darkest_color = darken(!base_color, 75)
!base_light_color = lighten(!base_color, 25)
!base_lighter_color = lighten(!base_color, 50)
!base_lightest_color = lighten(!base_color, 75)
!dark_complement_support_color = darken(!complement_support_color, 25)
!darker_complement_support_color = darken(!complement_support_color, 50)
!darkest_complement_support_color = darken(!complement_support_color, 75)
!light_complement_support_color = lighten(!complement_support_color, 25)
!lighter_complement_support_color = lighten(!complement_support_color, 50)
!lightest_complement_support_color = lighten(!complement_support_color, 75)
!dark_complement_accent_color = darken(!complement_accent_color, 25)
!darker_complement_accent_color = darken(!complement_accent_color, 50)
!darkest_complement_accent_color = darken(!complement_accent_color, 75)
!light_complement_accent_color = lighten(!complement_accent_color, 25)
!lighter_complement_accent_color = lighten(!complement_accent_color, 50)
!lightest_complement_accent_color = lighten(!complement_accent_color, 75)

View file

@ -0,0 +1,40 @@
@import compass/utilities.sass
// We can change the theme color here by pre-setting the !base_color
!base_color = #614DA3
@import split_compliment_theme.sass
html
:height 100%
body#split-compliment
:margin 0
:height 100%
.base
:background-color = !base_color
.darker
:background-color = !base_dark_color
.lighter
:background-color = !base_light_color
.complement-support
:background-color = !complement_support_color
.darker
:background-color = !dark_complement_support_color
.lighter
:background-color = !light_complement_support_color
.complement-accent
:background-color = !complement_accent_color
.darker
:background-color = !dark_complement_accent_color
.lighter
:background-color = !light_complement_accent_color
.base, .complement-support, .complement-accent
+clearfix
:height 33%
div
:height 100%
.darker
:float left
.lighter
:float right
.darker, .lighter
:width 33%

View file

@ -0,0 +1,9 @@
require 'compass'
module Compass
module Colors
end
end
require File.join(File.dirname(__FILE__), 'compass-colors', 'hsl')
require File.join(File.dirname(__FILE__), 'compass-colors', 'compass_extension')
require File.join(File.dirname(__FILE__), 'compass-colors', 'sass_extensions')

View file

@ -0,0 +1,7 @@
if defined?(Compass)
options = Hash.new
options[:stylesheets_directory] = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'sass'))
options[:templates_directory] = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'templates'))
Compass::Frameworks.register('colors', options)
end

View file

@ -0,0 +1,109 @@
module Compass
module Colors
class HSL
# Stored in degrees [0, 360)
attr_reader :h
# Stored as a number from [0,1]
attr_reader :s, :l
def self.from_color(color)
rgb = color.respond_to?(:rgb) ? color.rgb : color.value
from_rgb(*rgb)
end
def self.from_rgb(r, g, b)
rgb = [r,g,b]
rgb.map!{|c| c / 255.0}
min_rgb = rgb.min
max_rgb = rgb.max
delta = max_rgb - min_rgb
lightness = (max_rgb + min_rgb) / 2.0
if delta < 1e-5
hue = 0
saturation = 0
else
saturation = if ( lightness < 0.5 )
delta / ( max_rgb + min_rgb )
else
delta / ( 2 - max_rgb - min_rgb )
end
deltas = rgb.map{|c| (((max_rgb - c) / 6.0) + (delta / 2.0)) / delta}
hue = if (rgb[0] - max_rgb).abs < 1e-5
deltas[2] - deltas[1]
elsif (rgb[1] - max_rgb).abs < 1e-5
( 1.0 / 3.0 ) + deltas[0] - deltas[2]
else
( 2.0 / 3.0 ) + deltas[1] - deltas[0]
end
hue += 1 if hue < 0
hue -= 1 if hue > 1
end
from_fractions(hue, saturation, lightness)
end
def self.from_fractions(hue, saturation, lightness)
HSL.new(360 * hue, saturation, lightness)
end
def initialize(h, s, l)
self.h = h
self.s = s
self.l = l
end
def to_color
m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s
m1 = l * 2 - m2
Sass::Script::Color.new([hue_to_rgb(m1, m2, hp + 1.0/3),
hue_to_rgb(m1, m2, hp),
hue_to_rgb(m1, m2, hp - 1.0/3)].map { |c| (c * 0xff).round })
end
def h=(hue)
@h = hue % 360
end
def s=(saturation)
@s = if saturation < 0
0.0
elsif saturation > 1
1.0
else
saturation
end
end
def l=(lightness)
@l = if lightness < 0
0.0
elsif lightness > 1
1.0
else
lightness
end
end
private
#hue as a percentage
def hp
h / 360.0
end
# helper for making rgb
def hue_to_rgb(m1, m2, h)
h += 1 if h < 0
h -= 1 if h > 1
return m1 + (m2 - m1) * h * 6 if h * 6 < 1
return m2 if h * 2 < 1
return m1 + (m2 - m1) * (2.0/3 - h) * 6 if h * 3 < 2
return m1
end
end
end
end

View file

@ -0,0 +1,112 @@
require 'sass'
module Sass::Script::Functions
module Colors
extend self
def rgb_value(color)
if color.respond_to?(:rgb)
color.rgb
else
color.value
end
end
end
# Takes a color object and amount by which to lighten it (0 to 100).
def lighten(color, amount)
hsl = Compass::Colors::HSL.from_color(color)
hsl.l += amount.value / 100.0
hsl.to_color
end
# Takes a color object and percent by which to lighten it (0 to 100).
def lighten_percent(color, amount)
hsl = Compass::Colors::HSL.from_color(color)
hsl.l += (1 - hsl.l) * (amount.value / 100.0)
hsl.to_color
end
# Takes a color object and amount by which to darken it (0 to 100).
def darken(color, amount)
hsl = Compass::Colors::HSL.from_color(color)
hsl.l -= amount.value / 100.0
hsl.to_color
end
# Takes a color object and percent by which to darken it (0 to 100).
def darken_percent(color, amount)
hsl = Compass::Colors::HSL.from_color(color)
hsl.l *= 1.0 - (amount.value / 100.0)
hsl.to_color
end
# Saturate (make a color "richer") a color by the given amount (0 to 100)
def saturate(color, amount)
hsl = Compass::Colors::HSL.from_color(color)
hsl.s += amount.value / 100.0
hsl.to_color
end
# Saturate (make a color "richer") a color by the given percent (0 to 100)
def saturate_percent(color, amount)
hsl = Compass::Colors::HSL.from_color(color)
hsl.s += (1 - hsl.s) * (amount.value / 100.0)
hsl.to_color
end
# Desaturate (make a color "grayer") a color by the given amount (0 to 100)
def desaturate(color, amount)
hsl = Compass::Colors::HSL.from_color(color)
hsl.s -= amount.value / 100.0
hsl.to_color
end
# Desaturate (make a color "grayer") a color by the given percent (0 to 100)
def desaturate_percent(color, amount)
hsl = Compass::Colors::HSL.from_color(color)
hsl.s *= (1.0 - (amount.value / 100.0))
hsl.to_color
end
# Return the hue of a color as a number between 0 and 360
def hue(color)
Sass::Script::Number.new(Compass::Colors::HSL.from_color(color).h.round)
end
# Return the saturation of a color as a number between 0 and 100
def saturation(color)
Sass::Script::Number.new((Compass::Colors::HSL.from_color(color).s * 100).round)
end
# Return the luminosity of a color as a number between 0 and 100
def luminosity(color)
Sass::Script::Number.new((Compass::Colors::HSL.from_color(color).l * 100).round)
end
alias lightness luminosity
# Mixes two colors by some amount (0 to 100). Defaults to 50.
def mix(color1, color2, amount = nil)
percent = amount ? amount.value.round / 100.0 : 0.5
new_colors = Colors.rgb_value(color1).zip(Colors.rgb_value(color2)).map{|c1, c2| (c1 * percent) + (c2 * (1 - percent))}
Sass::Script::Color.new(new_colors)
end
# Returns the grayscale equivalent color for the given color
def grayscale(color)
hsl = Compass::Colors::HSL.from_color(color)
g = (hsl.l * 255).round
Sass::Script::Color.new([g, g, g])
end
# adjust the hue of a color by the given number of degrees.
def adjust_hue(color, degrees)
hsl = Compass::Colors::HSL.from_color(color)
degrees = degrees.value.to_f.round if degrees.is_a?(Sass::Script::Literal)
hsl.h += degrees
hsl.to_color
end
def complement(color)
adjust_hue color, 180
end
end

View file

@ -0,0 +1,43 @@
module BeApproximatelyTheSameColorAsMatcher
class BeApproximatelyTheSameColorAs
def initialize(expected)
@expected = expected
end
def matches?(target)
@target = target
@target.rgb.zip(@expected.rgb).all?{|e,t| (e-t).abs <= 1}
end
def failure_message
"expected <#{to_string(@target)}> to " +
"be approximately the same as <#{to_string(@expected)}>"
end
def negative_failure_message
"expected <#{to_string(@target)}> not to " +
"be approximately the same as <#{to_string(@expected)}>"
end
# Returns string representation of an object.
def to_string(value)
# indicate a nil
if value.nil?
'nil'
end
# join arrays
if value.class == Array
return value.join(", ")
end
# otherwise return to_s() instead of inspect()
return value.to_s
end
end
# Actual matcher that is exposed.
def be_approximately_the_same_color_as(expected)
BeApproximatelyTheSameColorAs.new(expected)
end
end

View file

@ -0,0 +1,54 @@
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(File.dirname(__FILE__), 'approximate_color_matching')
Spec::Runner.configure do |config|
config.include(BeApproximatelyTheSameColorAsMatcher)
end
require 'compass-colors'
describe "sass extensions" do
it "should lighten red into pink" do
pink = invoke(:lighten, color(255,0,0), number(25))
pink.should be_approximately_the_same_color_as(color(255,127,127))
end
it "should lighten red into pink (percentage)" do
pink = invoke(:lighten_percent, color(255,0,0), number(50))
pink.should be_approximately_the_same_color_as(color(255,127,127))
end
it "should darken red into maroon" do
maroon = invoke(:darken, color(255,0,0), number(25))
maroon.should be_approximately_the_same_color_as(color(127,0,0))
end
it "should darken red into maroon (percentage)" do
maroon = invoke(:darken_percent, color(255,0,0), number(50))
maroon.should be_approximately_the_same_color_as(color(127,0,0))
end
it "should darken white into gray and back again" do
darker = invoke(:darken, color(0xff, 0xff, 0xff), number(50))
lighter_again = invoke(:lighten, darker, number(100))
color(0xff, 0xff, 0xff).should be_approximately_the_same_color_as(lighter_again)
end
it "shouldn't saturate fully saturated colors" do
saturated = invoke(:saturate, color(0, 127, 127), number(50))
saturated.should be_approximately_the_same_color_as(color(0, 127, 127))
end
def invoke(name, *args)
Sass::Script::Functions::EvaluationContext.new({}).send(name, *args)
end
def color(r,g,b)
Sass::Script::Color.new([r,g,b])
end
def number(num)
Sass::Script::Number.new(num)
end
end

View file

@ -0,0 +1,28 @@
// In theory the lightness and saturation values of corresponding colors should not change.
// In reality, these values should be adjusted to create a more pleasant color combination.
// There is not any mathematical formula for this, but you can use the lighten, darken,
// saturate and desaturate functions to adjust your main colors.
!base_color ||= red
!support_color = adjust_hue(!base_color, 30)
!accent_color = adjust_hue(!base_color, -30)
!dark_base_color = darken(!base_color, 25)
!darker_base_color = darken(!base_color, 50)
!darkest_base_color = darken(!base_color, 75)
!light_base_color = lighten(!base_color, 25)
!lighter_base_color = lighten(!base_color, 50)
!lightest_base_color = lighten(!base_color, 75)
!dark_support_color = darken(!support_color, 25)
!darker_support_color = darken(!support_color, 50)
!darkest_support_color = darken(!support_color, 75)
!light_support_color = lighten(!support_color, 25)
!lighter_support_color = lighten(!support_color, 50)
!lightest_support_color = lighten(!support_color, 75)
!dark_accent_color = darken(!accent_color, 25)
!darker_accent_color = darken(!accent_color, 50)
!darkest_accent_color = darken(!accent_color, 75)
!light_accent_color = lighten(!accent_color, 25)
!lighter_accent_color = lighten(!accent_color, 50)
!lightest_accent_color = lighten(!accent_color, 75)

View file

@ -0,0 +1 @@
stylesheet '_theme.sass'

View file

@ -0,0 +1,7 @@
!base_color ||= red
!dark_base_color = darken(!base_color, 25)
!darker_base_color = darken(!base_color, 50)
!darkest_base_color = darken(!base_color, 75)
!light_base_color = lighten(!base_color, 25)
!lighter_base_color = lighten(!base_color, 75)
!lightest_base_color = lighten(!base_color, 50)

View file

@ -0,0 +1 @@
stylesheet '_theme.sass'

View file

@ -0,0 +1,20 @@
// In theory the lightness and saturation values of corresponding colors should not change.
// In reality, these values should be adjusted to create a more pleasant color combination.
// There is not any mathematical formula for this, but you can use the lighten, darken,
// saturate and desaturate functions to adjust your main colors.
!base_color ||= red
!complementary_color = complement(!base_color)
!dark_base_color = darken(!base_color, 25)
!darker_base_color = darken(!base_color, 50)
!darkest_base_color = darken(!base_color, 75)
!light_base_color = lighten(!base_color, 25)
!lighter_base_color = lighten(!base_color, 50)
!lightest_base_color = lighten(!base_color, 75)
!dark_complementary_color = darken(!complementary_color, 25)
!darker_complementary_color = darken(!complementary_color, 50)
!darkest_complementary_color = darken(!complementary_color, 75)
!light_complementary_color = lighten(!complementary_color, 25)
!lighter_complementary_color = lighten(!complementary_color, 50)
!lightest_complementary_color = lighten(!complementary_color, 75)

View file

@ -0,0 +1 @@
stylesheet '_theme.sass'

View file

@ -0,0 +1,28 @@
// In theory the lightness and saturation values of corresponding colors should not change.
// In reality, these values should be adjusted to create a more pleasant color combination.
// There is not any mathematical formula for this, but you can use the lighten, darken,
// saturate and desaturate functions to adjust your main colors.
!base_color ||= red
!complement_support_color = adjust_hue(!base_color, 180 + 30)
!complement_accent_color = adjust_hue(!base_color, 180 - 30)
!dark_base_color = darken(!base_color, 25)
!darker_base_color = darken(!base_color, 50)
!darkest_base_color = darken(!base_color, 75)
!light_base_color = lighten(!base_color, 25)
!lighter_base_color = lighten(!base_color, 50)
!lightest_base_color = lighten(!base_color, 75)
!dark_complement_support_color = darken(!complement_support_color, 25)
!darker_complement_support_color = darken(!complement_support_color, 50)
!darkest_complement_support_color = darken(!complement_support_color, 75)
!light_complement_support_color = lighten(!complement_support_color, 25)
!lighter_complement_support_color = lighten(!complement_support_color, 50)
!lightest_complement_support_color = lighten(!complement_support_color, 75)
!dark_complement_accent_color = darken(!complement_accent_color, 25)
!darker_complement_accent_color = darken(!complement_accent_color, 50)
!darkest_complement_accent_color = darken(!complement_accent_color, 75)
!light_complement_accent_color = lighten(!complement_accent_color, 25)
!lighter_complement_accent_color = lighten(!complement_accent_color, 50)
!lightest_complement_accent_color = lighten(!complement_accent_color, 75)

View file

@ -0,0 +1 @@
stylesheet '_theme.sass'

View file

@ -0,0 +1,28 @@
// In theory the lightness and saturation values of corresponding colors should not change.
// In reality, these values should be adjusted to create a more pleasant color combination.
// There is not any mathematical formula for this, but you can use the lighten, darken,
// saturate and desaturate functions to adjust your main colors.
!base_color ||= red
!support_color = adjust_hue(!base_color, 120)
!accent_color = adjust_hue(!base_color, -120)
!dark_base_color = darken(!base_color, 25)
!darker_base_color = darken(!base_color, 50)
!darkest_base_color = darken(!base_color, 75)
!light_base_color = lighten(!base_color, 25)
!lighter_base_color = lighten(!base_color, 50)
!lightest_base_color = lighten(!base_color, 75)
!dark_support_color = darken(!support_color, 25)
!darker_support_color = darken(!support_color, 50)
!darkest_support_color = darken(!support_color, 75)
!light_support_color = lighten(!support_color, 25)
!lighter_support_color = lighten(!support_color, 50)
!lightest_support_color = lighten(!support_color, 75)
!dark_accent_color = darken(!accent_color, 25)
!darker_accent_color = darken(!accent_color, 50)
!darkest_accent_color = darken(!accent_color, 75)
!light_accent_color = lighten(!accent_color, 25)
!lighter_accent_color = lighten(!accent_color, 50)
!lightest_accent_color = lighten(!accent_color, 75)

View file

@ -0,0 +1 @@
stylesheet '_theme.sass'

View file

@ -1,77 +0,0 @@
=== 0.9.13 / 2009-10-15
* 3 minor enhancements:
* Updated LazyArray#head, #tail and #lazy_possible? to be public
* Refactored Time#to_datetime to not use DateTime.parse
* Updated Logger to use Array#join instead of Array#to_s to make
it compatible with Ruby 1.9
=== 0.9.12 / 2009-05-05
* 4 bug fixes
* Fixed constant lookup for nested constructs
* Moved ByteArray to the Extlib module
* Fix specs for recent RSpec versions
* Fix compatibility with ActiveSupport
=== 0.9.11 / 2009-03-29
* 1 major enhancement:
* Added LazyModule, providing similar capabilities to traits in
Smalltalk
* 5 minor enhancements:
* Added Array#to_hash and Array#to_mash
* Silenced warnings when running in verbose mode
* Add ByteArray for representing binary data explicitly
* Alias Pathname#to_s to Pathname#to_str when not defined
* Added Object#try_call
* 2 bug fixes:
* Updated Module.find_const to use const_missing if constant not found
* Fixed LazyArray#equal? to compare object_ids
=== 0.9.10 / 2009-01-19
* 1 major enhancement:
* Ruby 1.9.1 compatibility
* 1 minor enhancement:
* Updated LazyArray#eql? and LazyArray#== to compare without lazy
loading if possible.
* 3 bug fixes:
* Fix for inheritance and hooks
* Fix for Class inheritable accessor to use #try_dup
* Fix for LazyArray to be more explicit in delegating to Array,
to lessen conflicts in subclasses
=== 0.9.9 / 2008-12-07
* 1 major enhancement:
* Updated LazyArray to have a tail/head so that it can append/prepend
without lazy-loading. This will eliminate some too-eager loading
from DataMapper::Collection, and (in certain cases) will boost
performance significantly.
* 3 minor enhancements:
* Minor Ruby 1.9.1 fixes. RSpec still needs to be updated to support
1.9.1 before everything can be verified completely.
* Updated Extlib::Inflection so that the plural of "cow" is now
"cows" instead of "kine".
* Misc documentation updates.
* 2 bug fixes:
* Fixed Extlib::Pooling Threading issue on JRuby and Windows.
* Removed Object#encoded_hash. It was not used by DataMapper or Merb,
and the specs were failing for JRuby.

View file

@ -1,180 +0,0 @@
#!/usr/bin/env ruby
require 'pathname'
require 'rubygems'
require 'rubygems/installer'
require 'rake'
require "rake/clean"
require "rake/gempackagetask"
require "fileutils"
require Pathname('spec/rake/spectask')
require Pathname('lib/extlib/version')
ROOT = Pathname(__FILE__).dirname.expand_path
JRUBY = RUBY_PLATFORM =~ /java/
WINDOWS = Gem.win_platform?
SUDO = (WINDOWS || JRUBY) ? '' : ('sudo' unless ENV['SUDOLESS'])
##############################################################################
# Package && release
##############################################################################
RUBY_FORGE_PROJECT = "extlib"
PROJECT_URL = "http://extlib.rubyforge.org"
PROJECT_SUMMARY = "Support library for DataMapper and Merb."
PROJECT_DESCRIPTION = PROJECT_SUMMARY
AUTHOR = "Dan Kubb"
EMAIL = "dan.kubb@gmail.com"
GEM_NAME = "extlib"
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
GEM_VERSION = Extlib::VERSION + PKG_BUILD
RELEASE_NAME = "REL #{GEM_VERSION}"
require "lib/extlib/tasks/release"
spec = Gem::Specification.new do |s|
s.name = GEM_NAME
s.version = GEM_VERSION
s.platform = Gem::Platform::RUBY
s.author = AUTHOR
s.email = EMAIL
s.homepage = PROJECT_URL
s.summary = PROJECT_SUMMARY
s.description = PROJECT_DESCRIPTION
s.require_path = 'lib'
s.files = %w[ LICENSE README Rakefile History.txt ] + Dir['lib/**/*'] + Dir['spec/**/*']
# rdoc
s.has_rdoc = false
s.extra_rdoc_files = %w[ LICENSE README History.txt ]
# Dependencies
# s.add_dependency "english", ">=0.2.0"
end
Rake::GemPackageTask.new(spec) do |package|
package.gem_spec = spec
end
desc 'Remove all package, docs and spec products'
task :clobber_all => %w[ clobber_package clobber_doc extlib:clobber_spec ]
##############################################################################
# Specs and continous integration
##############################################################################
task :default => 'extlib:spec'
task :spec => 'extlib:spec'
namespace :extlib do
Spec::Rake::SpecTask.new(:spec) do |t|
t.spec_opts << '--options' << ROOT + 'spec/spec.opts'
t.spec_files = Pathname.glob(ENV['FILES'] || 'spec/**/*_spec.rb').map { |f| f.to_s }
t.libs << 'lib'
begin
gem 'rcov'
t.rcov = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
t.rcov_opts << '--exclude' << 'spec'
t.rcov_opts << '--text-summary'
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
rescue LoadError
# rcov not installed
end
end
end
##############################################################################
# Documentation
##############################################################################
desc "Generate documentation"
task :doc do
begin
require 'yard'
exec 'yardoc'
rescue LoadError
puts 'You will need to install the latest version of Yard to generate the
documentation for extlib.'
end
end
def sudo_gem(cmd)
sh "#{SUDO} #{RUBY} -S gem #{cmd}", :verbose => false
end
desc "Install #{GEM_NAME}"
task :install => :package do
sudo_gem "install --local pkg/#{GEM_NAME}-#{GEM_VERSION}"
end
if WINDOWS
namespace :dev do
desc 'Install for development (for Windows)'
task :winstall => :gem do
system %{gem install --no-rdoc --no-ri -l pkg/#{GEM_NAME}-#{GEM_VERSION}.gem}
end
end
end
namespace :ci do
task :prepare do
rm_rf ROOT + "ci"
mkdir_p ROOT + "ci"
mkdir_p ROOT + "ci/doc"
mkdir_p ROOT + "ci/cyclomatic"
mkdir_p ROOT + "ci/token"
end
task :publish do
out = ENV['CC_BUILD_ARTIFACTS'] || "out"
mkdir_p out unless File.directory? out
mv "ci/rspec_report.html", "#{out}/rspec_report.html"
mv "ci/coverage", "#{out}/coverage"
mv "ci/doc", "#{out}/doc"
mv "ci/cyclomatic", "#{out}/cyclomatic_complexity"
mv "ci/token", "#{out}/token_complexity"
end
task :spec => :prepare do
Rake::Task[:spec].invoke
mv ROOT + "coverage", ROOT + "ci/coverage"
Rake::Task[:gem]
Gem::Installer.new("pkg/#{GEM_NAME}-#{GEM_VERSION}.gem").install
end
task :doc do
require 'yard'
sh 'yardoc'
end
task :saikuro do
system "saikuro -c -i lib -y 0 -w 10 -e 15 -o ci/cyclomatic"
mv 'ci/cyclomatic/index_cyclo.html', 'ci/cyclomatic/index.html'
system "saikuro -t -i lib -y 0 -w 20 -e 30 -o ci/token"
mv 'ci/token/index_token.html', 'ci/token/index.html'
end
end
task :ci => ["ci:spec"]
desc 'Default: run spec examples'
task :default => 'spec'
##############################################################################
# Benchmarks
##############################################################################
namespace :benchmark do
desc "Runs benchmarks"
task :run do
files = Dir["benchmarks/**/*.rb"]
files.each do |f|
system "ruby #{f}"
end
end
end

View file

@ -1,15 +0,0 @@
desc "Publish the release files to RubyForge."
task :release => [ :package ] do
packages = %w( gem tgz zip ).collect{ |ext| "pkg/#{GEM_NAME}-#{GEM_VERSION}.#{ext}" }
begin
sh %{rubyforge login}
sh %{rubyforge add_release #{RUBY_FORGE_PROJECT} #{GEM_NAME} #{GEM_VERSION} #{packages.join(' ')}}
sh %{rubyforge add_file #{RUBY_FORGE_PROJECT} #{GEM_NAME} #{GEM_VERSION} #{packages.join(' ')}}
rescue Exception => e
puts
puts "Release failed: #{e.message}"
puts
puts "Set PKG_BUILD environment variable if you do a subrelease (0.9.4.2008_08_02 when version is 0.9.4)"
end
end

View file

@ -1,3 +0,0 @@
module Extlib
VERSION = '0.9.13'
end

View file

@ -0,0 +1,21 @@
Autotest.add_hook :initialize do |at|
ignore = %w[ .git log plugins script tasks bin CHANGELOG FAQ MIT-LICENSE QUICKLINKS README ]
ignore.each do |exception|
at.add_exception(exception)
end
at.clear_mappings
at.add_mapping(%r{^spec/.+_spec\.rb$}) do |filename,_|
filename
end
at.add_mapping(%r{^lib/extlib/(.+)\.rb$}) do |_,match|
[ "spec/#{match[1]}_spec.rb" ]
end
at.add_mapping(%r{^spec/spec_helper\.rb$}) do
at.files_matching(%r{^spec/.+_spec\.rb$})
end
end

View file

@ -0,0 +1,5 @@
README.rdoc
lib/**/*.rb
bin/*
features/**/*.feature
LICENSE

View file

@ -0,0 +1,22 @@
## MAC OS
.DS_Store
## TEXTMATE
*.tmproj
tmtags
## EMACS
*~
\#*
.\#*
## VIM
*.swp
## PROJECT::GENERAL
coverage
rdoc
pkg
tmp
## PROJECT::SPECIFIC

View file

@ -1,4 +1,4 @@
Copyright (c) 2008 Sam Smoot.
Copyright (c) 2009 Dan Kubb
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View file

@ -0,0 +1,17 @@
= extlib
Support library for DataMapper and Merb.
== Note on Patches/Pull Requests
* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a
future version unintentionally.
* 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)
* Send me a pull request. Bonus points for topic branches.
== Copyright
Copyright (c) 2009 Dan Kubb. See LICENSE for details.

View file

@ -0,0 +1,28 @@
require 'rubygems'
require 'rake'
begin
gem 'jeweler', '~> 1.4'
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = 'extlib'
gem.summary = 'Support library for DataMapper and Merb'
gem.description = gem.summary
gem.email = 'dan.kubb@gmail.com'
gem.homepage = 'http://github.com/datamapper/extlib'
gem.authors = [ 'Dan Kubb' ]
gem.rubyforge_project = 'extlib'
gem.add_development_dependency 'json_pure', '~> 1.2.0'
gem.add_development_dependency 'rspec', '~> 1.2.9'
gem.add_development_dependency 'yard', '~> 0.4.0'
end
Jeweler::GemcutterTasks.new
FileList['tasks/**/*.rake'].each { |task| load task }
rescue LoadError
puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
end

View file

@ -0,0 +1 @@
0.9.14

View file

@ -0,0 +1,146 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{extlib}
s.version = "0.9.14"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Dan Kubb"]
s.date = %q{2009-12-11}
s.description = %q{Support library for DataMapper and Merb}
s.email = %q{dan.kubb@gmail.com}
s.extra_rdoc_files = [
"LICENSE",
"README.rdoc"
]
s.files = [
".autotest",
".document",
".gitignore",
"LICENSE",
"README.rdoc",
"Rakefile",
"VERSION",
"extlib.gemspec",
"lib/extlib.rb",
"lib/extlib/array.rb",
"lib/extlib/assertions.rb",
"lib/extlib/blank.rb",
"lib/extlib/boolean.rb",
"lib/extlib/byte_array.rb",
"lib/extlib/class.rb",
"lib/extlib/datetime.rb",
"lib/extlib/dictionary.rb",
"lib/extlib/hash.rb",
"lib/extlib/hook.rb",
"lib/extlib/inflection.rb",
"lib/extlib/lazy_array.rb",
"lib/extlib/lazy_module.rb",
"lib/extlib/logger.rb",
"lib/extlib/mash.rb",
"lib/extlib/module.rb",
"lib/extlib/nil.rb",
"lib/extlib/numeric.rb",
"lib/extlib/object.rb",
"lib/extlib/object_space.rb",
"lib/extlib/pathname.rb",
"lib/extlib/pooling.rb",
"lib/extlib/rubygems.rb",
"lib/extlib/simple_set.rb",
"lib/extlib/string.rb",
"lib/extlib/struct.rb",
"lib/extlib/symbol.rb",
"lib/extlib/time.rb",
"lib/extlib/virtual_file.rb",
"spec/array_spec.rb",
"spec/blank_spec.rb",
"spec/byte_array_spec.rb",
"spec/class_spec.rb",
"spec/datetime_spec.rb",
"spec/hash_spec.rb",
"spec/hook_spec.rb",
"spec/inflection/plural_spec.rb",
"spec/inflection/singular_spec.rb",
"spec/inflection_extras_spec.rb",
"spec/lazy_array_spec.rb",
"spec/lazy_module_spec.rb",
"spec/mash_spec.rb",
"spec/module_spec.rb",
"spec/object_space_spec.rb",
"spec/object_spec.rb",
"spec/pooling_spec.rb",
"spec/rcov.opts",
"spec/simple_set_spec.rb",
"spec/spec.opts",
"spec/spec_helper.rb",
"spec/string_spec.rb",
"spec/struct_spec.rb",
"spec/symbol_spec.rb",
"spec/time_spec.rb",
"spec/try_call_spec.rb",
"spec/try_dup_spec.rb",
"spec/virtual_file_spec.rb",
"tasks/ci.rake",
"tasks/metrics.rake",
"tasks/spec.rake",
"tasks/yard.rake",
"tasks/yardstick.rake"
]
s.homepage = %q{http://github.com/datamapper/extlib}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{extlib}
s.rubygems_version = %q{1.3.5}
s.summary = %q{Support library for DataMapper and Merb}
s.test_files = [
"spec/array_spec.rb",
"spec/blank_spec.rb",
"spec/byte_array_spec.rb",
"spec/class_spec.rb",
"spec/datetime_spec.rb",
"spec/hash_spec.rb",
"spec/hook_spec.rb",
"spec/inflection/plural_spec.rb",
"spec/inflection/singular_spec.rb",
"spec/inflection_extras_spec.rb",
"spec/lazy_array_spec.rb",
"spec/lazy_module_spec.rb",
"spec/mash_spec.rb",
"spec/module_spec.rb",
"spec/object_space_spec.rb",
"spec/object_spec.rb",
"spec/pooling_spec.rb",
"spec/simple_set_spec.rb",
"spec/spec_helper.rb",
"spec/string_spec.rb",
"spec/struct_spec.rb",
"spec/symbol_spec.rb",
"spec/time_spec.rb",
"spec/try_call_spec.rb",
"spec/try_dup_spec.rb",
"spec/virtual_file_spec.rb"
]
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_development_dependency(%q<json_pure>, ["~> 1.2.0"])
s.add_development_dependency(%q<rspec>, ["~> 1.2.9"])
s.add_development_dependency(%q<yard>, ["~> 0.4.0"])
else
s.add_dependency(%q<json_pure>, ["~> 1.2.0"])
s.add_dependency(%q<rspec>, ["~> 1.2.9"])
s.add_dependency(%q<yard>, ["~> 0.4.0"])
end
else
s.add_dependency(%q<json_pure>, ["~> 1.2.0"])
s.add_dependency(%q<rspec>, ["~> 1.2.9"])
s.add_dependency(%q<yard>, ["~> 0.4.0"])
end
end

View file

@ -28,8 +28,8 @@
class Class
# Defines class-level and instance-level attribute reader.
#
# @param *syms<Array> Array of attributes to define reader for.
# @return <Array[#to_s]> List of attributes that were made into cattr_readers
# @param [*syms<Array] Array of attributes to define reader for.
# @return [Array<#to_s>] List of attributes that were made into cattr_readers
#
# @api public
#
@ -56,9 +56,9 @@ class Class
# Defines class-level (and optionally instance-level) attribute writer.
#
# @param <Array[*#to_s, Hash{:instance_writer => Boolean}]> Array of attributes to define writer for.
# @param [Array<*#to_s, Hash{:instance_writer => Boolean}>] Array of attributes to define writer for.
# @option syms :instance_writer<Boolean> if true, instance-level attribute writer is defined.
# @return <Array[#to_s]> List of attributes that were made into cattr_writers
# @return [Array<#to_s>] List of attributes that were made into cattr_writers
#
# @api public
def cattr_writer(*syms)
@ -88,7 +88,7 @@ class Class
#
# @param *syms<Array[*#to_s, Hash{:instance_writer => Boolean}]> Array of attributes to define accessor for.
# @option syms :instance_writer<Boolean> if true, instance-level attribute writer is defined.
# @return <Array[#to_s]> List of attributes that were made into accessors
# @return [Array<#to_s>] List of attributes that were made into accessors
#
# @api public
def cattr_accessor(*syms)
@ -100,7 +100,7 @@ class Class
# each subclass has a copy of parent's attribute.
#
# @param *syms<Array[#to_s]> Array of attributes to define inheritable reader for.
# @return <Array[#to_s]> Array of attributes converted into inheritable_readers.
# @return [Array<#to_s>] Array of attributes converted into inheritable_readers.
#
# @api public
#
@ -139,7 +139,7 @@ class Class
# @param *syms<Array[*#to_s, Hash{:instance_writer => Boolean}]> Array of attributes to
# define inheritable writer for.
# @option syms :instance_writer<Boolean> if true, instance-level inheritable attribute writer is defined.
# @return <Array[#to_s]> An Array of the attributes that were made into inheritable writers.
# @return [Array<#to_s>] An Array of the attributes that were made into inheritable writers.
#
# @api public
#
@ -167,7 +167,7 @@ class Class
# @param *syms<Array[*#to_s, Hash{:instance_writer => Boolean}]> Array of attributes to
# define inheritable accessor for.
# @option syms :instance_writer<Boolean> if true, instance-level inheritable attribute writer is defined.
# @return <Array[#to_s]> An Array of attributes turned into inheritable accessors.
# @return [Array<#to_s>] An Array of attributes turned into inheritable accessors.
#
# @api public
def class_inheritable_accessor(*syms)

View file

@ -115,7 +115,7 @@ class Hash
# @param [Object] key The key for the param.
# @param [Object] value The value for the param.
#
# @return <String> This key value pair as a param
# @return [String] This key value pair as a param
#
# @api public
def normalize_param(key, value)
@ -176,7 +176,7 @@ class Hash
hash
end
# @return <String> The hash as attributes for an XML tag.
# @return [String] The hash as attributes for an XML tag.
#
# @example
# { :one => 1, "two"=>"TWO" }.to_xml_attributes
@ -209,7 +209,7 @@ class Hash
# Converts all keys into string values. This is used during reloading to
# prevent problems when classes are no longer declared.
#
# @return <Array> An array of they hash's keys
# @return [Array] An array of they hash's keys
#
# @example
# hash = { One => 1, Two => 2 }.proctect_keys!
@ -234,7 +234,7 @@ class Hash
# Destructively and non-recursively convert each key to an uppercase string,
# deleting nil values along the way.
#
# @return <Hash> The newly environmentized hash.
# @return [Hash] The newly environmentized hash.
#
# @example
# { :name => "Bob", :contact => { :email => "bob@bob.com" } }.environmentize_keys!
@ -361,7 +361,7 @@ class REXMLUtilityNode
# "date"::
# Parses +value+ using Date.parse
#
# @return <Integer, TrueClass, FalseClass, Time, Date, Object>
# @return [Integer, Boolean, Time, Date, Object]
# The result of typecasting +value+.
#
# @note
@ -377,7 +377,7 @@ class REXMLUtilityNode
#
# @param value<#gsub> An XML fragment.
#
# @return <#gsub> The XML fragment after converting entities.
# @return [#gsub] The XML fragment after converting entities.
def translate_xml_entities(value)
value.gsub(/&lt;/, "<").
gsub(/&gt;/, ">").
@ -401,7 +401,7 @@ class REXMLUtilityNode
# Converts the node into a readable HTML node.
#
# @return <String> The HTML node in text form.
# @return [String] The HTML node in text form.
def to_html
attributes.merge!(:type => @type ) if @type
"<#{name}#{attributes.to_xml_attributes}>#{@nil_element ? '' : inner_html}</#{name}>"

View file

@ -10,10 +10,13 @@ module Extlib
#
# @example
# "egg_and_hams".classify #=> "EggAndHam"
# "enlarged_testes".classify #=> "EnlargedTestis"
# "post".classify #=> "Post"
#
def classify(name)
camelize(singularize(name.to_s.sub(/.*\./, '')))
words = name.to_s.sub(/.*\./, '').split('_')
words[-1] = singularize(words[-1])
words.collect { |word| word.capitalize }.join
end
# By default, camelize converts strings to UpperCamelCase.
@ -48,7 +51,7 @@ module Extlib
# "employee_salary" #=> "Employee salary"
# "author_id" #=> "Author"
def humanize(lower_case_and_underscored_word)
lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize
lower_case_and_underscored_word.to_s.gsub(/_id$/, '').tr('_', ' ').capitalize
end
# Removes the module part from the expression in the string
@ -65,10 +68,13 @@ module Extlib
#
# @example
# "RawScaledScorer".tableize #=> "raw_scaled_scorers"
# "EnlargedTestis".tableize #=> "enlarged_testes"
# "egg_and_ham".tableize #=> "egg_and_hams"
# "fancyCategory".tableize #=> "fancy_categories"
def tableize(class_name)
pluralize(class_name.to_const_path.gsub(/\//, '_'))
words = class_name.to_const_path.tr('/', '_').split('_')
words[-1] = pluralize(words[-1])
words.join('_')
end
# Creates a foreign key name from a class name.
@ -253,7 +259,7 @@ module Extlib
attr_reader :singular_of, :plural_of
# Convert an English word from plurel to singular.
# Convert an English word from plural to singular.
#
# "boys".singular #=> boy
# "tomatoes".singular #=> tomato
@ -281,7 +287,7 @@ module Extlib
#
alias_method(:singularize, :singular)
# Convert an English word from singular to plurel.
# Convert an English word from singular to plural.
#
# "boy".plural #=> boys
# "tomato".plural #=> tomatoes

View file

@ -1,5 +1,5 @@
class LazyArray # borrowed partially from StrokeDB
instance_methods.each { |m| undef_method m unless %w[ __id__ __send__ send class dup object_id kind_of? respond_to? equal? assert_kind_of should should_not instance_variable_set instance_variable_get extend ].include?(m.to_s) }
include Enumerable
attr_reader :head, :tail
@ -82,7 +82,11 @@ class LazyArray # borrowed partially from StrokeDB
end
def empty?
!any?
(@tail.nil? || @tail.empty?) &&
(@head.nil? || @head.empty?) && begin
lazy_load
@array.empty?
end
end
def any?(&block)
@ -214,21 +218,21 @@ class LazyArray # borrowed partially from StrokeDB
self
end
def pop
if lazy_possible?(@tail)
@tail.pop
def pop(*args)
if lazy_possible?(@tail, *args)
@tail.pop(*args)
else
lazy_load
@array.pop
@array.pop(*args)
end
end
def shift
if lazy_possible?(@head)
@head.shift
def shift(*args)
if lazy_possible?(@head, *args)
@head.shift(*args)
else
lazy_load
@array.shift
@array.shift(*args)
end
end
@ -401,6 +405,16 @@ class LazyArray # borrowed partially from StrokeDB
raise ArgumentError, "arguments may be 1 or 2 Integers, or 1 Range object, was: #{args.inspect}", caller(1)
end
def each
lazy_load
if block_given?
@array.each { |entry| yield entry }
self
else
@array.each
end
end
# delegate any not-explicitly-handled methods to @array, if possible.
# this is handy for handling methods mixed-into Array like group_by
def method_missing(method, *args, &block)
@ -419,14 +433,14 @@ class LazyArray # borrowed partially from StrokeDB
# 0 and incrementally compare each entry. if other is a LazyArray
# this has a lesser likelyhood of triggering a lazy load
0.upto(@head.size - 1) do |i|
return false unless @head[i].send(operator, other[i])
return false unless @head[i].__send__(operator, other[i])
end
# compare the tail against the end of other. start at index
# -1 and decrementally compare each entry. if other is a LazyArray
# this has a lesser likelyhood of triggering a lazy load
-1.downto(@tail.size * -1) do |i|
return false unless @tail[i].send(operator, other[i])
return false unless @tail[i].__send__(operator, other[i])
end
lazy_load
@ -434,24 +448,4 @@ class LazyArray # borrowed partially from StrokeDB
@array.send(operator, other.to_ary)
end
# add proxies for all remaining Array and Enumerable methods
(Array.public_instance_methods(false) | Enumerable.public_instance_methods(false)).each do |method|
next if public_method_defined?(method)
target = if method.to_s[-1, 1] == '='
"send(:#{method}, *args, &block)"
else
"#{method}(*args, &block)"
end
class_eval <<-RUBY, __FILE__, __LINE__ + 1
public
def #{method}(*args, &block) # def []=(*args, &block)
lazy_load # lazy_load
results = @array.#{target} # results = @array.send(:[]=, *args, &block)
results.equal?(@array) ? self : results # results.equal?(@array) ? self : results
end # end
RUBY
end
end

View file

@ -47,7 +47,7 @@ class Mash < Hash
# A hash to update values in the mash with. The keys and the values will be
# converted to Mash format.
#
# @return <Mash> The updated mash.
# @return [Mash] The updated mash.
def update(other_hash)
other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
self
@ -57,7 +57,7 @@ class Mash < Hash
# @param key<Object> The key to check for. This will be run through convert_key.
#
# @return <TrueClass, FalseClass> True if the key exists in the mash.
# @return [Boolean] True if the key exists in the mash.
def key?(key)
super(convert_key(key))
end
@ -70,7 +70,7 @@ class Mash < Hash
# @param key<Object> The key to fetch. This will be run through convert_key.
# @param *extras<Array> Default value.
#
# @return <Object> The value at key or the default value.
# @return [Object] The value at key or the default value.
def fetch(key, *extras)
super(convert_key(key), *extras)
end
@ -78,14 +78,14 @@ class Mash < Hash
# @param *indices<Array>
# The keys to retrieve values for. These will be run through +convert_key+.
#
# @return <Array> The values at each of the provided keys
# @return [Array] The values at each of the provided keys
def values_at(*indices)
indices.collect {|key| self[convert_key(key)]}
end
# @param hash<Hash> The hash to merge with the mash.
#
# @return <Mash> A new mash with the hash values merged in.
# @return [Mash] A new mash with the hash values merged in.
def merge(hash)
self.dup.update(hash)
end
@ -98,7 +98,7 @@ class Mash < Hash
# @param *rejected<Array[(String, Symbol)] The mash keys to exclude.
#
# @return <Mash> A new mash without the selected keys.
# @return [Mash] A new mash without the selected keys.
#
# @example
# { :one => 1, :two => 2, :three => 3 }.except(:one)
@ -109,17 +109,17 @@ class Mash < Hash
# Used to provide the same interface as Hash.
#
# @return <Mash> This mash unchanged.
# @return [Mash] This mash unchanged.
def stringify_keys!; self end
# @return <Hash> The mash as a Hash with symbolized keys.
# @return [Hash] The mash as a Hash with symbolized keys.
def symbolize_keys
h = Hash.new(default)
each { |key, val| h[key.to_sym] = val }
h
end
# @return <Hash> The mash as a Hash with string keys.
# @return [Hash] The mash as a Hash with string keys.
def to_hash
Hash.new(default).merge(self)
end
@ -127,7 +127,7 @@ class Mash < Hash
protected
# @param key<Object> The key to convert.
#
# @param <Object>
# @param [Object]
# The converted key. If the key was a symbol, it will be converted to a
# string.
#
@ -138,7 +138,7 @@ class Mash < Hash
# @param value<Object> The value to convert.
#
# @return <Object>
# @return [Object]
# The converted value. A Hash or an Array of hashes, will be converted to
# their Mash equivalents.
#

View file

@ -1,7 +1,7 @@
class Object
# Extracts the singleton class, so that metaprogramming can be done on it.
#
# @return <Class> The meta class.
# @return [Class] The meta class.
#
# @example [Setup]
# class MyString < String; end
@ -60,7 +60,7 @@ class Object
# @param name<String> The name of the constant to get, e.g. "Merb::Router".
#
# @return <Object> The constant corresponding to the name.
# @return [Object] The constant corresponding to the name.
def full_const_get(name)
list = name.split("::")
list.shift if list.first.blank?
@ -76,7 +76,7 @@ class Object
# @param name<String> The name of the constant to get, e.g. "Merb::Router".
# @param value<Object> The value to assign to the constant.
#
# @return <Object> The constant corresponding to the name.
# @return [Object] The constant corresponding to the name.
def full_const_set(name, value)
list = name.split("::")
toplevel = list.first.blank?
@ -91,7 +91,7 @@ class Object
#
# @param name<String> The name of the full module name to make
#
# @return <NilClass>
# @return [nil]
def make_module(str)
mod = str.split("::")
current_module = self
@ -114,7 +114,7 @@ class Object
# Check whether the object quacks_like? at least one of the options in the
# array.
#
# @return <TrueClass, FalseClass>
# @return [Boolean]
# True if the object quacks like duck.
def quacks_like?(duck)
case duck
@ -131,7 +131,7 @@ class Object
# Override this in a child if it cannot be dup'ed
#
# @return <Object>
# @return [Object]
def try_dup
self.dup
end
@ -140,7 +140,7 @@ class Object
# returns result. If not, just returns receiver
# itself
#
# @return <Object>
# @return [Object]
def try_call(*args)
if self.respond_to?(:call)
self.call(*args)
@ -152,7 +152,7 @@ class Object
# @param arrayish<#include?> Container to check, to see if it includes the object.
# @param *more<Array>:: additional args, will be flattened into arrayish
#
# @return <TrueClass, FalseClass>
# @return [Boolean]
# True if the object is included in arrayish (+ more)
#
# @example 1.in?([1,2,3]) #=> true
@ -165,7 +165,7 @@ class Object
# Add instance_variable_defined? for backward compatibility
# @param variable<Symbol, String>
#
# @return <TrueClass, FalseClass>
# @return [Boolean]
# True if the object has the given instance variable defined
unless respond_to?(:instance_variable_defined?)
def instance_variable_defined?(variable)

View file

@ -2,7 +2,7 @@ module ObjectSpace
class << self
# @return <Array[Class]> All the classes in the object space.
# @return [Array<Class>] All the classes in the object space.
def classes
klasses = []
ObjectSpace.each_object(Class) {|o| klasses << o}

View file

@ -30,7 +30,7 @@ module Gem
# from any other location. If there are two gems of different versions in
# the gems directory, the later one will load as usual.
#
# @return <Array[Array]> The object used for sorting gem specs.
# @return [Array<Array>] The object used for sorting gem specs.
def sort_obj
[@name, installation_path == File.join(defined?(Merb) && Merb.respond_to?(:root) ? Merb.root : Dir.pwd,"gems") ? 1 : -1, @version.to_ints, @new_platform == Gem::Platform::RUBY ? -1 : 1]
end

View file

@ -36,9 +36,10 @@ class String
#
# @api public
def snake_case
return self.downcase if self =~ /^[A-Z]+$/
self.gsub(/([A-Z]+)(?=[A-Z][a-z]?)|\B[A-Z]/, '_\&') =~ /_*(.*)/
return $+.downcase
return downcase if match(/\A[A-Z]+\z/)
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
gsub(/([a-z])([A-Z])/, '\1_\2').
downcase
end
##

View file

@ -2,10 +2,14 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
describe Extlib::Inflection do
describe "#classify" do
it 'classifies data_mapper as DataMaper' do
it 'classifies data_mapper as DataMapper' do
Extlib::Inflection.classify('data_mapper').should == 'DataMapper'
end
it "classifies enlarged_testes as EnlargedTestis" do
Extlib::Inflection.classify('enlarged_testes').should == 'EnlargedTestis'
end
it "singularizes string first: classifies data_mappers as egg_and_hams as EggAndHam" do
Extlib::Inflection.classify('egg_and_hams').should == 'EggAndHam'
end
@ -72,13 +76,26 @@ describe Extlib::Inflection do
Extlib::Inflection.tableize('fancy_category').should == 'fancy_categories'
end
it 'underscores CamelCase strings before pluralization: enlarged_testis => enlarged_testes' do
Extlib::Inflection.tableize('enlarged_testis').should == 'enlarged_testes'
end
it 'underscores CamelCase strings before pluralization: FancyCategory => fancy_categories' do
Extlib::Inflection.tableize('FancyCategory').should == 'fancy_categories'
end
it 'underscores CamelCase strings before pluralization: EnlargedTestis => enlarged_testes' do
Extlib::Inflection.tableize('EnlargedTestis').should == 'enlarged_testes'
end
it 'replaces :: with underscores: Fancy::Category => fancy_categories' do
Extlib::Inflection.tableize('Fancy::Category').should == 'fancy_categories'
end
it 'underscores CamelCase strings before pluralization: Enlarged::Testis => enlarged_testes' do
Extlib::Inflection.tableize('Enlarged::Testis').should == 'enlarged_testes'
end
end
describe "#foreign_key" do

View file

@ -146,6 +146,10 @@ end
subject { @lazy_array }
it 'should be an Enumerable' do
(Enumerable === subject).should be_true
end
describe 'when frozen', state do
before { subject.freeze }
@ -551,6 +555,17 @@ end
should_be_a_kicker
should_not_change_subject
end
describe 'when the subject has only nil entries' do
subject { LazyArray.new << nil }
action { subject.empty? }
should_return_false
should_not_be_a_kicker
should_not_change_subject
end
end
[ :eql?, :== ].each do |method|
@ -976,6 +991,16 @@ end
end
end
should_respond_to(:nil?)
describe '#nil?' do
action { subject.nil? }
should_return_expected_value { false }
should_not_be_a_kicker
end
should_respond_to(:pop)
describe '#pop', state do

View file

@ -0,0 +1,6 @@
--exclude "spec"
--sort coverage
--callsites
--xrefs
--profile
--text-summary

View file

@ -1,3 +1,4 @@
--colour
--loadby random
--format profile
--backtrace

View file

@ -77,6 +77,7 @@ describe String, "#snake_case" do
"CNN".snake_case.should == "cnn"
"CNNNews".snake_case.should == "cnn_news"
"HeadlineCNNNews".snake_case.should == "headline_cnn_news"
"NameACRONYM".snake_case.should == "name_acronym"
end
it "does NOT change one word lowercase" do

Some files were not shown because too many files have changed in this diff Show more