esod-client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/EXAMPLES +140 -0
- data/GEM_RELEASE +19 -0
- data/README +10 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/esod-client.gemspec +118 -0
- data/esod-client.rb +35 -0
- data/lib/activesupport-2.2.2/CHANGELOG +1257 -0
- data/lib/activesupport-2.2.2/README +43 -0
- data/lib/activesupport-2.2.2/README.CFT +2 -0
- data/lib/activesupport-2.2.2/lib/active_support.rb +26 -0
- data/lib/activesupport-2.2.2/lib/active_support/base64.rb +33 -0
- data/lib/activesupport-2.2.2/lib/active_support/basic_object.rb +24 -0
- data/lib/activesupport-2.2.2/lib/active_support/buffered_logger.rb +122 -0
- data/lib/activesupport-2.2.2/lib/active_support/cache.rb +223 -0
- data/lib/activesupport-2.2.2/lib/active_support/cache/compressed_mem_cache_store.rb +20 -0
- data/lib/activesupport-2.2.2/lib/active_support/cache/drb_store.rb +15 -0
- data/lib/activesupport-2.2.2/lib/active_support/cache/file_store.rb +72 -0
- data/lib/activesupport-2.2.2/lib/active_support/cache/mem_cache_store.rb +127 -0
- data/lib/activesupport-2.2.2/lib/active_support/cache/memory_store.rb +52 -0
- data/lib/activesupport-2.2.2/lib/active_support/cache/synchronized_memory_store.rb +47 -0
- data/lib/activesupport-2.2.2/lib/active_support/callbacks.rb +280 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext.rb +6 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash.rb +14 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/conversions.rb +259 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/deep_merge.rb +23 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/diff.rb +19 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/except.rb +25 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/indifferent_access.rb +137 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/keys.rb +52 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/reverse_merge.rb +35 -0
- data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/slice.rb +33 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor.rb +14 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/blankslate.rb +113 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder.rb +13 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +20 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/css.rb +250 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb +115 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb +139 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +63 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb +328 -0
- data/lib/activesupport-2.2.2/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb +1021 -0
- data/lib/activesupport-2.2.2/lib/activesupport.rb +1 -0
- data/lib/esodclient/esodclient.rb +22 -0
- data/lib/hash.rb +22 -0
- data/lib/mime-types-1.16/History.txt +107 -0
- data/lib/mime-types-1.16/Install.txt +17 -0
- data/lib/mime-types-1.16/Licence.txt +15 -0
- data/lib/mime-types-1.16/Manifest.txt +12 -0
- data/lib/mime-types-1.16/README.txt +28 -0
- data/lib/mime-types-1.16/Rakefile +316 -0
- data/lib/mime-types-1.16/lib/mime/types.rb +751 -0
- data/lib/mime-types-1.16/lib/mime/types.rb.data +1324 -0
- data/lib/mime-types-1.16/mime-types.gemspec +43 -0
- data/lib/mime-types-1.16/setup.rb +1585 -0
- data/lib/mime-types-1.16/test/test_mime_type.rb +356 -0
- data/lib/mime-types-1.16/test/test_mime_types.rb +122 -0
- data/lib/rest-client-1.2.0/README.rdoc +102 -0
- data/lib/rest-client-1.2.0/Rakefile +57 -0
- data/lib/rest-client-1.2.0/VERSION +1 -0
- data/lib/rest-client-1.2.0/bin/restclient +87 -0
- data/lib/rest-client-1.2.0/lib/rest_client.rb +2 -0
- data/lib/rest-client-1.2.0/lib/restclient.rb +108 -0
- data/lib/rest-client-1.2.0/lib/restclient/exceptions.rb +89 -0
- data/lib/rest-client-1.2.0/lib/restclient/mixin/response.rb +48 -0
- data/lib/rest-client-1.2.0/lib/restclient/net_http_ext.rb +21 -0
- data/lib/rest-client-1.2.0/lib/restclient/payload.rb +178 -0
- data/lib/rest-client-1.2.0/lib/restclient/raw_response.rb +30 -0
- data/lib/rest-client-1.2.0/lib/restclient/request.rb +287 -0
- data/lib/rest-client-1.2.0/lib/restclient/resource.rb +146 -0
- data/lib/rest-client-1.2.0/lib/restclient/response.rb +20 -0
- data/lib/rest-client-1.2.0/spec/base.rb +10 -0
- data/lib/rest-client-1.2.0/spec/exceptions_spec.rb +65 -0
- data/lib/rest-client-1.2.0/spec/master_shake.jpg +0 -0
- data/lib/rest-client-1.2.0/spec/mixin/response_spec.rb +46 -0
- data/lib/rest-client-1.2.0/spec/payload_spec.rb +131 -0
- data/lib/rest-client-1.2.0/spec/raw_response_spec.rb +17 -0
- data/lib/rest-client-1.2.0/spec/request_spec.rb +521 -0
- data/lib/rest-client-1.2.0/spec/resource_spec.rb +75 -0
- data/lib/rest-client-1.2.0/spec/response_spec.rb +21 -0
- data/lib/rest-client-1.2.0/spec/restclient_spec.rb +53 -0
- data/lib/trollop/trollop.rb +735 -0
- metadata +137 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
module ActiveSupport #:nodoc:
|
2
|
+
module CoreExtensions #:nodoc:
|
3
|
+
module Hash #:nodoc:
|
4
|
+
module Keys
|
5
|
+
# Return a new hash with all keys converted to strings.
|
6
|
+
def stringify_keys
|
7
|
+
inject({}) do |options, (key, value)|
|
8
|
+
options[key.to_s] = value
|
9
|
+
options
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Destructively convert all keys to strings.
|
14
|
+
def stringify_keys!
|
15
|
+
keys.each do |key|
|
16
|
+
self[key.to_s] = delete(key)
|
17
|
+
end
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
# Return a new hash with all keys converted to symbols.
|
22
|
+
def symbolize_keys
|
23
|
+
inject({}) do |options, (key, value)|
|
24
|
+
options[(key.to_sym rescue key) || key] = value
|
25
|
+
options
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Destructively convert all keys to symbols.
|
30
|
+
def symbolize_keys!
|
31
|
+
self.replace(self.symbolize_keys)
|
32
|
+
end
|
33
|
+
|
34
|
+
alias_method :to_options, :symbolize_keys
|
35
|
+
alias_method :to_options!, :symbolize_keys!
|
36
|
+
|
37
|
+
# Validate all keys in a hash match *valid keys, raising ArgumentError on a mismatch.
|
38
|
+
# Note that keys are NOT treated indifferently, meaning if you use strings for keys but assert symbols
|
39
|
+
# as keys, this will fail.
|
40
|
+
#
|
41
|
+
# ==== Examples:
|
42
|
+
# { :name => "Rob", :years => "28" }.assert_valid_keys(:name, :age) # => raises "ArgumentError: Unknown key(s): years"
|
43
|
+
# { :name => "Rob", :age => "28" }.assert_valid_keys("name", "age") # => raises "ArgumentError: Unknown key(s): name, age"
|
44
|
+
# { :name => "Rob", :age => "28" }.assert_valid_keys(:name, :age) # => passes, raises nothing
|
45
|
+
def assert_valid_keys(*valid_keys)
|
46
|
+
unknown_keys = keys - [valid_keys].flatten
|
47
|
+
raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module ActiveSupport #:nodoc:
|
2
|
+
module CoreExtensions #:nodoc:
|
3
|
+
module Hash #:nodoc:
|
4
|
+
# Allows for reverse merging two hashes where the keys in the calling hash take precedence over those
|
5
|
+
# in the <tt>other_hash</tt>. This is particularly useful for initializing an option hash with default values:
|
6
|
+
#
|
7
|
+
# def setup(options = {})
|
8
|
+
# options.reverse_merge! :size => 25, :velocity => 10
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# Using <tt>merge</tt>, the above example would look as follows:
|
12
|
+
#
|
13
|
+
# def setup(options = {})
|
14
|
+
# { :size => 25, :velocity => 10 }.merge(options)
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# The default <tt>:size</tt> and <tt>:velocity</tt> are only set if the +options+ hash passed in doesn't already
|
18
|
+
# have the respective key.
|
19
|
+
module ReverseMerge
|
20
|
+
# Performs the opposite of <tt>merge</tt>, with the keys and values from the first hash taking precedence over the second.
|
21
|
+
def reverse_merge(other_hash)
|
22
|
+
other_hash.merge(self)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Performs the opposite of <tt>merge</tt>, with the keys and values from the first hash taking precedence over the second.
|
26
|
+
# Modifies the receiver in place.
|
27
|
+
def reverse_merge!(other_hash)
|
28
|
+
replace(reverse_merge(other_hash))
|
29
|
+
end
|
30
|
+
|
31
|
+
alias_method :reverse_update, :reverse_merge!
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ActiveSupport #:nodoc:
|
2
|
+
module CoreExtensions #:nodoc:
|
3
|
+
module Hash #:nodoc:
|
4
|
+
# Slice a hash to include only the given keys. This is useful for
|
5
|
+
# limiting an options hash to valid keys before passing to a method:
|
6
|
+
#
|
7
|
+
# def search(criteria = {})
|
8
|
+
# assert_valid_keys(:mass, :velocity, :time)
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# search(options.slice(:mass, :velocity, :time))
|
12
|
+
#
|
13
|
+
# If you have an array of keys you want to limit to, you should splat them:
|
14
|
+
#
|
15
|
+
# valid_keys = [:mass, :velocity, :time]
|
16
|
+
# search(options.slice(*valid_keys))
|
17
|
+
module Slice
|
18
|
+
# Returns a new hash with only the given keys.
|
19
|
+
def slice(*keys)
|
20
|
+
keys = keys.map! { |key| convert_key(key) } if respond_to?(:convert_key)
|
21
|
+
hash = self.class.new
|
22
|
+
keys.each { |k| hash[k] = self[k] if has_key?(k) }
|
23
|
+
hash
|
24
|
+
end
|
25
|
+
|
26
|
+
# Replaces the hash with only the given keys.
|
27
|
+
def slice!(*keys)
|
28
|
+
replace(slice(*keys))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Prefer gems to the bundled libs.
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
begin
|
5
|
+
gem 'builder', '~> 2.1.2'
|
6
|
+
rescue Gem::LoadError
|
7
|
+
$:.unshift "#{File.dirname(__FILE__)}/vendor/builder-2.1.2"
|
8
|
+
end
|
9
|
+
|
10
|
+
begin
|
11
|
+
gem 'xml-simple', '~> 1.0.11'
|
12
|
+
rescue Gem::LoadError
|
13
|
+
$:.unshift "#{File.dirname(__FILE__)}/vendor/xml-simple-1.0.11"
|
14
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#--
|
3
|
+
# Copyright 2004, 2006 by Jim Weirich (jim@weirichhouse.org).
|
4
|
+
# All rights reserved.
|
5
|
+
|
6
|
+
# Permission is granted for use, copying, modification, distribution,
|
7
|
+
# and distribution of modified versions of this work as long as the
|
8
|
+
# above copyright notice is included.
|
9
|
+
#++
|
10
|
+
|
11
|
+
######################################################################
|
12
|
+
# BlankSlate provides an abstract base class with no predefined
|
13
|
+
# methods (except for <tt>\_\_send__</tt> and <tt>\_\_id__</tt>).
|
14
|
+
# BlankSlate is useful as a base class when writing classes that
|
15
|
+
# depend upon <tt>method_missing</tt> (e.g. dynamic proxies).
|
16
|
+
#
|
17
|
+
class BlankSlate
|
18
|
+
class << self
|
19
|
+
|
20
|
+
# Hide the method named +name+ in the BlankSlate class. Don't
|
21
|
+
# hide +instance_eval+ or any method beginning with "__".
|
22
|
+
def hide(name)
|
23
|
+
if instance_methods.include?(name.to_s) and
|
24
|
+
name !~ /^(__|instance_eval)/
|
25
|
+
@hidden_methods ||= {}
|
26
|
+
@hidden_methods[name.to_sym] = instance_method(name)
|
27
|
+
undef_method name
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def find_hidden_method(name)
|
32
|
+
@hidden_methods ||= {}
|
33
|
+
@hidden_methods[name] || superclass.find_hidden_method(name)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Redefine a previously hidden method so that it may be called on a blank
|
37
|
+
# slate object.
|
38
|
+
def reveal(name)
|
39
|
+
bound_method = nil
|
40
|
+
unbound_method = find_hidden_method(name)
|
41
|
+
fail "Don't know how to reveal method '#{name}'" unless unbound_method
|
42
|
+
define_method(name) do |*args|
|
43
|
+
bound_method ||= unbound_method.bind(self)
|
44
|
+
bound_method.call(*args)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
instance_methods.each { |m| hide(m) }
|
50
|
+
end
|
51
|
+
|
52
|
+
######################################################################
|
53
|
+
# Since Ruby is very dynamic, methods added to the ancestors of
|
54
|
+
# BlankSlate <em>after BlankSlate is defined</em> will show up in the
|
55
|
+
# list of available BlankSlate methods. We handle this by defining a
|
56
|
+
# hook in the Object and Kernel classes that will hide any method
|
57
|
+
# defined after BlankSlate has been loaded.
|
58
|
+
#
|
59
|
+
module Kernel
|
60
|
+
class << self
|
61
|
+
alias_method :blank_slate_method_added, :method_added
|
62
|
+
|
63
|
+
# Detect method additions to Kernel and remove them in the
|
64
|
+
# BlankSlate class.
|
65
|
+
def method_added(name)
|
66
|
+
result = blank_slate_method_added(name)
|
67
|
+
return result if self != Kernel
|
68
|
+
BlankSlate.hide(name)
|
69
|
+
result
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
######################################################################
|
75
|
+
# Same as above, except in Object.
|
76
|
+
#
|
77
|
+
class Object
|
78
|
+
class << self
|
79
|
+
alias_method :blank_slate_method_added, :method_added
|
80
|
+
|
81
|
+
# Detect method additions to Object and remove them in the
|
82
|
+
# BlankSlate class.
|
83
|
+
def method_added(name)
|
84
|
+
result = blank_slate_method_added(name)
|
85
|
+
return result if self != Object
|
86
|
+
BlankSlate.hide(name)
|
87
|
+
result
|
88
|
+
end
|
89
|
+
|
90
|
+
def find_hidden_method(name)
|
91
|
+
nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
######################################################################
|
97
|
+
# Also, modules included into Object need to be scanned and have their
|
98
|
+
# instance methods removed from blank slate. In theory, modules
|
99
|
+
# included into Kernel would have to be removed as well, but a
|
100
|
+
# "feature" of Ruby prevents late includes into modules from being
|
101
|
+
# exposed in the first place.
|
102
|
+
#
|
103
|
+
class Module
|
104
|
+
alias blankslate_original_append_features append_features
|
105
|
+
def append_features(mod)
|
106
|
+
result = blankslate_original_append_features(mod)
|
107
|
+
return result if mod != Object
|
108
|
+
instance_methods.each do |name|
|
109
|
+
BlankSlate.hide(name)
|
110
|
+
end
|
111
|
+
result
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright 2004 by Jim Weirich (jim@weirichhouse.org).
|
5
|
+
# All rights reserved.
|
6
|
+
|
7
|
+
# Permission is granted for use, copying, modification, distribution,
|
8
|
+
# and distribution of modified versions of this work as long as the
|
9
|
+
# above copyright notice is included.
|
10
|
+
#++
|
11
|
+
|
12
|
+
require 'builder/xmlmarkup'
|
13
|
+
require 'builder/xmlevents'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#--
|
3
|
+
# Copyright 2004, 2006 by Jim Weirich (jim@weirichhouse.org).
|
4
|
+
# All rights reserved.
|
5
|
+
|
6
|
+
# Permission is granted for use, copying, modification, distribution,
|
7
|
+
# and distribution of modified versions of this work as long as the
|
8
|
+
# above copyright notice is included.
|
9
|
+
#++
|
10
|
+
|
11
|
+
require 'blankslate'
|
12
|
+
|
13
|
+
######################################################################
|
14
|
+
# BlankSlate has been promoted to a top level name and is now
|
15
|
+
# available as a standalone gem. We make the name available in the
|
16
|
+
# Builder namespace for compatibility.
|
17
|
+
#
|
18
|
+
module Builder
|
19
|
+
BlankSlate = ::BlankSlate
|
20
|
+
end
|
@@ -0,0 +1,250 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#--
|
3
|
+
# Copyright 2004, 2005 by Jim Weirich (jim@weirichhouse.org).
|
4
|
+
# Copyright 2005 by Scott Barron (scott@elitists.net).
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# Permission is granted for use, copying, modification, distribution,
|
8
|
+
# and distribution of modified versions of this work as long as the
|
9
|
+
# above copyright notice is included.
|
10
|
+
#
|
11
|
+
# Much of this is taken from Jim's work in xmlbase.rb and xmlmarkup.rb.
|
12
|
+
# Documentation has also been copied and pasted and modified to reflect
|
13
|
+
# that we're building CSS here instead of XML. Jim is conducting the
|
14
|
+
# orchestra here and I'm just off in the corner playing a flute.
|
15
|
+
#++
|
16
|
+
|
17
|
+
# Provide a flexible and easy to use Builder for creating Cascading
|
18
|
+
# Style Sheets (CSS).
|
19
|
+
|
20
|
+
|
21
|
+
require 'builder/blankslate'
|
22
|
+
|
23
|
+
module Builder
|
24
|
+
|
25
|
+
# Create a Cascading Style Sheet (CSS) using Ruby.
|
26
|
+
#
|
27
|
+
# Example usage:
|
28
|
+
#
|
29
|
+
# css = Builder::CSS.new
|
30
|
+
#
|
31
|
+
# text_color = '#7F7F7F'
|
32
|
+
# preferred_fonts = 'Helvetica, Arial, sans_serif'
|
33
|
+
#
|
34
|
+
# css.comment! 'This is our stylesheet'
|
35
|
+
# css.body {
|
36
|
+
# background_color '#FAFAFA'
|
37
|
+
# font_size 'small'
|
38
|
+
# font_family preferred_fonts
|
39
|
+
# color text_color
|
40
|
+
# }
|
41
|
+
#
|
42
|
+
# css.id!('navbar') {
|
43
|
+
# width '500px'
|
44
|
+
# }
|
45
|
+
#
|
46
|
+
# css.class!('navitem') {
|
47
|
+
# color 'red'
|
48
|
+
# }
|
49
|
+
#
|
50
|
+
# css.a :hover {
|
51
|
+
# text_decoration 'underline'
|
52
|
+
# }
|
53
|
+
#
|
54
|
+
# css.div(:id => 'menu') {
|
55
|
+
# background 'green'
|
56
|
+
# }
|
57
|
+
#
|
58
|
+
# css.div(:class => 'foo') {
|
59
|
+
# background 'red'
|
60
|
+
# }
|
61
|
+
#
|
62
|
+
# This will yield the following stylesheet:
|
63
|
+
#
|
64
|
+
# /* This is our stylesheet */
|
65
|
+
# body {
|
66
|
+
# background_color: #FAFAFA;
|
67
|
+
# font_size: small;
|
68
|
+
# font_family: Helvetica, Arial, sans_serif;
|
69
|
+
# color: #7F7F7F;
|
70
|
+
# }
|
71
|
+
#
|
72
|
+
# #navbar {
|
73
|
+
# width: 500px;
|
74
|
+
# }
|
75
|
+
#
|
76
|
+
# .navitem {
|
77
|
+
# color: red;
|
78
|
+
# }
|
79
|
+
#
|
80
|
+
# a:hover {
|
81
|
+
# text_decoration: underline;
|
82
|
+
# }
|
83
|
+
#
|
84
|
+
# div#menu {
|
85
|
+
# background: green;
|
86
|
+
# }
|
87
|
+
#
|
88
|
+
# div.foo {
|
89
|
+
# background: red;
|
90
|
+
# }
|
91
|
+
#
|
92
|
+
class CSS < BlankSlate
|
93
|
+
|
94
|
+
# Create a CSS builder.
|
95
|
+
#
|
96
|
+
# out:: Object receiving the markup.1 +out+ must respond to
|
97
|
+
# <tt><<</tt>.
|
98
|
+
# indent:: Number of spaces used for indentation (0 implies no
|
99
|
+
# indentation and no line breaks).
|
100
|
+
#
|
101
|
+
def initialize(indent=2)
|
102
|
+
@indent = indent
|
103
|
+
@target = []
|
104
|
+
@parts = []
|
105
|
+
@library = {}
|
106
|
+
end
|
107
|
+
|
108
|
+
def +(part)
|
109
|
+
_join_with_op! '+'
|
110
|
+
self
|
111
|
+
end
|
112
|
+
|
113
|
+
def >>(part)
|
114
|
+
_join_with_op! ''
|
115
|
+
self
|
116
|
+
end
|
117
|
+
|
118
|
+
def >(part)
|
119
|
+
_join_with_op! '>'
|
120
|
+
self
|
121
|
+
end
|
122
|
+
|
123
|
+
def |(part)
|
124
|
+
_join_with_op! ','
|
125
|
+
self
|
126
|
+
end
|
127
|
+
|
128
|
+
# Return the target of the builder
|
129
|
+
def target!
|
130
|
+
@target * ''
|
131
|
+
end
|
132
|
+
|
133
|
+
# Create a comment string in the output.
|
134
|
+
def comment!(comment_text)
|
135
|
+
@target << "/* #{comment_text} */\n"
|
136
|
+
end
|
137
|
+
|
138
|
+
def id!(arg, &block)
|
139
|
+
_start_container('#'+arg.to_s, nil, block_given?)
|
140
|
+
_css_block(block) if block
|
141
|
+
_unify_block
|
142
|
+
self
|
143
|
+
end
|
144
|
+
|
145
|
+
def class!(arg, &block)
|
146
|
+
_start_container('.'+arg.to_s, nil, block_given?)
|
147
|
+
_css_block(block) if block
|
148
|
+
_unify_block
|
149
|
+
self
|
150
|
+
end
|
151
|
+
|
152
|
+
def store!(sym, &block)
|
153
|
+
@library[sym] = block.to_proc
|
154
|
+
end
|
155
|
+
|
156
|
+
def group!(*args, &block)
|
157
|
+
args.each do |arg|
|
158
|
+
if arg.is_a?(Symbol)
|
159
|
+
instance_eval(&@library[arg])
|
160
|
+
else
|
161
|
+
instance_eval(&arg)
|
162
|
+
end
|
163
|
+
_text ', ' unless arg == args.last
|
164
|
+
end
|
165
|
+
if block
|
166
|
+
_css_block(block)
|
167
|
+
_unify_block
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def method_missing(sym, *args, &block)
|
172
|
+
sym = "#{sym}:#{args.shift}" if args.first.kind_of?(Symbol)
|
173
|
+
if block
|
174
|
+
_start_container(sym, args.first)
|
175
|
+
_css_block(block)
|
176
|
+
_unify_block
|
177
|
+
elsif @in_block
|
178
|
+
_indent
|
179
|
+
_css_line(sym, *args)
|
180
|
+
_newline
|
181
|
+
return self
|
182
|
+
else
|
183
|
+
_start_container(sym, args.first, false)
|
184
|
+
_unify_block
|
185
|
+
end
|
186
|
+
self
|
187
|
+
end
|
188
|
+
|
189
|
+
# "Cargo culted" from Jim who also "cargo culted" it. See xmlbase.rb.
|
190
|
+
def nil?
|
191
|
+
false
|
192
|
+
end
|
193
|
+
|
194
|
+
private
|
195
|
+
def _unify_block
|
196
|
+
@target << @parts * ''
|
197
|
+
@parts = []
|
198
|
+
end
|
199
|
+
|
200
|
+
def _join_with_op!(op)
|
201
|
+
rhs, lhs = @target.pop, @target.pop
|
202
|
+
@target << "#{lhs} #{op} #{rhs}"
|
203
|
+
end
|
204
|
+
|
205
|
+
def _text(text)
|
206
|
+
@parts << text
|
207
|
+
end
|
208
|
+
|
209
|
+
def _css_block(block)
|
210
|
+
_newline
|
211
|
+
_nested_structures(block)
|
212
|
+
_end_container
|
213
|
+
_end_block
|
214
|
+
end
|
215
|
+
|
216
|
+
def _end_block
|
217
|
+
_newline
|
218
|
+
_newline
|
219
|
+
end
|
220
|
+
|
221
|
+
def _newline
|
222
|
+
_text "\n"
|
223
|
+
end
|
224
|
+
|
225
|
+
def _indent
|
226
|
+
_text ' ' * @indent
|
227
|
+
end
|
228
|
+
|
229
|
+
def _nested_structures(block)
|
230
|
+
@in_block = true
|
231
|
+
self.instance_eval(&block)
|
232
|
+
@in_block = false
|
233
|
+
end
|
234
|
+
|
235
|
+
def _start_container(sym, atts = {}, with_bracket = true)
|
236
|
+
selector = sym.to_s
|
237
|
+
selector << ".#{atts[:class]}" if atts && atts[:class]
|
238
|
+
selector << '#' + "#{atts[:id]}" if atts && atts[:id]
|
239
|
+
@parts << "#{selector}#{with_bracket ? ' {' : ''}"
|
240
|
+
end
|
241
|
+
|
242
|
+
def _end_container
|
243
|
+
@parts << "}"
|
244
|
+
end
|
245
|
+
|
246
|
+
def _css_line(sym, *args)
|
247
|
+
_text("#{sym.to_s.gsub('_','-')}: #{args * ' '};")
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|