Commit 6c33051f by tady

install draper

parent 9e53bcc2
...@@ -116,3 +116,6 @@ gem 'settingslogic' ...@@ -116,3 +116,6 @@ gem 'settingslogic'
# Check mail format # Check mail format
gem 'validates_email_format_of' gem 'validates_email_format_of'
# Presentaion layer
gem 'draper', '~> 1.3'
...@@ -39,8 +39,8 @@ GEM ...@@ -39,8 +39,8 @@ GEM
activerecord (>= 3.0.0) activerecord (>= 3.0.0)
arel (4.0.2) arel (4.0.2)
ast (1.1.0) ast (1.1.0)
atomic (1.1.14) atomic (1.1.15)
bcrypt (3.1.6) bcrypt (3.1.7)
bcrypt-ruby (3.1.5) bcrypt-ruby (3.1.5)
bcrypt (>= 3.1.3) bcrypt (>= 3.1.3)
better_errors (1.1.0) better_errors (1.1.0)
...@@ -103,12 +103,17 @@ GEM ...@@ -103,12 +103,17 @@ GEM
docile (1.1.3) docile (1.1.3)
domain_name (0.5.16) domain_name (0.5.16)
unf (>= 0.0.5, < 1.0.0) unf (>= 0.0.5, < 1.0.0)
draper (1.3.0)
actionpack (>= 3.0)
activemodel (>= 3.0)
activesupport (>= 3.0)
request_store (~> 1.0.3)
erubis (2.7.0) erubis (2.7.0)
eventmachine (1.0.3) eventmachine (1.0.3)
execjs (2.0.2) execjs (2.0.2)
factory_girl (4.4.0) factory_girl (4.4.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
factory_girl_rails (4.4.0) factory_girl_rails (4.4.1)
factory_girl (~> 4.4.0) factory_girl (~> 4.4.0)
railties (>= 3.0.0) railties (>= 3.0.0)
faraday (0.9.0) faraday (0.9.0)
...@@ -118,9 +123,9 @@ GEM ...@@ -118,9 +123,9 @@ GEM
github-markdown (0.6.4) github-markdown (0.6.4)
gmail_xoauth (0.4.1) gmail_xoauth (0.4.1)
oauth (>= 0.3.6) oauth (>= 0.3.6)
guard (2.4.0) guard (2.5.1)
formatador (>= 0.2.4) formatador (>= 0.2.4)
listen (~> 2.1) listen (~> 2.6)
lumberjack (~> 1.0) lumberjack (~> 1.0)
pry (>= 0.9.12) pry (>= 0.9.12)
thor (>= 0.18.1) thor (>= 0.18.1)
...@@ -151,7 +156,7 @@ GEM ...@@ -151,7 +156,7 @@ GEM
launchy (2.4.2) launchy (2.4.2)
addressable (~> 2.3) addressable (~> 2.3)
libv8 (3.16.14.3) libv8 (3.16.14.3)
listen (2.6.0) listen (2.6.2)
celluloid (>= 0.15.2) celluloid (>= 0.15.2)
celluloid-io (>= 0.15.0) celluloid-io (>= 0.15.0)
rb-fsevent (>= 0.9.3) rb-fsevent (>= 0.9.3)
...@@ -205,7 +210,7 @@ GEM ...@@ -205,7 +210,7 @@ GEM
oauth2 (~> 0.9.3) oauth2 (~> 0.9.3)
omniauth (~> 1.2) omniauth (~> 1.2)
orm_adapter (0.5.0) orm_adapter (0.5.0)
parser (2.1.4) parser (2.1.5)
ast (~> 1.1) ast (~> 1.1)
slop (~> 3.4, >= 3.4.5) slop (~> 3.4, >= 3.4.5)
poltergeist (1.5.0) poltergeist (1.5.0)
...@@ -250,13 +255,14 @@ GEM ...@@ -250,13 +255,14 @@ GEM
rdoc (4.1.1) rdoc (4.1.1)
json (~> 1.4) json (~> 1.4)
ref (1.0.5) ref (1.0.5)
request_store (1.0.5)
rest-client (1.6.7) rest-client (1.6.7)
mime-types (>= 1.16) mime-types (>= 1.16)
rspec (2.14.1) rspec (2.14.1)
rspec-core (~> 2.14.0) rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0) rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0) rspec-mocks (~> 2.14.0)
rspec-core (2.14.7) rspec-core (2.14.8)
rspec-expectations (2.14.5) rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0) diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6) rspec-mocks (2.14.6)
...@@ -311,8 +317,8 @@ GEM ...@@ -311,8 +317,8 @@ GEM
eventmachine (>= 1.0.0) eventmachine (>= 1.0.0)
rack (>= 1.0.0) rack (>= 1.0.0)
thor (0.18.1) thor (0.18.1)
thread_safe (0.1.3) thread_safe (0.2.0)
atomic atomic (>= 1.1.7, < 2)
tilt (1.4.1) tilt (1.4.1)
timers (1.1.0) timers (1.1.0)
tins (1.0.0) tins (1.0.0)
...@@ -352,6 +358,7 @@ DEPENDENCIES ...@@ -352,6 +358,7 @@ DEPENDENCIES
coveralls coveralls
database_rewinder database_rewinder
devise devise
draper (~> 1.3)
factory_girl_rails factory_girl_rails
faraday faraday
github-markdown github-markdown
......
class TagDecorator < Draper::Decorator
delegate_all
# Define presentation-specific methods here. Helpers are accessed through
# `helpers` (aka `h`). You can override attributes, for example:
#
# def created_at
# helpers.content_tag :span, class: 'time' do
# object.created_at.strftime("%a %m/%d/%y")
# end
# end
# tagをtree viewで表示する
def tree_view_node
_html = ''
_html += %Q{
<a href="#{ h.posts_path(q: '#' + model.name) }" data-name="#{model.name}">
#{model.name} <span class="badge">#{model.posts.count}</span>
</a>
}
_html += '<ul>'
model.children.each do |_child|
_html += '<li>'
_html << _child.decorate.tree_view_node
_html += '</li>'
end
_html += '</ul>'
_html.html_safe
end
end
class TagsDecorator < Draper::CollectionDecorator
# tagをtree viewで表示する
def tree_view
_html = ''
_html += %Q{
<ul class="mod-tag-tree">
<input type="search" class="mod-tag-tree-filter form-control" placeholder="filter...">
}
self.each do |_node|
_html += %Q{
<li>
#{_node.decorate.tree_view_node}
</li>
}
end
_html += "</ul>"
_html.html_safe
end
end
module PostsHelper module PostsHelper
# @param {ActiveRecord::Relation} node # # @param {ActiveRecord::Relation} node
def h_display_tree_old(node) # def h_display_tree_old(node)
_html = '<ul>' # _html = '<ul>'
if node.posts.count > 0 # if node.posts.count > 0
_html << %Q{ # _html << %Q{
<li> # <li>
<a href="#{ posts_path(q: '#' + node.name) }">#{node.name} <span class="badge">#{node.posts.count}</span></a> # <a href="#{ posts_path(q: '#' + node.name) }">#{node.name} <span class="badge">#{node.posts.count}</span></a>
</li> # </li>
} # }
end # end
node.children.each do |_child| # node.children.each do |_child|
_html << h_display_tree(_child) # _html << h_display_tree(_child)
end # end
_html << '</ul>' # _html << '</ul>'
_html.html_safe # _html.html_safe
end # end
# @param {ActiveRecord::Relation} node # # @param {ActiveRecord::Relation} node
def h_display_tree(node) # def h_display_tree(node)
_html = '' # _html = ''
_html += %Q{ # _html += %Q{
<a href="#{ posts_path(q: '#' + node.name) }" data-name="#{node.name}"> # <a href="#{ posts_path(q: '#' + node.name) }" data-name="#{node.name}">
#{node.name} <span class="badge">#{node.posts.count}</span> # #{node.name} <span class="badge">#{node.posts.count}</span>
</a> # </a>
} # }
_html += '<ul>' # _html += '<ul>'
node.children.each do |_child| # node.children.each do |_child|
_html += '<li>' # _html += '<li>'
_html << h_display_tree(_child) # _html << h_display_tree(_child)
_html += '</li>' # _html += '</li>'
end # end
_html << '</ul>' # _html << '</ul>'
_html.html_safe # _html.html_safe
end # end
end end
<%#
desc:
- タグTreeを表示
- フィルタリングフォームあり
css:
- mod-tag-tree.css
locals:
- root {Model}
usage:
render partial: 'partials/tag_tree', locals: { root: Tag }
%>
<ul class="mod-tag-tree">
<input type="search" class="mod-tag-tree-filter form-control" placeholder="filter...">
<% root.roots.each do |tag_root| %>
<li>
<%= h_display_tree(tag_root) %>
</li>
<% end %>
</ul>
...@@ -18,9 +18,7 @@ ...@@ -18,9 +18,7 @@
<div class="tab-pane" id="tab-tree"> <div class="tab-pane" id="tab-tree">
<% cache('tag-tree', :expires_in => 1.hour) do %> <% cache('tag-tree', :expires_in => 1.hour) do %>
<div class="list-group"> <div class="list-group">
<% Tag.roots.each do |root| %> <%= Tag.all.decorate.tree_view %>
<%= h_display_tree(root) %>
<% end %>
</div> </div>
<% end %> <% end %>
</div><!-- /.tab-pane --> </div><!-- /.tab-pane -->
......
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
<div class="modal-body"> <div class="modal-body">
<h4>マージ先のTagを選んでください</h4> <h4>マージ先のTagを選んでください</h4>
<div id="merge-tag-tree"> <div id="merge-tag-tree">
<%= render partial: 'partials/tag_tree', locals: { root: Tag } %> <%= Tag.all.decorate.tree_view %>
</div> </div>
</div> </div>
......
require 'spec_helper'
describe TagDecorator do
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment