Commit 7edcdf72 authored by Floréal Toumikian's avatar Floréal Toumikian

Fixed: code smells

parent 737fba15
Pipeline #26430 passed with stage
in 1 minute and 9 seconds
......@@ -2,7 +2,7 @@
title: Tags
---
<ul>
<% for tag_link in (all_tag_links ' ', class: 'chip') %>
<% for tag_link in (all_tag_links class: 'chip') %>
<li><%= tag_link %></li>
<% end %>
</ul>
def authors item
authors = item[:author_name]
[ authors ].flatten
# frozen_string_literal: true
def authors(item)
[item[:author_name]].flatten
end
# frozen_string_literal: true
# Will insert external comment app "isso"
module Comments
ISSO_URL = "isso.url"
ISSO_URL = 'isso.url'
def comments_base_url
@comments_base_url = File.read(ISSO_URL).rstrip if @comments_base_url.nil?
@comments_base_url
end
def comments_section
'<section id="isso-thread"></section>'
'<section id="isso-thread"></section>'
end
def comments_script
<<-eos
<<-HTML
<script data-isso="#{comments_base_url}/"
data-isso-lang="fr"
src="#{comments_base_url}/js/embed.min.js"></script>
eos
HTML
end
end
......
# frozen_string_literal: true
include Nanoc::Helpers::Tagging
include Nanoc::Helpers::Blogging
include Nanoc::Helpers::LinkTo
......
# frozen_string_literal: true
require 'i18n'
# Helper allowing to localize date and time
module Localization
def localize_date date
# Localises a given date
def localize_date(date)
setup_locales unless locales_loaded?
I18n.l date, format: :long
end
# Checks wheter locale is loaded or not
def locales_loaded?
!I18n.load_path.empty?
end
# Configures locale
def setup_locales
I18n.load_path = Dir.glob(locale_config[:pattern])
I18n.default_locale = locale_config[:default].to_sym
end
# Returns locale section configuration
def locale_config
@config[:locale]
end
......
# frozen_string_literal: true
require 'erb'
# Provides feature related to page tagging
......@@ -14,7 +16,7 @@ module TagPages
end
# finds each tags from every page. Each tag appears once in the result
# which is sorted
# which is sorted
# @return Array an array of String (tag)
def all_tags
# keeps from rebuilding tag list each time this method is called
......@@ -30,28 +32,31 @@ module TagPages
# finds all tags for every pages and create a link for each
#
# @return String
def all_tag_links separator = ' ', attributes = {}
def all_tag_links(attributes = {})
all_tags.map { |tag| tag_link tag, attributes }
end
# finds out what should tag pages base path should be
# will read configuration in nanorc.yml file or provide
# a default path (/tags)
# @example Configuring tag prefix
# @example Configuring tag prefix
#
# tag_pages:
# prefix: /keywords
#
# @return String the tag page prefix
def tag_pages_prefix
default = "/tags"
return @config[:tag_pages][:prefix] || default unless @config[:tag_pages].nil?
default = '/tags'
tag_pages_conf = @config[:tag_pages]
return @config[:tag_pages][:prefix] || default unless tag_pages_conf.nil?
default
end
# provide a link to a tag page. Uses #tag_page_pefix to build the tag page path
# provide a link to a tag page. Uses #tag_page_pefix to build the tag page
# path
#
# @see #tag_pages_prefix
def tag_link tag, attributes = {}
def tag_link(tag, attributes = {})
link_to tag, @items["#{tag_pages_prefix}/#{tag}.html"], attributes
end
......@@ -59,8 +64,8 @@ module TagPages
# to the tag pages
#
# @return String
def tag_links_for item, separator = ' ', links_attributes = {}
item[:tags].map { |tag| tag_link tag, links_attributes }.join(separator) unless item[:tags].nil?
def tag_links_for(item, separator = ' ', links_attributes = {})
item[:tags].map { |tag| tag_link tag, links_attributes }&.join(separator)
end
# Creates one Nanoc::Item for each tag
......@@ -70,12 +75,10 @@ module TagPages
def create_tags_pages
all_tags.map do |tag|
@items.create(
"<ul>
<% items_with_tag(\"#{tag}\").each do |item| %>
"<ul><% items_with_tag(\"#{tag}\").each do |item| %>
<li><%= link_to item[:title], item %></li>
<% end %>
</ul>",
{ :title => "Tag: #{tag}" },
<% end %></ul>",
{ title: "Tag: #{tag}" },
"#{tag_pages_prefix}/#{tag}.html"
)
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment