Skip to content

Commit

Permalink
Add page:if_has_content_for and page:unless_has_content_for. Fixes #40
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroedin committed Feb 29, 2016
1 parent 2e57bbe commit fb7b14a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions hammer/services/tags/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,27 @@ class Page < TagContainer
end
end

# Expands tag if current page editable region has content
tag 'page:if_has_content_for' do |tag|
rname = tag.attr['region'].strip
always = tag.attr['always_show_in_edit_mode'].to_s.to_b && tag.globals.context.data['edit_mode'] == true
content = nil
if tag.globals.context.data["page"] && tag.globals.context.data["page"]["content"] && tag.globals.context.data["page"]["content"][rname]
content = tag.globals.context.data["page"]["content"][rname]
end
tag.expand if always || !content.nil?
end

tag 'page:unless_has_content_for' do |tag|
rname = tag.attr['region'].strip
always = tag.attr['always_show_in_edit_mode'].to_s.to_b && tag.globals.context.data['edit_mode'] == true
content = nil
if tag.globals.context.data["page"] && tag.globals.context.data["page"]["content"] && tag.globals.context.data["page"]["content"][rname]
content = tag.globals.context.data["page"]["content"][rname]
end
tag.expand if always || content.nil?
end

# Page template tags
tag 'page:template' do |tag|
# tag.locals.page_template = tag.locals.page.template
Expand Down

0 comments on commit fb7b14a

Please sign in to comment.