Skip to content

Commit

Permalink
Order methods logically
Browse files Browse the repository at this point in the history
  • Loading branch information
tijmenb committed Apr 24, 2018
1 parent 2e1d209 commit 3cf0a6b
Showing 1 changed file with 63 additions and 63 deletions.
126 changes: 63 additions & 63 deletions lib/govuk_publishing_components/presenters/meta_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,50 @@ def meta_tags

private

def has_content_history?
(content_item[:public_updated_at] && details[:first_public_at] && content_item[:public_updated_at] != details[:first_public_at]) ||
(details[:change_history] && details[:change_history].size > 1)
end
def add_core_tags(meta_tags)
meta_tags["govuk:format"] = content_item[:document_type] if content_item[:document_type]
meta_tags["govuk:schema-name"] = content_item[:schema_name] if content_item[:schema_name]

def root_taxon_slugs(content_item)
root_taxon_set = Set.new
user_journey_stage = content_item[:user_journey_document_supertype]
meta_tags["govuk:user-journey-stage"] = user_journey_stage if user_journey_stage

links = content_item[:links]
# Taxons will have :parent_taxons, but content items will have :taxons
parent_taxons = links[:parent_taxons] || links[:taxons] unless links.nil?
navigation_document_type = content_item[:navigation_document_supertype]
meta_tags["govuk:navigation-document-type"] = navigation_document_type if navigation_document_type

if parent_taxons.blank?
root_taxon_set << content_item[:base_path].sub(%r(^/), '') if content_item[:document_type] == 'taxon'
else
parent_taxons.each do |parent_taxon|
root_taxon_set += root_taxon_slugs(parent_taxon)
end
end
meta_tags["govuk:content-id"] = content_item[:content_id] if content_item[:content_id]
meta_tags["govuk:withdrawn"] = "withdrawn" if content_item[:withdrawn_notice].present?
meta_tags["govuk:content-has-history"] = "true" if has_content_history?
meta_tags["govuk:static-analytics:strip-postcodes"] = "true" if should_strip_postcode_pii?(content_item, local_assigns)

root_taxon_set
meta_tags
end

def should_strip_postcode_pii?(content_item, local_assigns)
# allow override if we explicitly want to strip pii (or not) regardless of
# document_type
return local_assigns[:strip_postcode_pii] if local_assigns.key?(:strip_postcode_pii)
def add_organisation_tags(meta_tags)
organisations = []
organisations += links[:organisations] || []
organisations += links[:worldwide_organisations] || []
organisations_content = organisations.map { |link| "<#{link[:analytics_identifier]}>" }.uniq.join
meta_tags["govuk:analytics:organisations"] = organisations_content if organisations.any?

formats_that_might_include_postcodes = [
'smart_answer',
'search'
]
formats_that_might_include_postcodes.include?(content_item[:document_type])
world_locations = links[:world_locations] || []
world_locations_content = world_locations.map { |link| "<#{link[:analytics_identifier]}>" }.join
meta_tags["govuk:analytics:world-locations"] = world_locations_content if world_locations.any?

meta_tags
end

def add_political_tags(meta_tags)
if details.key?(:political) && details.key?(:government)
political_status = "non-political"
if details[:political]
political_status = details[:government][:current] ? "political" : "historic"
end

meta_tags["govuk:political-status"] = political_status
meta_tags["govuk:publishing-government"] = details[:government][:slug]
end

meta_tags
end

def add_taxonomy_tags(meta_tags)
Expand Down Expand Up @@ -94,50 +105,39 @@ def add_step_by_step_tags(meta_tags)
meta_tags
end

def add_core_tags(meta_tags)
meta_tags["govuk:format"] = content_item[:document_type] if content_item[:document_type]
meta_tags["govuk:schema-name"] = content_item[:schema_name] if content_item[:schema_name]

user_journey_stage = content_item[:user_journey_document_supertype]
meta_tags["govuk:user-journey-stage"] = user_journey_stage if user_journey_stage

navigation_document_type = content_item[:navigation_document_supertype]
meta_tags["govuk:navigation-document-type"] = navigation_document_type if navigation_document_type

meta_tags["govuk:content-id"] = content_item[:content_id] if content_item[:content_id]
meta_tags["govuk:withdrawn"] = "withdrawn" if content_item[:withdrawn_notice].present?
meta_tags["govuk:content-has-history"] = "true" if has_content_history?
meta_tags["govuk:static-analytics:strip-postcodes"] = "true" if should_strip_postcode_pii?(content_item, local_assigns)

meta_tags
def has_content_history?
(content_item[:public_updated_at] && details[:first_public_at] && content_item[:public_updated_at] != details[:first_public_at]) ||
(details[:change_history] && details[:change_history].size > 1)
end

def add_organisation_tags(meta_tags)
organisations = []
organisations += links[:organisations] || []
organisations += links[:worldwide_organisations] || []
organisations_content = organisations.map { |link| "<#{link[:analytics_identifier]}>" }.uniq.join
meta_tags["govuk:analytics:organisations"] = organisations_content if organisations.any?

world_locations = links[:world_locations] || []
world_locations_content = world_locations.map { |link| "<#{link[:analytics_identifier]}>" }.join
meta_tags["govuk:analytics:world-locations"] = world_locations_content if world_locations.any?
def root_taxon_slugs(content_item)
root_taxon_set = Set.new

meta_tags
end
links = content_item[:links]
# Taxons will have :parent_taxons, but content items will have :taxons
parent_taxons = links[:parent_taxons] || links[:taxons] unless links.nil?

def add_political_tags(meta_tags)
if details.key?(:political) && details.key?(:government)
political_status = "non-political"
if details[:political]
political_status = details[:government][:current] ? "political" : "historic"
if parent_taxons.blank?
root_taxon_set << content_item[:base_path].sub(%r(^/), '') if content_item[:document_type] == 'taxon'
else
parent_taxons.each do |parent_taxon|
root_taxon_set += root_taxon_slugs(parent_taxon)
end

meta_tags["govuk:political-status"] = political_status
meta_tags["govuk:publishing-government"] = details[:government][:slug]
end

meta_tags
root_taxon_set
end

def should_strip_postcode_pii?(content_item, local_assigns)
# allow override if we explicitly want to strip pii (or not) regardless of
# document_type
return local_assigns[:strip_postcode_pii] if local_assigns.key?(:strip_postcode_pii)

formats_that_might_include_postcodes = [
'smart_answer',
'search'
]
formats_that_might_include_postcodes.include?(content_item[:document_type])
end
end
end
Expand Down

0 comments on commit 3cf0a6b

Please sign in to comment.