easy_dl 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +11 -0
- data/LICENSE +22 -0
- data/README.md +35 -0
- data/Rakefile +13 -0
- data/easy_dl.gemspec +17 -0
- data/lib/easy_dl/definition_list_builder.rb +41 -0
- data/lib/easy_dl/dl_helper.rb +12 -0
- data/lib/easy_dl/version.rb +3 -0
- data/lib/easy_dl.rb +9 -0
- data/test/dl_helper_test.rb +27 -0
- data/test/test_helper.rb +29 -0
- metadata +59 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jakub Głuszecki
|
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,35 @@
|
|
1
|
+
# EasyDl
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'easy_dl'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install easy_dl
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```haml
|
22
|
+
= definition_list_for(@person) do |d|
|
23
|
+
= d.item :name
|
24
|
+
= d.item :surname
|
25
|
+
= d.item :born do |person|
|
26
|
+
= person.date_of_birth.year
|
27
|
+
```
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
Rake::TestTask.new(:test) do |t|
|
9
|
+
t.libs << 'lib'
|
10
|
+
t.libs << 'test'
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
12
|
+
t.verbose = true
|
13
|
+
end
|
data/easy_dl.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/easy_dl/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Jakub Głuszecki"]
|
6
|
+
gem.email = ["jakub.gluszecki@expander.pl"]
|
7
|
+
gem.description = %q{Gem for generating html definition lists}
|
8
|
+
gem.summary = %q{Gem for generating html definition lists}
|
9
|
+
gem.homepage = "https://github.com/cthulhu666/easy_dl"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "easy_dl"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = EasyDl::VERSION
|
17
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module EasyDl
|
2
|
+
|
3
|
+
class DefinitionListBuilder
|
4
|
+
include ::ActionView::Helpers::TagHelper
|
5
|
+
|
6
|
+
def initialize(obj, template)
|
7
|
+
@obj = obj
|
8
|
+
@template = template
|
9
|
+
@is_active_record = obj.respond_to?(:to_model)
|
10
|
+
end
|
11
|
+
|
12
|
+
def item(name)
|
13
|
+
concat tag(:dt, nil, true, true)
|
14
|
+
concat try_translate(name)
|
15
|
+
concat '</dt>'
|
16
|
+
|
17
|
+
concat tag(:dd, nil, true, true)
|
18
|
+
if block_given?
|
19
|
+
yield @obj
|
20
|
+
else
|
21
|
+
concat @obj.send(name)
|
22
|
+
end
|
23
|
+
concat '</dd>'
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def try_translate(name)
|
30
|
+
@is_active_record ?
|
31
|
+
I18n.t("activerecord.attributes.#{@obj.class.name.downcase}.#{name}") : name.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
def concat(str)
|
35
|
+
str ||= '-'
|
36
|
+
@template.safe_concat(str)
|
37
|
+
''
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/lib/easy_dl.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DlHelperTest < ActionView::TestCase
|
4
|
+
|
5
|
+
context '' do
|
6
|
+
setup do
|
7
|
+
@person = OpenStruct.new(name: 'John', surname: 'Doe')
|
8
|
+
concat(definition_list_for(@person, class: 'easy') do |d|
|
9
|
+
d.item :name
|
10
|
+
d.item :surname
|
11
|
+
end)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "have 'easy' class" do
|
15
|
+
assert_select 'dl.easy'
|
16
|
+
end
|
17
|
+
|
18
|
+
should "have 2 <dt> tags" do
|
19
|
+
assert_select 'dl dt', 2
|
20
|
+
end
|
21
|
+
|
22
|
+
should "have 2 <dd> tags" do
|
23
|
+
assert_select 'dl dd', 2
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'mocha'
|
6
|
+
require 'shoulda-context'
|
7
|
+
|
8
|
+
#require 'active_model'
|
9
|
+
require 'action_controller'
|
10
|
+
require 'action_view'
|
11
|
+
require 'action_view/template'
|
12
|
+
|
13
|
+
require 'action_view/test_case'
|
14
|
+
|
15
|
+
module Rails
|
16
|
+
def self.env
|
17
|
+
ActiveSupport::StringInquirer.new("test")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
22
|
+
require 'easy_dl'
|
23
|
+
|
24
|
+
I18n.default_locale = :en
|
25
|
+
|
26
|
+
class ActionView::TestCase
|
27
|
+
include EasyDl::DlHelper
|
28
|
+
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: easy_dl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jakub Głuszecki
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-28 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Gem for generating html definition lists
|
15
|
+
email:
|
16
|
+
- jakub.gluszecki@expander.pl
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- easy_dl.gemspec
|
27
|
+
- lib/easy_dl.rb
|
28
|
+
- lib/easy_dl/definition_list_builder.rb
|
29
|
+
- lib/easy_dl/dl_helper.rb
|
30
|
+
- lib/easy_dl/version.rb
|
31
|
+
- test/dl_helper_test.rb
|
32
|
+
- test/test_helper.rb
|
33
|
+
homepage: https://github.com/cthulhu666/easy_dl
|
34
|
+
licenses: []
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.8.15
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: Gem for generating html definition lists
|
57
|
+
test_files:
|
58
|
+
- test/dl_helper_test.rb
|
59
|
+
- test/test_helper.rb
|