attribeautiful 0.0.1
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +62 -0
- data/Rakefile +2 -0
- data/attribeautiful.gemspec +22 -0
- data/lib/attribeautiful.rb +2 -0
- data/lib/attribeautiful/attribute.rb +51 -0
- data/lib/attribeautiful/attribute/name.rb +32 -0
- data/lib/attribeautiful/attribute/value.rb +40 -0
- data/lib/attribeautiful/container.rb +97 -0
- data/lib/attribeautiful/element.rb +26 -0
- data/lib/attribeautiful/version.rb +3 -0
- metadata +91 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Kevin Burleigh
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Attribeautiful
|
2
|
+
|
3
|
+
Dynamically-generated HTML element attribute management methods.
|
4
|
+
Easily add attributes to an element, or content to an attribute value.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'attribeautiful'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install attribeautiful
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
class SectionBlock
|
24
|
+
include Attribeautiful
|
25
|
+
|
26
|
+
html_element :header
|
27
|
+
html_element :body
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
yield self if block_given?
|
31
|
+
self
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
sb = SectionBlock.new do |sb|
|
36
|
+
sb.header_class_add "important", "slick"
|
37
|
+
|
38
|
+
sb.header_custom_one_add "do-something"
|
39
|
+
sb.header_custom_two_add "do-something-else"
|
40
|
+
sb.header_custom_two_use_underscores
|
41
|
+
|
42
|
+
sb.body_id_add "specific-section-id"
|
43
|
+
sb.body_style_add "float:left", "color:blue"
|
44
|
+
sb.body_style_add "position:relative"
|
45
|
+
sb.body_style_use_semicolons
|
46
|
+
end
|
47
|
+
|
48
|
+
puts "#{sb.header_class_attr}" # class="important slick"
|
49
|
+
puts "#{sb.header_custom_one_attr}" # custom-one="do-something"
|
50
|
+
puts "#{sb.header_custom_two_attr}" # custom_two="do-something-else"
|
51
|
+
puts "#{sb.body_id_attr}" # id="specific-section-id"
|
52
|
+
puts "#{sb.body_class_attr}" # nothing!
|
53
|
+
puts "#{sb.body_style_attr}" # style="float:left;color:blue;position:relative"
|
54
|
+
```
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
1. Fork it
|
59
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
60
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
61
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
62
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/attribeautiful/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Kevin Burleigh"]
|
6
|
+
gem.email = ["klb@kindlinglabs.com"]
|
7
|
+
gem.description = %q{Dynamically-generated HTML element attribute management methods}
|
8
|
+
gem.summary = %q{Dynamically-generated HTML element attribute management methods.
|
9
|
+
Easily add attributes to an element, or content to an attribute
|
10
|
+
value.}
|
11
|
+
gem.homepage = "http://github.com/kevinburleigh75/attribeautiful"
|
12
|
+
|
13
|
+
gem.add_dependency "eager_beaver"
|
14
|
+
gem.add_dependency "active_support", ">= 3.0.0"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($\)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.name = "attribeautiful"
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
gem.version = Attribeautiful::VERSION
|
22
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "attribute/name")
|
2
|
+
require File.join(File.dirname(__FILE__), "attribute/value")
|
3
|
+
require 'active_support/lazy_load_hooks'
|
4
|
+
require 'active_support/core_ext/string'
|
5
|
+
|
6
|
+
module Attribeautiful
|
7
|
+
|
8
|
+
class Attribute
|
9
|
+
|
10
|
+
attr_accessor :attr_name
|
11
|
+
attr_accessor :attr_value
|
12
|
+
|
13
|
+
def initialize(name)
|
14
|
+
self.attr_name = Attribeautiful::Attribute::Name.new(name)
|
15
|
+
self.attr_value = Attribeautiful::Attribute::Value.new
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def use_underscores
|
20
|
+
self.attr_name.use_underscores
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def use_dashes
|
25
|
+
self.attr_name.use_dashes
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def add(*args)
|
30
|
+
self.attr_value.add(*args)
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def use_spaces
|
35
|
+
self.attr_value.use_spaces
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
def use_semicolons
|
40
|
+
self.attr_value.use_semicolons
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
return "" if attr_value.to_s.empty?
|
46
|
+
return "#{attr_name}=\"#{attr_value}\"".html_safe
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Attribeautiful
|
2
|
+
class Attribute
|
3
|
+
|
4
|
+
class Name
|
5
|
+
attr_accessor :text
|
6
|
+
|
7
|
+
def initialize(name)
|
8
|
+
self.text = name
|
9
|
+
self.use_dashes
|
10
|
+
end
|
11
|
+
|
12
|
+
def use_dashes?
|
13
|
+
@use_dashes
|
14
|
+
end
|
15
|
+
|
16
|
+
def use_dashes
|
17
|
+
@use_dashes = true
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def use_underscores
|
22
|
+
@use_dashes = false
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
use_dashes? ? text.gsub('_', '-') : text.gsub('-', '_')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Attribeautiful
|
2
|
+
class Attribute
|
3
|
+
|
4
|
+
class Value
|
5
|
+
|
6
|
+
attr_accessor :strings
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
self.strings = []
|
10
|
+
self.use_spaces
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def use_spaces
|
15
|
+
@use_spaces = true
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def use_semicolons
|
20
|
+
@use_spaces = false
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def use_spaces?
|
25
|
+
@use_spaces
|
26
|
+
end
|
27
|
+
|
28
|
+
def add(*args)
|
29
|
+
self.strings << args
|
30
|
+
self.strings = strings.flatten.uniq
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
use_spaces? ? strings.join(" ") : strings.join(";")
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'eager_beaver'
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), 'element')
|
4
|
+
require File.join(File.dirname(__FILE__), 'attribute')
|
5
|
+
|
6
|
+
module Attribeautiful
|
7
|
+
|
8
|
+
def self.included(includer)
|
9
|
+
includer.extend(ClassMethods)
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
|
14
|
+
def html_element_names
|
15
|
+
@html_element_names ||= []
|
16
|
+
end
|
17
|
+
|
18
|
+
def html_element(elem_name)
|
19
|
+
include EagerBeaver
|
20
|
+
|
21
|
+
html_element_names << elem_name
|
22
|
+
|
23
|
+
## handle <elem_name>_element methods
|
24
|
+
add_method_matcher do |mm|
|
25
|
+
mm.matcher = Proc.new do
|
26
|
+
#puts "MATCHING: <elem_name>_element against #{missing_method_name}"
|
27
|
+
/\A(\w+)_element\z/ =~ missing_method_name.to_s
|
28
|
+
@elem_name = Regexp.last_match ? Regexp.last_match[1] : nil
|
29
|
+
#puts "MATCHING: #{Regexp.last_match ? 'SUCESS' : 'FAILURE'}"
|
30
|
+
Regexp.last_match
|
31
|
+
end
|
32
|
+
|
33
|
+
mm.new_method_code_maker = Proc.new do
|
34
|
+
%Q{
|
35
|
+
def #{missing_method_name}
|
36
|
+
@#{@elem_name}_element ||= Attribeautiful::Element.new
|
37
|
+
end
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
## handle <elem_name>_<attr_name>_attr methods
|
43
|
+
add_method_matcher do |mm|
|
44
|
+
mm.matcher = Proc.new do
|
45
|
+
#puts "MATCHING: <elem_name>_<attr_name>_attr against #{missing_method_name}"
|
46
|
+
#puts "#{original_caller.class.html_element_names}"
|
47
|
+
original_caller.class.html_element_names.detect{ |elem_name|
|
48
|
+
#puts "#{elem_name}"
|
49
|
+
/\A(#{elem_name})_(\w+)_attr\z/ =~ missing_method_name.to_s
|
50
|
+
}
|
51
|
+
@elem_name = Regexp.last_match ? Regexp.last_match[1] : nil
|
52
|
+
@attr_name = Regexp.last_match ? Regexp.last_match[2] : nil
|
53
|
+
#puts "MATCHING: #{Regexp.last_match ? 'SUCESS' : 'FAILURE'}"
|
54
|
+
Regexp.last_match
|
55
|
+
end
|
56
|
+
|
57
|
+
mm.new_method_code_maker = Proc.new do
|
58
|
+
%Q{
|
59
|
+
def #{missing_method_name}
|
60
|
+
#{@elem_name}_element.#{@attr_name}_attr ||= Attribeautiful::Attribute.new("#{@attr_name}")
|
61
|
+
end
|
62
|
+
}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
## handle <elem_name>_<attr_name>_<attr_action> methods
|
67
|
+
add_method_matcher do |mm|
|
68
|
+
mm.matcher = Proc.new do
|
69
|
+
#puts "MATCHING: <elem_name>_<attr_name>_<attr_action> against #{missing_method_name}"
|
70
|
+
#puts "#{original_caller.class.html_element_names}"
|
71
|
+
original_caller.class.html_element_names.detect{ |elem_name|
|
72
|
+
#puts "#{elem_name}"
|
73
|
+
Attribeautiful::Attribute.instance_methods.detect do |attr_action|
|
74
|
+
#puts " #{attr_action}"
|
75
|
+
/\A(#{elem_name})_(\w+)_(#{attr_action})\z/ =~ missing_method_name.to_s
|
76
|
+
end
|
77
|
+
}
|
78
|
+
@elem_name = Regexp.last_match ? Regexp.last_match[1] : nil
|
79
|
+
@attr_name = Regexp.last_match ? Regexp.last_match[2] : nil
|
80
|
+
@attr_action = Regexp.last_match ? Regexp.last_match[3] : nil
|
81
|
+
#puts "MATCHING: #{Regexp.last_match ? 'SUCESS' : 'FAILURE'}"
|
82
|
+
Regexp.last_match
|
83
|
+
end
|
84
|
+
|
85
|
+
mm.new_method_code_maker = Proc.new do
|
86
|
+
%Q{
|
87
|
+
def #{@elem_name}_#{@attr_name}_#{@attr_action}(*args, &block)
|
88
|
+
#{@elem_name}_#{@attr_name}_attr.#{@attr_action}(*args, &block)
|
89
|
+
end
|
90
|
+
}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'eager_beaver'
|
2
|
+
require File.join(File.dirname(__FILE__), "attribute")
|
3
|
+
|
4
|
+
module Attribeautiful
|
5
|
+
|
6
|
+
class Element
|
7
|
+
include EagerBeaver
|
8
|
+
|
9
|
+
## handle <attr_name>_attr methods
|
10
|
+
add_method_matcher do |mm|
|
11
|
+
mm.matcher = Proc.new do
|
12
|
+
/\A(\w+)_attr/ =~ missing_method_name
|
13
|
+
@attr_name = Regexp.last_match ? Regexp.last_match[1] : nil
|
14
|
+
end
|
15
|
+
|
16
|
+
mm.new_method_code_maker = Proc.new do
|
17
|
+
%Q{
|
18
|
+
def #{missing_method_name}
|
19
|
+
@#{@attr_name}_attr ||= Attribeautiful::Attribute.new("#{@attr_name}")
|
20
|
+
end
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: attribeautiful
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kevin Burleigh
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: eager_beaver
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: active_support
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 3.0.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 3.0.0
|
46
|
+
description: Dynamically-generated HTML element attribute management methods
|
47
|
+
email:
|
48
|
+
- klb@kindlinglabs.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- attribeautiful.gemspec
|
59
|
+
- lib/attribeautiful.rb
|
60
|
+
- lib/attribeautiful/attribute.rb
|
61
|
+
- lib/attribeautiful/attribute/name.rb
|
62
|
+
- lib/attribeautiful/attribute/value.rb
|
63
|
+
- lib/attribeautiful/container.rb
|
64
|
+
- lib/attribeautiful/element.rb
|
65
|
+
- lib/attribeautiful/version.rb
|
66
|
+
homepage: http://github.com/kevinburleigh75/attribeautiful
|
67
|
+
licenses: []
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.24
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Dynamically-generated HTML element attribute management methods. Easily add
|
90
|
+
attributes to an element, or content to an attribute value.
|
91
|
+
test_files: []
|