dom_id 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/Manifest.txt +15 -0
- data/README.txt +4 -0
- data/Rakefile +13 -0
- data/about.yml +7 -0
- data/init.rb +2 -0
- data/lib/dom_id.rb +20 -0
- data/test/database.yml +18 -0
- data/test/fixtures/people_thing.rb +3 -0
- data/test/fixtures/people_things.yml +4 -0
- data/test/fixtures/thing.rb +3 -0
- data/test/fixtures/things.yml +4 -0
- data/test/schema.rb +11 -0
- data/test/test_dom_id.rb +30 -0
- data/test/test_helper.rb +40 -0
- metadata +72 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.txt
|
4
|
+
Rakefile
|
5
|
+
about.yml
|
6
|
+
init.rb
|
7
|
+
lib/dom_id.rb
|
8
|
+
test/database.yml
|
9
|
+
test/test_dom_id.rb
|
10
|
+
test/fixtures/people_thing.rb
|
11
|
+
test/fixtures/people_things.yml
|
12
|
+
test/fixtures/thing.rb
|
13
|
+
test/fixtures/things.yml
|
14
|
+
test/schema.rb
|
15
|
+
test/test_helper.rb
|
data/README.txt
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'hoe'
|
3
|
+
require 'lib/dom_id'
|
4
|
+
|
5
|
+
Hoe.new('dom_id', DomId::VERSION) do |p|
|
6
|
+
p.rubyforge_name = 'seattlerb'
|
7
|
+
p.author = 'Geoffrey Grosenbach'
|
8
|
+
p.email = 'boss AT topfunky.com'
|
9
|
+
p.summary = 'Creates a CSS DOM id from an ActiveRecord object.'
|
10
|
+
p.description = 'Creates a CSS DOM id from an ActiveRecord object.'
|
11
|
+
p.url = "http://rubyforge.org/projects/seattlerb"
|
12
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
13
|
+
end
|
data/about.yml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
author: topfunky
|
2
|
+
summary: Creates a dom_id method for generating unique id's in HTML pages.
|
3
|
+
homepage: http://codefluency.com/articles/2006/07/02/rails-views-bulletproofing-dom_id/
|
4
|
+
plugin: http://topfunky.net/svn/plugins/dom_id
|
5
|
+
license: MIT
|
6
|
+
version: 0.2
|
7
|
+
rails_version: 1.0+
|
data/init.rb
ADDED
data/lib/dom_id.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module DomId
|
2
|
+
|
3
|
+
VERSION='0.1.0'
|
4
|
+
|
5
|
+
##
|
6
|
+
# Implementation of http://codefluency.com/articles/2006/05/30/rails-views-dom-id-scheme
|
7
|
+
#
|
8
|
+
# comment.dom_id
|
9
|
+
# => "comment_15"
|
10
|
+
#
|
11
|
+
# Use in views and controllers instead of doing "comment_<%= comment.id %>"
|
12
|
+
#
|
13
|
+
#
|
14
|
+
def dom_id(prefix=nil)
|
15
|
+
display_id = new_record? ? "new" : id
|
16
|
+
prefix = prefix.nil? ? self.class.name.underscore : "#{prefix}_#{self.class.name.underscore}"
|
17
|
+
"#{prefix}_#{display_id}"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/test/database.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
sqlite:
|
2
|
+
:adapter: sqlite
|
3
|
+
:dbfile: plugin.sqlite.db
|
4
|
+
sqlite3:
|
5
|
+
:adapter: sqlite3
|
6
|
+
:dbfile: ":memory:"
|
7
|
+
postgresql:
|
8
|
+
:adapter: postgresql
|
9
|
+
:username: postgres
|
10
|
+
:password: postgres
|
11
|
+
:database: plugin_test
|
12
|
+
:min_messages: ERROR
|
13
|
+
mysql:
|
14
|
+
:adapter: mysql
|
15
|
+
:host: localhost
|
16
|
+
:username: rails
|
17
|
+
:password:
|
18
|
+
:database: plugin_test
|
data/test/schema.rb
ADDED
data/test/test_dom_id.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
2
|
+
|
3
|
+
class Thing < ActiveRecord::Base
|
4
|
+
|
5
|
+
def new_record?; false; end
|
6
|
+
|
7
|
+
def id; 1; end
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
class PeopleThing < ActiveRecord::Base
|
12
|
+
|
13
|
+
def new_record?; true; end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
class TestDomId < Test::Unit::TestCase
|
18
|
+
|
19
|
+
def test_dom_id
|
20
|
+
thing = Thing.new
|
21
|
+
assert_equal 'thing_1', thing.dom_id
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_new
|
25
|
+
pt = PeopleThing.new
|
26
|
+
assert_equal 'people_thing_new', pt.dom_id
|
27
|
+
assert_equal 'many_people_thing_new', pt.dom_id('many')
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Include this file in your test by copying the following line to your test:
|
2
|
+
# require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
3
|
+
|
4
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
5
|
+
RAILS_ROOT = File.dirname(__FILE__)
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'test/unit'
|
9
|
+
require 'active_record'
|
10
|
+
require 'active_record/fixtures'
|
11
|
+
require 'active_support/binding_of_caller'
|
12
|
+
require 'active_support/breakpoint'
|
13
|
+
require "#{File.dirname(__FILE__)}/../init"
|
14
|
+
|
15
|
+
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
16
|
+
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
17
|
+
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite3'])
|
18
|
+
|
19
|
+
load(File.dirname(__FILE__) + "/schema.rb") if File.exist?(File.dirname(__FILE__) + "/schema.rb")
|
20
|
+
|
21
|
+
Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
|
22
|
+
$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
|
23
|
+
|
24
|
+
class Test::Unit::TestCase #:nodoc:
|
25
|
+
def create_fixtures(*table_names)
|
26
|
+
if block_given?
|
27
|
+
Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
|
28
|
+
else
|
29
|
+
Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Turn off transactional fixtures if you're working with MyISAM tables in MySQL
|
34
|
+
self.use_transactional_fixtures = true
|
35
|
+
|
36
|
+
# Instantiated fixtures are slow, but give you @david where you otherwise would need people(:david)
|
37
|
+
self.use_instantiated_fixtures = false
|
38
|
+
|
39
|
+
# Add more helper methods to be used by all tests here...
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: dom_id
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2007-06-24 00:00:00 -07:00
|
8
|
+
summary: Creates a CSS DOM id from an ActiveRecord object.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: boss AT topfunky.com
|
12
|
+
homepage: http://rubyforge.org/projects/seattlerb
|
13
|
+
rubyforge_project: seattlerb
|
14
|
+
description: Creates a CSS DOM id from an ActiveRecord object.
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Geoffrey Grosenbach
|
31
|
+
files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
- Rakefile
|
36
|
+
- about.yml
|
37
|
+
- init.rb
|
38
|
+
- lib/dom_id.rb
|
39
|
+
- test/database.yml
|
40
|
+
- test/test_dom_id.rb
|
41
|
+
- test/fixtures/people_thing.rb
|
42
|
+
- test/fixtures/people_things.yml
|
43
|
+
- test/fixtures/thing.rb
|
44
|
+
- test/fixtures/things.yml
|
45
|
+
- test/schema.rb
|
46
|
+
- test/test_helper.rb
|
47
|
+
test_files:
|
48
|
+
- test/test_dom_id.rb
|
49
|
+
- test/test_helper.rb
|
50
|
+
rdoc_options:
|
51
|
+
- --main
|
52
|
+
- README.txt
|
53
|
+
extra_rdoc_files:
|
54
|
+
- History.txt
|
55
|
+
- Manifest.txt
|
56
|
+
- README.txt
|
57
|
+
executables: []
|
58
|
+
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
dependencies:
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: hoe
|
66
|
+
version_requirement:
|
67
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 1.2.1
|
72
|
+
version:
|