From f024f6297053c7fd36a84348d46dadaca962b52d Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 6 May 2015 16:36:10 +1000 Subject: [PATCH] Content-manage footer fields --- Gemfile | 1 + Gemfile.lock | 2 + app/controllers/admin/contents_controller.rb | 3 +- app/helpers/markdown_helper.rb | 6 +++ app/models/content_configuration.rb | 15 +++++++ app/views/admin/contents/_fieldset.html.haml | 8 ++++ app/views/admin/contents/edit.html.haml | 10 +---- app/views/shared/_footer.html.haml | 42 ++++++++++---------- config/locales/en.yml | 12 +++++- spec/features/admin/content_spec.rb | 12 ++++++ 10 files changed, 81 insertions(+), 30 deletions(-) create mode 100644 app/helpers/markdown_helper.rb create mode 100644 app/views/admin/contents/_fieldset.html.haml diff --git a/Gemfile b/Gemfile index b63961a3ef..0ab0e38c2a 100644 --- a/Gemfile +++ b/Gemfile @@ -30,6 +30,7 @@ gem 'newrelic_rpm' gem 'haml' gem 'sass', "~> 3.3" gem 'sass-rails', '~> 3.2.3', groups: [:default, :assets] +gem 'redcarpet' gem 'aws-sdk' gem 'db2fog' gem 'andand' diff --git a/Gemfile.lock b/Gemfile.lock index 17dbfdf8c5..5d4b2a0e4e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -424,6 +424,7 @@ GEM ffi (>= 0.5.0) rdoc (3.12.2) json (~> 1.4) + redcarpet (3.2.3) ref (1.0.5) representative (1.0.5) activesupport (>= 2.2.2) @@ -583,6 +584,7 @@ DEPENDENCIES rack-ssl rails (= 3.2.21) rails-i18n (~> 3.0.0) + redcarpet representative_view roadie-rails (~> 1.0.3) rspec-rails diff --git a/app/controllers/admin/contents_controller.rb b/app/controllers/admin/contents_controller.rb index 8e46bed7c9..a048981f5e 100644 --- a/app/controllers/admin/contents_controller.rb +++ b/app/controllers/admin/contents_controller.rb @@ -1,7 +1,8 @@ module Admin class ContentsController < Spree::Admin::BaseController def edit - @preferences = [:home_tagline_cta, :home_whats_happening, :footer_about_url] + @preferences_home = [:home_tagline_cta, :home_whats_happening] + @preferences_footer = [:footer_facebook_url, :footer_twitter_url, :footer_instagram_url, :footer_linkedin_url, :footer_googleplus_url, :footer_pinterest_url, :footer_email, :footer_links_md, :footer_about_url] end def update diff --git a/app/helpers/markdown_helper.rb b/app/helpers/markdown_helper.rb new file mode 100644 index 0000000000..bd45e31124 --- /dev/null +++ b/app/helpers/markdown_helper.rb @@ -0,0 +1,6 @@ +module MarkdownHelper + def render_markdown(markdown) + md ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, no_intra_emphasis: true, tables: true, autolink: true, superscript: true) + md.render markdown + end +end diff --git a/app/models/content_configuration.rb b/app/models/content_configuration.rb index 41f958abf8..22eb6e0d87 100644 --- a/app/models/content_configuration.rb +++ b/app/models/content_configuration.rb @@ -2,5 +2,20 @@ class ContentConfiguration < Spree::Preferences::Configuration preference :home_tagline_cta, :string, default: "Browse Open Food Network Australia" preference :home_whats_happening, :string, default: "Thanks for making the Open Food Network possible. Our vision is a better food system, and we're proud of what we're achieving together." + preference :footer_facebook_url, :string, default: "https://www.facebook.com/OpenFoodNet" + preference :footer_twitter_url, :string, default: "https://twitter.com/OpenFoodNet" + preference :footer_instagram_url, :string, default: "" + preference :footer_linkedin_url, :string, default: "http://www.linkedin.com/groups/Open-Food-Foundation-4743336" + preference :footer_googleplus_url, :string, default: "" + preference :footer_pinterest_url, :string, default: "" + preference :footer_email, :string, default: "hello@openfoodnetwork.org" + preference :footer_links_md, :text, default: <<-EOS +[Newsletter sign-up](/) + +[Blog](/) + +[Calendar](/) +EOS + preference :footer_about_url, :string, default: "http://global.openfoodnetwork.org/ofn-local/open-food-network-australia/" end diff --git a/app/views/admin/contents/_fieldset.html.haml b/app/views/admin/contents/_fieldset.html.haml new file mode 100644 index 0000000000..709f3d5ec8 --- /dev/null +++ b/app/views/admin/contents/_fieldset.html.haml @@ -0,0 +1,8 @@ +%fieldset.no-border-bottom + %legend{align: "center"}= name + - preferences.each do |key| + - type = ContentConfig.preference_type(key) + .field + = label_tag(key, t(key) + ': ') + tag(:br) if type != :boolean + = preference_field_tag(key, ContentConfig[key], :type => type) + = label_tag(key, t(key)) + tag(:br) if type == :boolean diff --git a/app/views/admin/contents/edit.html.haml b/app/views/admin/contents/edit.html.haml index ec53db23b3..ef4467f09d 100644 --- a/app/views/admin/contents/edit.html.haml +++ b/app/views/admin/contents/edit.html.haml @@ -6,14 +6,8 @@ = form_tag main_app.admin_content_path, method: :put do #preferences - %fieldset.no-border-bottom - %legend{align: "center"} Home page - - @preferences.each do |key| - - type = ContentConfig.preference_type(key) - .field - = label_tag(key, t(key) + ': ') + tag(:br) if type != :boolean - = preference_field_tag(key, ContentConfig[key], :type => type) - = label_tag(key, t(key)) + tag(:br) if type == :boolean + = render 'fieldset', name: 'Home page', preferences: @preferences_home + = render 'fieldset', name: 'Footer', preferences: @preferences_footer .form-buttons.filter-actions.actions{"data-hook" => "buttons"} = button t(:update), 'icon-refresh' diff --git a/app/views/shared/_footer.html.haml b/app/views/shared/_footer.html.haml index b73d5d8783..39aa16d046 100644 --- a/app/views/shared/_footer.html.haml +++ b/app/views/shared/_footer.html.haml @@ -52,26 +52,28 @@ // This is the instance-managed set of links: %h4 Keep in touch %p.social-icons - %a{href: "/"} - %i.ofn-i_044-facebook - %a{href: "/"} - %i.ofn-i_041-twitter - %a{href: "/"} - %i.ofn-i_043-instagram - %a{href: "/"} - %i.ofn-i_042-linkedin - %a{href: "/"} - %i.ofn-i_046-g - %a{href: "/"} - %i.ofn-i_045-pintrest - %p - %a{href: "hello@openfoodnetwork.org".reverse, target: '_blank', mailto: true} Email us - %p - %a{href: "/"} Newsletter sign-up - %p - %a{href: "/"} Blog - %p - %a{href: "/"} Calendar + - if ContentConfig.footer_facebook_url.present? + %a{href: ContentConfig.footer_facebook_url} + %i.ofn-i_044-facebook + - if ContentConfig.footer_twitter_url.present? + %a{href: ContentConfig.footer_twitter_url} + %i.ofn-i_041-twitter + - if ContentConfig.footer_instagram_url.present? + %a{href: ContentConfig.footer_instagram_url} + %i.ofn-i_043-instagram + - if ContentConfig.footer_linkedin_url.present? + %a{href: ContentConfig.footer_linkedin_url} + %i.ofn-i_042-linkedin + - if ContentConfig.footer_googleplus_url.present? + %a{href: ContentConfig.footer_googleplus_url} + %i.ofn-i_046-g + - if ContentConfig.footer_pinterest_url.present? + %a{href: ContentConfig.footer_pinterest_url} + %i.ofn-i_045-pintrest + - if ContentConfig.footer_email.present? + %p + %a{href: ContentConfig.footer_email.reverse, mailto: true, target: '_blank'} Email us + = render_markdown(ContentConfig.footer_links_md).html_safe .small-6.medium-3.columns.text-left diff --git a/config/locales/en.yml b/config/locales/en.yml index f84e5708a4..05ad5113ee 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -20,4 +20,14 @@ en: producers_join: Australian producers are now welcome to join the Open Food Network. charges_sales_tax: Charges GST? - home_tagline_cta: "Home tagline call to action" + home_tagline_cta: "Tagline call to action" + home_whats_happening: "What's happening" + footer_facebook_url: "Facebook URL" + footer_twitter_url: "Twitter URL" + footer_instagram_url: "Instagram URL" + footer_linkedin_url: "LinkedIn URL" + footer_googleplus_url: "Google Plus URL" + footer_pinterest_url: "Pinterest URL" + footer_email: "Email" + footer_links_md: "Links" + footer_about_url: "About URL" \ No newline at end of file diff --git a/spec/features/admin/content_spec.rb b/spec/features/admin/content_spec.rb index 8dd72ebd4d..045b8a3012 100644 --- a/spec/features/admin/content_spec.rb +++ b/spec/features/admin/content_spec.rb @@ -13,10 +13,22 @@ feature %q{ click_link 'Content' fill_in 'home_tagline_cta', with: 'Editable text' + fill_in 'footer_facebook_url', with: '' + fill_in 'footer_twitter_url', with: 'http://twitter.com/me' + fill_in 'footer_links_md', with: '[markdown link](/)' click_button 'Update' page.should have_content 'Your content has been successfully updated!' visit root_path + + # The content should be shown page.should have_content 'Editable text' + + # And social media icons are only shown if they have a value + page.should_not have_selector 'i.ofn-i_044-facebook' + page.should have_selector 'i.ofn-i_041-twitter' + + # And markdown is rendered + page.should have_link 'markdown link' end end