module GroupTags include Radiant::Taggable include ReaderHelper class TagError < StandardError; end desc %{ The root 'group' tag is not meant to be called directly. All it does is summon a group object so that its fields can be displayed with eg.
To show a particular group, supply an id or name attribute. There is no access control
involved here: if you choose to show a group on an unrestricted page, it will appear.
Note that because of limitations in radius this has to be done in a containing root tag:
}
tag 'group' do |tag|
tag.locals.group = if tag.attr['id']
Group.find_by_id(tag.attr['id'])
elsif tag.attr['name']
Group.find_by_name(tag.attr['name'])
elsif @mailer_vars
@mailer_vars[:@group]
else
tag.locals.page.homegroup
end
tag.expand if tag.locals.group
end
[:name, :description, :url].each do |field|
desc %{
Displays the #{field} field of the currently relevant group. Works in email messages too.
}
tag "group:#{field}" do |tag|
tag.locals.group.send(field)
end
end
desc %{
Expands if this group has messages.
...
}
tag "group:if_messages" do |tag|
tag.expand if tag.locals.group.messages.ordinary.published.any?
end
desc %{
Expands if this group does not have messages.
...
}
tag "group:unless_messages" do |tag|
tag.expand unless tag.locals.group.messages.ordinary.published.any?
end
desc %{
Loops through the non-functional messages (ie not welcomes and reminders) that belong to this group
and that have been sent, though not necessarily to the present reader (which is the point, really).
...
}
tag "group:messages" do |tag|
tag.locals.messages = tag.locals.group.messages.ordinary.published
tag.expand
end
tag "group:messages:each" do |tag|
result = []
tag.locals.messages.each do |message|
tag.locals.message = message
result << tag.expand
end
result
end
end