syaso 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 +20 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +26 -0
- data/lib/syaso.rb +9 -0
- data/lib/syaso/base.rb +113 -0
- data/lib/syaso/init.rb +5 -0
- data/lib/syaso/list.rb +74 -0
- data/lib/syaso/list_item.rb +24 -0
- data/lib/syaso/version.rb +5 -0
- data/syaso.gemspec +26 -0
- data/test/test_helper.rb +17 -0
- data/test/units/syaso/test_list.rb +42 -0
- data/test/units/test_syaso.rb +14 -0
- metadata +97 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 sekizo
|
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,48 @@
|
|
1
|
+
# Syaso
|
2
|
+
|
3
|
+
ActionView helper.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'syaso'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install syaso
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
in Gemfile
|
22
|
+
|
23
|
+
gem "syaso"
|
24
|
+
|
25
|
+
in app/views/SOME_VIEW.html.erb
|
26
|
+
|
27
|
+
# Syaso::List
|
28
|
+
<%= Syaso.list(@records).render(:class => [:padding], :item => { :style => "border-bottom:1px solid Gray" }) do |item| %>
|
29
|
+
<%= item.name %>
|
30
|
+
<% end %>
|
31
|
+
|
32
|
+
# or
|
33
|
+
|
34
|
+
<%= Syaso.list(@records).each(:class => [:padding]) do |item| %>
|
35
|
+
<%= item.render(:style => "border-bottom:1px solid Gray") do |i| %>
|
36
|
+
<%= i.name %>
|
37
|
+
<% end
|
38
|
+
<% end %>
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
|
5
|
+
require "rake/testtask"
|
6
|
+
|
7
|
+
# load path
|
8
|
+
$: << File.expand_path("../lib", __FILE__)
|
9
|
+
|
10
|
+
# default task
|
11
|
+
task :default do
|
12
|
+
sh "rake -T"
|
13
|
+
end
|
14
|
+
|
15
|
+
# test tasks
|
16
|
+
Rake::TestTask.new do |t|
|
17
|
+
t.libs << "test"
|
18
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
19
|
+
end
|
20
|
+
|
21
|
+
namespace :test do
|
22
|
+
Rake::TestTask.new(:units) do |t|
|
23
|
+
t.libs << "test"
|
24
|
+
t.test_files = FileList["test/units/**/test_*.rb"]
|
25
|
+
end
|
26
|
+
end
|
data/lib/syaso.rb
ADDED
data/lib/syaso/base.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Syaso::Base
|
4
|
+
#--------------------#
|
5
|
+
# constants
|
6
|
+
|
7
|
+
#--------------------#
|
8
|
+
# attributes
|
9
|
+
|
10
|
+
attr_reader :content
|
11
|
+
|
12
|
+
#--------------------#
|
13
|
+
# class methods
|
14
|
+
|
15
|
+
#--------------------#
|
16
|
+
# instance methods
|
17
|
+
|
18
|
+
# initialize method
|
19
|
+
#
|
20
|
+
# @param [ActionView] context
|
21
|
+
def initialize(context)
|
22
|
+
super()
|
23
|
+
self.context = context
|
24
|
+
#@@default_html_tag ||= :div
|
25
|
+
#@@default_html_class ||= []
|
26
|
+
end
|
27
|
+
|
28
|
+
def render(options = {}, &block)
|
29
|
+
self._render(options, &block)
|
30
|
+
end
|
31
|
+
#--------------------#
|
32
|
+
protected
|
33
|
+
|
34
|
+
attr_accessor :tag, :context
|
35
|
+
attr_writer :content
|
36
|
+
|
37
|
+
# render method
|
38
|
+
#
|
39
|
+
# @param [Hash] options
|
40
|
+
def _render(options = {}, &block)
|
41
|
+
ops = filter_options(options)
|
42
|
+
self.buffer do
|
43
|
+
self.context.content_tag(self.tag, ops) do
|
44
|
+
self.buffer do
|
45
|
+
block_given? ? yield(self) : self.content
|
46
|
+
end
|
47
|
+
end # context.content_tag
|
48
|
+
end # buffer
|
49
|
+
end # context.concat
|
50
|
+
|
51
|
+
# buffer contents
|
52
|
+
def buffer(&block)
|
53
|
+
self.context.concat(yield)
|
54
|
+
""
|
55
|
+
end
|
56
|
+
|
57
|
+
# default tag
|
58
|
+
#
|
59
|
+
# @return [Symbol]
|
60
|
+
def default_html_tag
|
61
|
+
:div
|
62
|
+
end
|
63
|
+
|
64
|
+
# default html classes
|
65
|
+
#
|
66
|
+
# @return [Array<String>]
|
67
|
+
def default_html_class
|
68
|
+
[]
|
69
|
+
end
|
70
|
+
|
71
|
+
#--------------------#
|
72
|
+
private
|
73
|
+
|
74
|
+
# filter html options
|
75
|
+
#
|
76
|
+
# @param [Hash] options
|
77
|
+
# @return [Hash]
|
78
|
+
def filter_options(options = {})
|
79
|
+
ops = options.dup
|
80
|
+
|
81
|
+
options.each do |k, v|
|
82
|
+
ops[k] = v.is_a?(Proc) ? v.call(self) : v
|
83
|
+
end
|
84
|
+
|
85
|
+
self.tag = ops.delete(:tag)||self.default_html_tag
|
86
|
+
ops = filter_html_class_options(ops)
|
87
|
+
ops
|
88
|
+
end
|
89
|
+
|
90
|
+
# filter html classes
|
91
|
+
#
|
92
|
+
# @param [Hash] options
|
93
|
+
# @return [Hash]
|
94
|
+
def filter_html_class_options(options = {})
|
95
|
+
options[:class] ||= []
|
96
|
+
options[:class] = options[:class].to_s.split(" ") unless options[:class].is_a?(Array)
|
97
|
+
options[:class] += self.default_html_class
|
98
|
+
options.delete(:class) if options[:class].blank?
|
99
|
+
options
|
100
|
+
end
|
101
|
+
|
102
|
+
# method missing
|
103
|
+
#
|
104
|
+
# @param [Symbol] name
|
105
|
+
# @param [Array] args
|
106
|
+
def method_missing(name, *args, &block)
|
107
|
+
begin
|
108
|
+
self.content.__send__(name, *args, &block)
|
109
|
+
rescue => e
|
110
|
+
super
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
data/lib/syaso/init.rb
ADDED
data/lib/syaso/list.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "syaso/base"
|
4
|
+
require "syaso/list_item"
|
5
|
+
|
6
|
+
class Syaso::List < Syaso::Base
|
7
|
+
#--------------------#
|
8
|
+
# content
|
9
|
+
|
10
|
+
ITEM_VIEW = Syaso::ListItem
|
11
|
+
|
12
|
+
# initialize instance
|
13
|
+
#
|
14
|
+
# @param [ActionView] context
|
15
|
+
# @param [Array] content
|
16
|
+
def initialize(context, content)
|
17
|
+
super(context)
|
18
|
+
self.content = content
|
19
|
+
end
|
20
|
+
|
21
|
+
# render list
|
22
|
+
#
|
23
|
+
# @param [Hash] options
|
24
|
+
def render(options = {}, &block)
|
25
|
+
ops = options.delete(:item)||{}
|
26
|
+
self.each(options) do |i|
|
27
|
+
self.buffer do
|
28
|
+
i.render(ops, &block)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# render container and iterate items
|
34
|
+
#
|
35
|
+
# @param [Hash] options
|
36
|
+
def each(options = {}, &block)
|
37
|
+
self._render(options) do |i|
|
38
|
+
self.content.each do |i|
|
39
|
+
yield(self.item_view(i))
|
40
|
+
end
|
41
|
+
""
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
#--------------------#
|
46
|
+
protected
|
47
|
+
|
48
|
+
# item view
|
49
|
+
#
|
50
|
+
# @param [Object] item
|
51
|
+
def item_view(item)
|
52
|
+
ITEM_VIEW.new(self.context, self, item)
|
53
|
+
end
|
54
|
+
|
55
|
+
# default html tag
|
56
|
+
def default_html_tag
|
57
|
+
:ul
|
58
|
+
end
|
59
|
+
|
60
|
+
# default html class
|
61
|
+
def default_html_class
|
62
|
+
[:list]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
module Syaso
|
67
|
+
# list view instance
|
68
|
+
#
|
69
|
+
# @param [ActionView] context
|
70
|
+
# @param [Array] list
|
71
|
+
def self.list(context, list)
|
72
|
+
Syaso::List.new(context, list)
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "syaso/base"
|
4
|
+
|
5
|
+
class Syaso::ListItem < Syaso::Base
|
6
|
+
def initialize(context, holder, content)
|
7
|
+
super(context)
|
8
|
+
self.holder = holder
|
9
|
+
self.content = content
|
10
|
+
end
|
11
|
+
|
12
|
+
def index
|
13
|
+
self.holder.index(self.content)
|
14
|
+
end
|
15
|
+
|
16
|
+
#--------------------#
|
17
|
+
protected
|
18
|
+
|
19
|
+
attr_writer :holder
|
20
|
+
|
21
|
+
def default_html_tag
|
22
|
+
:li
|
23
|
+
end
|
24
|
+
end
|
data/syaso.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'syaso/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "syaso"
|
8
|
+
gem.version = Syaso::VERSION
|
9
|
+
gem.authors = ["sekizo"]
|
10
|
+
gem.email = ["sekizoworld@mac.com"]
|
11
|
+
gem.description = %q{basic views for ActiveView}
|
12
|
+
gem.summary = %q{helper for ActionView}
|
13
|
+
gem.homepage = ""
|
14
|
+
gem.license = "MIT"
|
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.require_paths = ["lib"]
|
20
|
+
|
21
|
+
#--------------------#
|
22
|
+
# additionals
|
23
|
+
gem.add_dependency "actionpack"
|
24
|
+
gem.add_development_dependency "shoulda"
|
25
|
+
|
26
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "action_view"
|
4
|
+
require "shoulda"
|
5
|
+
require "test/unit"
|
6
|
+
|
7
|
+
file = File.expand_path("../../lib/syaso", __FILE__)
|
8
|
+
require file
|
9
|
+
|
10
|
+
def setup_view
|
11
|
+
@context = ActionView::Base.new
|
12
|
+
@context.output_buffer = ""
|
13
|
+
end
|
14
|
+
|
15
|
+
def output
|
16
|
+
@context.output_buffer
|
17
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
class TestSyasoList < Test::Unit::TestCase
|
6
|
+
context "Syaso::List" do
|
7
|
+
|
8
|
+
setup do
|
9
|
+
setup_view
|
10
|
+
@records = [1, 2, 3]
|
11
|
+
@list = Syaso::List.new(@context, @records)
|
12
|
+
end # setup
|
13
|
+
|
14
|
+
should "default render ul" do
|
15
|
+
@list.render
|
16
|
+
assert(output.match(/^<ul[^\>]*>/), "List begin with '<ul>'.")
|
17
|
+
end # should "default render ul"
|
18
|
+
|
19
|
+
should "respond to render items" do
|
20
|
+
assert_nothing_raised(Exception) do
|
21
|
+
@list.render(:class => [:container]) do |item|
|
22
|
+
item.content
|
23
|
+
end # list.render
|
24
|
+
end # assert
|
25
|
+
end # should "respond to render items"
|
26
|
+
|
27
|
+
should "respond to render item" do
|
28
|
+
assert_nothing_raised(Exception) do
|
29
|
+
@list.each(:class => [:container]) do |item|
|
30
|
+
item.render(:tag => :p, :id => lambda {|i| "item_#{i.content}"}) do |i|
|
31
|
+
i.content
|
32
|
+
end # item.render
|
33
|
+
end # list.each
|
34
|
+
end # assert
|
35
|
+
end # should "respond to render item"
|
36
|
+
|
37
|
+
teardown do
|
38
|
+
puts output
|
39
|
+
end # teardown
|
40
|
+
|
41
|
+
end # context "Syaso"
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: syaso
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- sekizo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: actionpack
|
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: shoulda
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: basic views for ActiveView
|
47
|
+
email:
|
48
|
+
- sekizoworld@mac.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/syaso.rb
|
59
|
+
- lib/syaso/base.rb
|
60
|
+
- lib/syaso/init.rb
|
61
|
+
- lib/syaso/list.rb
|
62
|
+
- lib/syaso/list_item.rb
|
63
|
+
- lib/syaso/version.rb
|
64
|
+
- syaso.gemspec
|
65
|
+
- test/test_helper.rb
|
66
|
+
- test/units/syaso/test_list.rb
|
67
|
+
- test/units/test_syaso.rb
|
68
|
+
homepage: ''
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.8.24
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: helper for ActionView
|
93
|
+
test_files:
|
94
|
+
- test/test_helper.rb
|
95
|
+
- test/units/syaso/test_list.rb
|
96
|
+
- test/units/test_syaso.rb
|
97
|
+
has_rdoc:
|