Using Middleman Tags - middleman

I am wondering if someone could explain how I can utilise tags in an article.
The documentation states that by default the blog extension should allow you to access tagged articles via tags/blogging.html. http://middlemanapp.com/guides/blog
I guess I'm not sure if I need to create this dir (tags/blogging.html) or if its generated for me?
Then I'm wondering how to create a list of tags, each with a URL that points to this tag template.
I've added this example tag data to the front matter of a few of my articles.
---
title: My Middleman Blog Post
date: 2011/10/18
category: music
tags: blogging, middleman, hello, world
---
my index.html.erb looks like this:
<section class="article-index music">
<% data.blog.articles.each_with_index do |article, i| %>
<% if article.category == 'music' %>
<article>
<h2><%= article.title %></h2>
<time pubdate><%= article.date.strftime('%b %e') %></time>
<span class="categories"><%= article.tags %></span>
<%= article.summary %>
</article>
<% end %>
<% end %>
</section>
This is outputting all my articles, with a title, date, all tags and a summary.
I'm assuming you need to loop through all the tags and output each in a URL of its own, but I'm not really sure of the best way to do this.
At a guess I'm assuming its something like:
<% article.tags.each do |tag| %>
tag
<% end %>
Any help is appreciated.
Thanks

By combining the other answers I have come up with this solution.
<% article.tags.each do |tag| %>
<%= link_to tag, tag_path(tag) %>
<% end %>
It has the benefit of using a generated path, rather than the hardcoded one.

Tags for all articles can be retrieved with the following:
<% blog.tags.each do |tag, articles| %>
<%= link_to tag, tag_path(tag) %> (<%= articles.size %>)<br />
<% end %>
This is exactly what I have on my blog:-
Blog
Github

Currently, you'd have to do it like so:
<% article.tags.split(", ").each do |tag| %>
tag
<% end %>
Assuming your tags are separated with a comma and a space.

I write my tags in the frontmatter as an array
tags : [ accessibility, standards ]
Then I can just loop through them
In HAML it would ne
- current_page.data.tags.each do | tag |

Not supported in 2.0. Possibly in upcoming 3.0

This works perfectly for me in HAML for just displaying the tags, no links
%p= article.tags.join(', ')

Related

view contain all data from database

i'm learning Rails 3, i'm generating a User, a User have many Post. but when i'm creating some Post all data from database appear like this in user/view/show.html.erb :
Post id: 2, title: "hello post", description: "hello posting", user_id: 2, created_at:"2013-03-01 16:18:07", updated_at: "2013-03-01 16:18:07"
my code in show.html.erb like this :
<%= #user.posts.each do |post| %>
<p>
<%= post.title %>
</p>
<p>
<%= post.description%>
</p>
<% end %>
how to hide all post data from database? Thanks..
The problem is that you're using the <%= %> embed rather than <% %> for your loop (<%= #user.posts.each do |post| %>). The loop returns the array of Post objects, and then your use of <%= tells erb to stick that value into the page.
You want to use <% #user.posts.each do |post| %> instead (without =). That means to execute the code, but not display it's result.

Activerecord iteration / append an exception at a certain position

I'm looking for a way to include a specific element at a certain position inside an iteration
Not experienced enough to use the right pattern (hence to search here on stack overflow with the right keywords, afraid of getting some duplicate question with this one)… but the base idea would as the following :
<% Post.all.each do |post| %>
<% if Post.all.index(post) == 5 # or any position %>
# render some html element (some kind of exception)
<% else %>
<%= post.title %>
<% end %>
<% end %>
But just without skipping any records in my post array
I'm not sure I have totally understood your request. each_with_index may help you, and if you don't use the else, you won't skip any records :
<% Post.all.each_with_index do |post, index| %>
<% if index == 5 # or any position %>
# render some html element (some kind of exception)
<% end %>
<%= post.title %>
<% end %>

How to specify twitter bootstrap's <i> tag in Embedded Ruby

-Newbie to Ruby on Rails and integrating a few aspects of Twitter Bootstrap in (or at least trying :))-
I have a link in regular HTML with Twitter Bootstrap icons in it:
<li class="sidebar"><i class="icon-user"></i> Home</li>
(The i tag is for twitter's image icons)
If I were writing that same HTML in embedded Ruby, how could I still get the icon in there?
Right now I have:
<%= link_to content_tag(:li, "Home"), root_path %>
Is it possible to specify Twitter's tag in embedded ruby?
Also, should I specify the sidebar class in regular html or with :class => "sidebar"
Thanks!
Sure, just try something like:
<%= content_tag(:li, :class => 'sidebar') do %>
<%= link_to '#' do %>
<%= content_tag :i, '', :class => 'icon-user' %> Home
<% end -%>
<% end -%>
The shorter alternative I use is
link_to " ".html_safe, '#'
It's 'dirtier' but somewhat easier to understand.

how can i use fb_server_fbml helper method in facebooker2?

I am developing a facebook app using rails 3 and facebooker2
i cannot find any example on how to use fb_server_fbml helper method.
what is "proc" in its paramter. Can anyone provide me with sample code?
Thanks
The &proc parameter is used as a content block that is inserted between the <fb:serverFbml> tags. You can learn more about block helpers and differences between Rails 2.3 and Rails 3 here: Block Helpers in Rails 3
So, try something like this:
<% fb_server_fbml do %>
<%#Insert here your content %>
<% end %>
If you want to use the request form, try the following:
<% fb_server_fbml do %>
<% fb_request_form("Your app name","http://www.example.com/callback","Try this out!") do %>
<%= fb_multi_friend_selector("Invite your friends:", {:rows => 3}) %>
<% end %>
<% end %>

Is it possible to use partials to be rendered as wrappers in Rails?

I would like to render structures like this:
<tag1>
<tag2 someattribute="somevalue">
<.. lot of things inside ..>
</tag2>
</tag1>
<tag1>
<tag2 someattribute="someothervalue">
<.. different inside things inside ..>
</tag2>
</tag1>
The tag1, tag2 are the same, they are just parametrized. The inner part of the code changes. I tried to implement the thing above like that (haml):
%div{id:['products', id]}
.products_content
%div{id:['products', id, 'content'], class:'products_mask'}
= yield
This was the partial _content_head.html.haml, which is called from a template:
= render 'shared/content_head', id: 'all' do
%h3= Title
%p= Body of the text.
My theory that yield inside the partial would lead to rendering of the passed block did not prove. Is there a way to use partials as code wrappers? Can you suggest me some solution how to reach this? Thank you.
This might be a good use of the capture method.
I'm only familiar with ERB, but here is the general idea:
<% structure = capture do %>
<h3>Title</h3>
<p>Body of text</p>
<% end %>
Then pass the variable into the partial:
<%= render 'shared/content_head', :structure => structure %>
And within the partial, spit out the structure variable:
<%= structure %>
Reset structure multiple times within the view as you render partials (or maybe more appropriately, in a helper?).
I've used the following (Rails 4, but I think it should work with Rails 3 too):
<%# app/views/users/_edit.html.erb %>
<%= render layout: 'modal_wrapping' do |f| %>
<%= f.input :email %>
...
<% end %>
.
<%# app/views/users/_modal_wrapping.html.erb %>
<div id='modal'>
<%= simple_form_for #user do |f| %>
<%= yield f %>
<% end %>
</div>