refactors settings/flags helper to memoize values
This commit is contained in:
committed by
Juanjo Bazán
parent
90f79e4bd5
commit
0325dd6199
@@ -7,7 +7,7 @@ module AdminHelper
|
||||
def official_level_options
|
||||
options = [["",0]]
|
||||
(1..5).each do |i|
|
||||
options << [[t("admin.officials.level_#{i}"), Setting["official_level_#{i}_name"]].compact.join(': '), i]
|
||||
options << [[t("admin.officials.level_#{i}"), setting["official_level_#{i}_name"]].compact.join(': '), i]
|
||||
end
|
||||
options
|
||||
end
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
module FeatureFlagsHelper
|
||||
def feature?(name)
|
||||
!!Setting["feature.#{name}"]
|
||||
end
|
||||
end
|
||||
11
app/helpers/settings_helper.rb
Normal file
11
app/helpers/settings_helper.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
module SettingsHelper
|
||||
|
||||
def feature?(name)
|
||||
setting["feature.#{name}"].presence
|
||||
end
|
||||
|
||||
def setting
|
||||
@all_settings ||= Hash[ Setting.all.map{|s| [s.key, s.value.presence]} ]
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,4 +1,5 @@
|
||||
class ApplicationMailer < ActionMailer::Base
|
||||
helper :settings
|
||||
default from: "participacion@madrid.es"
|
||||
layout 'mailer'
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class DeviseMailer < Devise::Mailer
|
||||
helper :application
|
||||
helper :application, :settings
|
||||
include Devise::Controllers::UrlHelpers
|
||||
default template_path: 'devise/mailer'
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<li class="name">
|
||||
<%= link_to root_path do %>
|
||||
<%= image_tag('header_logo_madrid.png', class: 'left', size: '96x96', alt: t("layouts.header.logo")) %>
|
||||
<%= Setting['org_name'] %> <span>|</span> <span class="logo-site"><%= t("admin.dashboard.index.title") %></span>
|
||||
<%= setting['org_name'] %> <span>|</span> <span class="logo-site"><%= t("admin.dashboard.index.title") %></span>
|
||||
<% end %>
|
||||
</li>
|
||||
<li class="toggle-topbar menu-icon"><a href="#"><span></span></a></li>
|
||||
|
||||
@@ -53,26 +53,26 @@
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-3 column social">
|
||||
<% if Setting['twitter_handle'] %>
|
||||
<%= link_to "https://twitter.com/#{Setting['twitter_handle']}", target: "_blank", title: t("social.twitter") do %>
|
||||
<% if setting['twitter_handle'] %>
|
||||
<%= link_to "https://twitter.com/#{setting['twitter_handle']}", target: "_blank", title: t("social.twitter") do %>
|
||||
<span class="sr-only"><%= t("social.twitter") %></span>
|
||||
<i class="icon-twitter"></i>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if Setting['facebook_handle'] %>
|
||||
<%= link_to "https://www.facebook.com/#{Setting['facebook_handle']}/", target: "_blank", title: t("social.facebook") do %>
|
||||
<% if setting['facebook_handle'] %>
|
||||
<%= link_to "https://www.facebook.com/#{setting['facebook_handle']}/", target: "_blank", title: t("social.facebook") do %>
|
||||
<span class="sr-only"><%= t("social.facebook") %></span>
|
||||
<i class="icon-facebook"></i>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if Setting['blog_url'] %>
|
||||
<%= link_to Setting['blog_url'], target: "_blank", title: t("social.blog") do %>
|
||||
<% if setting['blog_url'] %>
|
||||
<%= link_to setting['blog_url'], target: "_blank", title: t("social.blog") do %>
|
||||
<span class="sr-only"><%= t("social.blog") %></span>
|
||||
<i class="icon-blog"></i>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if Setting['youtube_handle'] %>
|
||||
<%= link_to "https://www.youtube.com/#{Setting['youtube_handle']}", target: "_blank", title: t("social.youtube") do %>
|
||||
<% if setting['youtube_handle'] %>
|
||||
<%= link_to "https://www.youtube.com/#{setting['youtube_handle']}", target: "_blank", title: t("social.youtube") do %>
|
||||
<span class="sr-only"><%= t("social.youtube") %></span>
|
||||
<i class="icon-youtube"></i>
|
||||
<% end %>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<div class="row">
|
||||
<%= render "shared/locale_switcher" %>
|
||||
<div class="external-links">
|
||||
<%= link_to Setting['org_name'], root_path, class: ("selected" unless current_page?("/opendata")) %> |
|
||||
<%= link_to setting['org_name'], root_path, class: ("selected" unless current_page?("/opendata")) %> |
|
||||
<%= link_to t("layouts.header.external_link_transparency"), t("layouts.header.external_link_transparency_url") %> |
|
||||
<%= link_to t("layouts.header.external_link_opendata"), "/opendata", class: ("selected" if current_page?("/opendata")) %>
|
||||
</div>
|
||||
@@ -21,7 +21,7 @@
|
||||
<%= t("layouts.header.open_gov", open: "#{t('layouts.header.open')}") %> <span>|</span>
|
||||
<span class="logo-site"><%= t("layouts.header.open_data") %></span>
|
||||
<% else %>
|
||||
<%= Setting['org_name'] %>
|
||||
<%= setting['org_name'] %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</li>
|
||||
@@ -43,8 +43,8 @@
|
||||
<%= link_to t("layouts.header.spending_proposals"), spending_proposals_path, class: ("active" if controller_name == "spending_proposals") %>
|
||||
<% end %>
|
||||
<%= link_to t("layouts.header.more_information"), page_path('more_information'), class: ("active" if current_page?("/more_information")) %>
|
||||
<% if Setting['blog_url'] %>
|
||||
<%= link_to Setting['blog_url'], target: "_blank" do %>
|
||||
<% if setting['blog_url'] %>
|
||||
<%= link_to setting['blog_url'], target: "_blank" do %>
|
||||
<%= t("layouts.header.external_link_blog") %>
|
||||
<i class="icon-external"></i>
|
||||
<% end %>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<title><%= content_for?(:title) ? yield(:title) : Setting['org_name'] %></title>
|
||||
<title><%= content_for?(:title) ? yield(:title) : setting['org_name'] %></title>
|
||||
<%= stylesheet_link_tag "application" %>
|
||||
<%= javascript_include_tag "vendor/modernizr" %>
|
||||
<%= javascript_include_tag "application", 'data-turbolinks-track' => true %>
|
||||
@@ -16,7 +16,7 @@
|
||||
type: "image/png" %>
|
||||
<%= content_for :social_media_meta_tags %>
|
||||
|
||||
<%= Setting['per_page_code'].try(:html_safe) %>
|
||||
<%= setting['per_page_code'].try(:html_safe) %>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<tr>
|
||||
<td style="border-bottom: 1px solid #dadfe1; padding: 20px 0;">
|
||||
<a href="#" target="_blank">
|
||||
<%= image_tag('logo_email_gobierno_abierto.png', style: "border: 0; display: block; width: 100%;max-width: 370px", alt: Setting['org_name']) %>
|
||||
<%= image_tag('logo_email_gobierno_abierto.png', style: "border: 0; display: block; width: 100%;max-width: 370px", alt: setting['org_name']) %>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -31,7 +31,7 @@
|
||||
<tr>
|
||||
<td style="text-align: center; border-top: 1px solid #dadfe1; padding-top: 20px;">
|
||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif; margin: 0;padding: 0;line-height: 1.5em;color: #797f7f; font-size: 12px;">
|
||||
<%= Setting['org_name'] %></p>
|
||||
<%= setting['org_name'] %></p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
<li class="name">
|
||||
<%= link_to management_root_path do %>
|
||||
<%= image_tag('header_logo_madrid.png', class: 'left', size: '96x96') %>
|
||||
<%= Setting['org_name'] %> <span>|</span> <span class="logo-site"><%= t("management.dashboard.index.title") %></span>
|
||||
<%= setting['org_name'] %> <span>|</span> <span class="logo-site"><%= t("management.dashboard.index.title") %></span>
|
||||
<% end %>
|
||||
</li>
|
||||
<li class="toggle-topbar menu-icon"><a href="#"><span></span></a></li>
|
||||
|
||||
@@ -35,9 +35,9 @@
|
||||
<% end %>
|
||||
|
||||
<% if voted_for?(@featured_proposals_votes, proposal) %>
|
||||
<% if Setting['twitter_handle'] %>
|
||||
<% if setting['twitter_handle'] %>
|
||||
<div class="share-supported">
|
||||
<%= social_share_button_tag(proposal.title, url: proposal_url(proposal), via: Setting['twitter_handle']) %>
|
||||
<%= social_share_button_tag(proposal.title, url: proposal_url(proposal), via: setting['twitter_handle']) %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -51,9 +51,9 @@
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if voted_for?(@proposal_votes, proposal) && Setting['twitter_handle'] %>
|
||||
<% if voted_for?(@proposal_votes, proposal) && setting['twitter_handle'] %>
|
||||
<div class="share-supported">
|
||||
<%= social_share_button_tag(proposal.title, url: proposal_url(proposal), via: Setting['twitter_handle']) %>
|
||||
<%= social_share_button_tag(proposal.title, url: proposal_url(proposal), via: setting['twitter_handle']) %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -6,15 +6,15 @@
|
||||
<meta name="twitter:image" content="<%= image_url '/social-media-icon.png' %>" />
|
||||
<!-- Facebook OG -->
|
||||
<meta id="ogtitle" property="og:title" content="<%= social_title %>"/>
|
||||
<% if Setting['url'] %>
|
||||
<meta property="article:publisher" content=<%= Setting['url'] %>/>
|
||||
<% if setting['url'] %>
|
||||
<meta property="article:publisher" content=<%= setting['url'] %>/>
|
||||
<% end %>
|
||||
<% if Setting['facebook_handle'] %>
|
||||
<meta property="article:author" content="https://www.facebook.com/<%= Setting['facebook_handle'] %>"/>
|
||||
<% if setting['facebook_handle'] %>
|
||||
<meta property="article:author" content="https://www.facebook.com/<%= setting['facebook_handle'] %>"/>
|
||||
<% end %>
|
||||
<meta property="og:type" content="article"/>
|
||||
<meta id="ogurl" property="og:url" content="<%= social_url %>"/>
|
||||
<meta id="ogimage" property="og:image" content="<%= image_url '/social-media-icon.png' %>"/>
|
||||
<meta property="og:site_name" content="<%= Setting['org_name'] %>"/>
|
||||
<meta property="og:site_name" content="<%= setting['org_name'] %>"/>
|
||||
<meta id="ogdescription" property="og:description" content="<%= social_description %>"/>
|
||||
<meta property="fb:app_id" content="<%= Rails.application.secrets.facebook_key %>"/>
|
||||
|
||||
@@ -5,7 +5,6 @@ describe GeozonesHelper do
|
||||
describe "#geozones_name" do
|
||||
let(:geozone) { create :geozone }
|
||||
|
||||
|
||||
it "returns geozone name if present" do
|
||||
spending_proposal = create(:spending_proposal, geozone: geozone)
|
||||
expect(geozone_name(spending_proposal)).to eq geozone.name
|
||||
|
||||
31
spec/helpers/settings_helper_spec.rb
Normal file
31
spec/helpers/settings_helper_spec.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SettingsHelper, type: :helper do
|
||||
|
||||
describe "#setting" do
|
||||
|
||||
it "returns a hash with all settings values" do
|
||||
Setting["key1"] = "value1"
|
||||
Setting["key2"] = "value2"
|
||||
|
||||
expect(setting["key1"]).to eq("value1")
|
||||
expect(setting["key2"]).to eq("value2")
|
||||
expect(setting["key3"]).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#feature?" do
|
||||
it "returns presence of feature flag setting value" do
|
||||
|
||||
Setting["feature.f1"] = "active"
|
||||
Setting["feature.f2"] = ""
|
||||
Setting["feature.f3"] = nil
|
||||
|
||||
expect(feature? "f1").to eq("active")
|
||||
expect(feature? "f2").to eq(nil)
|
||||
expect(feature? "f3").to eq(nil)
|
||||
expect(feature? "f4").to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user