Skip to content

Commit b5ec6af

Browse files
committed
Passage à Haml 6+
La nouvelle version supprime quelques helper, dont `list_of` qui était utilisée ici et là et qui est maintenant rajoutée dans `application_helper`. Méthodes supprimées: block_is_haml?, capture_haml, escape_once, find_and_preserve, flatten, haml_concat, haml_indent, haml_tag, haml_tag_if, html_attrs, html_escape, init_haml_helpers, is_haml?, list_of, non_haml, precede, succeed, surround, tab_down, tab_up, with_tabs Référence: https://github.com/haml/haml/releases/tag/v6.0.0
1 parent 61d93f1 commit b5ec6af

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ gem "doorkeeper"
2020
gem "ffi-hunspell", github: "postmodern/ffi-hunspell"
2121
gem "french_rails", "~>0.5", github: "linuxfrorg/french-rails"
2222
gem "friendly_id", "~>5.1"
23-
gem "haml", "~>5.0"
23+
gem "haml", "~>6.3"
2424
gem "htmlentities", "~>4.3"
2525
gem "html-pipeline-linuxfr", "~>0.17", github: "linuxfrorg/html-pipeline-linuxfr"
2626
gem "html_spellchecker", "~>0.1"

Gemfile.lock

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ GEM
174174
activerecord (>= 4.0.0)
175175
globalid (1.2.1)
176176
activesupport (>= 6.1)
177-
haml (5.2.2)
178-
temple (>= 0.8.0)
177+
haml (6.3.0)
178+
temple (>= 0.8.2)
179+
thor
179180
tilt
180181
has_scope (0.8.2)
181182
actionpack (>= 5.2)
@@ -406,7 +407,7 @@ DEPENDENCIES
406407
ffi-hunspell!
407408
french_rails (~> 0.5)!
408409
friendly_id (~> 5.1)
409-
haml (~> 5.0)
410+
haml (~> 6.3)
410411
html-pipeline-linuxfr (~> 0.17)!
411412
html_spellchecker (~> 0.1)
412413
html_truncator (~> 0.4)

app/helpers/application_helper.rb

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
# encoding: utf-8
1+
# Helper methods for the whole application
22
module ApplicationHelper
3-
4-
def title(title, tag=nil)
3+
def title(title, tag = nil)
54
title = h(title)
65
@title.unshift title
76
content_tag(tag, title) if tag
@@ -11,7 +10,7 @@ def h1(str)
1110
title(str, :h1)
1211
end
1312

14-
def feed(title, link=nil)
13+
def feed(title, link = nil)
1514
link ||= { format: :atom }
1615
@feeds[link] = title
1716
end
@@ -22,15 +21,30 @@ def link(rel, link)
2221

2322
def meta_for(content)
2423
@author = content.node.user.try(:name)
25-
@keywords = content.node.popular_tags.map &:name
24+
@keywords = content.node.popular_tags.map(&:name)
2625
@description = content.title
27-
@dont_index = true if content.node.score < 0
28-
published_at = content.node.try(:created_at) || DateTime.now()
26+
@dont_index = true if content.node.score.negative?
27+
published_at = content.node.try(:created_at) || DateTime.now
2928
# For all content recently published, ask robots to not index it if
3029
# a minimum score is not reached during the first 24 hours.
3130
# The threshold is set to the one used by moderated News, so the moderated
3231
# content can still be fastly indexed by robots.
33-
@dont_index ||= true if published_at > DateTime.now() - 24.hour && content.node.score <= News.accept_threshold
32+
@dont_index ||= true if published_at > DateTime.now - 24.hours && content.node.score <= News.accept_threshold
3433
end
3534

35+
def list_of(enum, opts = {}, &block)
36+
opts_attributes = opts.map { |k, v| " #{k}='#{v}'" }.join
37+
enum.map do |i|
38+
result = capture(i, &block)
39+
40+
if result.count("\n") > 1
41+
result.gsub!("\n", "\n ")
42+
result = "\n #{result.strip}\n"
43+
else
44+
result.strip!
45+
end
46+
47+
%(<li#{opts_attributes}>#{result}</li>)
48+
end.join("\n").html_safe
49+
end
3650
end

test/fixtures/news.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ first_part_only:
3636
cached_slug: une-actualite-avec-une-seule-partie
3737
author_name: Auteur sympa
3838
author_email: [email protected]
39+
body: Uns seule partie

0 commit comments

Comments
 (0)