Semantics, Code and Circumstance
April 10, 2010: This afternoon I recieved a visit from a plushy black cat. I've never seen her before and since she has a collar she may be moved in with her owner in the last days.
Read more about project 365 ...This plugin provides a liquid filter for the mephisto blog engine for inclusion of calendars hosted by Google.
Installation
Installation takes three simple steps.
Usage
This plugin offers you a liquid filter. You may call this filter from every liquid template. Provide the liquid filter call with the private url of your calendars ical file. The number at the end specifies the number of items you may get. Example:
{{ 'https://www.google.com/calendar/ical/your.user.name/private-xxxxx/basic.ics' | gcal_shortlist, 7 }}
This little plugin provides you with a protected area for your users on your mephisto blog. Its built to use engines compatible mephisto available in the mephisto version 8.2.
To install this plugin, run:
script/generate plugin_migration
rake db:migrate RAILS_ENV=production
This will make some changes to your production database and will expose a new Userlogin tab to your Mephisto administration interface. From there you can create new userlogins. When creating new userlogins provide a username and a password (Attention! This is designed for ease of use and easy remebering. The passwords are NOT ENCRYPTED! Don’t use this for really important stuff) along with some sites you like to provide inside of the protected area.
You need to create a liquid template for every site you list as protected. So, if you list “family_gallery” as a protected site, you need to create a template called “family_gallery.liquid”. This page will be available at http://yoursite.com/protected/family_galery. The page http://yoursite.com/protected will show a login form (if not logged in) or the conten of “protected_index.liquid” (otherwise).
Coding in hastiness combined with a limited vocabulary late at night will certainly result in comprehension difficulties at the very next morning:
<%= "#{t("role.role")}" %>: <%= "#{t("role."+role.role)}" %>
Kids, don’t try this at home.
It is wildly known and even somewhat accepted, that the pagination mechanism of Mephisto 0.8.2 is very buggy and non-functional. However, paging blog posts is a feature that kills a blog engine if it does not work. Fortunately, James of Rails Talk wrote a nice tutorial for bringing up paging again. His description is easy done and works well, as long as you have only one section, the mandatory Home section.
However, blogs with multiple sections (like this one) faced a strange problem with doubled section names in URLs. A workaround with separate URL helpers for each section exists, but is utterly unhandy. After some investigation it turns out, that a small change to the original tutorial solves the whole section difficulty. The original instruction was to add the following to mephisto_paged_article_list/lib/paged_article_list/link_helpers.rb:
def path_for( path_info, page_number )
return path_info[:path] + "/page/" + page_number.to_s
end
Now, when using this with multiple sections, path_info[:path] contains the name of the current section (or nothing, if the section is Home). Moreover, the produced path is a relative path, so that the returned string will be appended to the base URL that already contains the section name as the last part. This is where the doubled section names come from. To remove this behaviour, we need to change the code a little bit:
def path_for( path_info, page_number )
path = path_info[:path] + '/page/' + page_number.to_s
path_info[:path].blank? ? path : '/' + path
end
With this code, we assemble the path the same way, but precede it with a ’/’ whenever the section name is not empty. This gives us a non-relative URL without the doubled section name and thus correct pagination URLs for all sections.
On my crusade on gaining more insight into mephisto, I felt it would be helpful to see how this plugin thingy works. I found, that writing your own mephisto plugin is not as hard as you would think. In fact, it is real easy. Start with generating the plugin skeleton.
# ruby script/generate plugin NameOfYourPlugin
Now, define your method inside lib/name_of_your_plugin.rb.
module NameOfYourPlugin
def link_to_something_strange(object_to_yield)
url = 'http://example.com/api?'
url += "id=#{object_to_yield['some_attribute']}"
content_tag :a, 'foobar', :href => url
end
end
After that, open init.rb and paste in the following:
require 'name_of_your_plugin'
Liquid::Template.register_filter NameOfYourPlugin
The first line is the standard registration you need for every rails plugin. The second line registers whatever method you defined as a global liquid filter. If you like to add another filter, just put the method inside lib/name_of_your_plugin.rb and it will be automagically registered.
The last step is to include your fresh filter into the liquid template.
{{ object_to_yield | link_to_something_strange }}
That’s all folks. Really. Be sure to check the first fruit of this new gained insights.