Skip to content

Commit

Permalink
Feature lead image and first paragraph of text from a wiki page on th…
Browse files Browse the repository at this point in the history
…e corresponding tag index page (resolves publiclab#973) (publiclab#985)

* Add feature publiclab#973

* Add links and properly display only first paragraph

* Fix off-by-1 bug

* Move the wiki content to above the graph

* Modify tests for the tag controller to reflect changes

* Fix erronous test
  • Loading branch information
ryzokuken authored and jywarren committed Nov 16, 2016
1 parent 1a2817e commit 72d3087
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def index
end

def show
@wiki = DrupalNode.where(path: "/wiki/#{params[:id]}").first
if params[:id].match('question:')
default_type = "questions"
else
Expand Down
22 changes: 22 additions & 0 deletions app/views/tag/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
<%= render :partial => "sidebar/related" %>
<div class="col-md-9">

<% if @wiki %>
<div id="wiki-content">
<% if @wiki.main_image %>
<div class="row">
<div class="col-md-4">
<%= image_tag(@wiki.main_image.path, class: "img-responsive") %>
</div>
<div class="col-md-8">
<h2><%= link_to @wiki.latest.title, "/wiki/#{params[:id]}" %></h2>
<%= (@wiki.latest.render_body.split('</p>').first + '</p>').html_safe %>
<%= link_to("Read More", "/wiki/#{params[:id]}") if @wiki.latest.render_body.split('</p>').length > 2 %>
</div>
</div>
<% else %>
<h2><%= @wiki.latest.title %></h2>
<%= @wiki.latest.render_body.split('\n').first.html_safe %>
<%= link_to("Read More", "/wiki/#{params[:id]}") if @wiki.latest.render_body.split('\n').length > 1 %>
<% end %>
</div>
<% end %>

<% if @tags.first %>
<div id="note-graph" style="height:100px;"></div>

Expand Down
9 changes: 9 additions & 0 deletions test/functional/tag_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ def setup
end

#assert_equal assigns['tags'].length, 1
assert_select '#wiki-content', 0
end

test "should show a featured wiki page at top, if it exists" do
tag = tags(:test)

get :show, id: node(:organizers).slug

assert_select '#wiki-content', 1
end

test "tag widget" do
Expand Down

0 comments on commit 72d3087

Please sign in to comment.