Utilize ERB template in MediumTag (#2786) [ci skip]

This commit is contained in:
Mario See 2019-05-14 10:42:48 -04:00 committed by Mac Siri
parent d478cc372b
commit 209f796c8d
2 changed files with 22 additions and 17 deletions

View file

@ -3,29 +3,19 @@ class MediumTag < LiquidTagBase
include ActionView::Helpers::TagHelper
include InlineSvg::ActionView::Helpers
attr_reader :response
PARTIAL = "liquids/medium".freeze
def initialize(_tag_name, url, _tokens)
@response = parse_url_for_medium_article(url)
end
def render(_context)
<<-HTML
<div class='ltag__link'>
<a href='#{response[:url]}' class='ltag__link__link'>
<div class='ltag__link__pic'>
<img src='#{response[:author_image]}' alt='#{response[:author]}'/>
</div>
</a>
<a href='#{response[:url]}' class='ltag__link__link'>
<div class='ltag__link__content'>
<h2>#{response[:title]}</h2>
<h3>#{response[:author]}</h3>
#{inline_svg('medium_icon.svg', size: '27px*27px', aria: true, title: 'medium logo')} Medium
<div class='ltag__link__taglist'>#{response[:reading_time]}</div>
</div>
</a>
</div>
HTML
ActionController::Base.new.render_to_string(
partial: PARTIAL,
locals: {
response: @response
},
)
end
private

View file

@ -0,0 +1,15 @@
<div class='ltag__link'>
<a href='<%= response[:url] %>' class='ltag__link__link'>
<div class='ltag__link__pic'>
<img src='<%= response[:author_image] %>' alt='<%= response[:author] %>'/>
</div>
</a>
<a href='<%= response[:url] %>' class='ltag__link__link'>
<div class='ltag__link__content'>
<h2><%= response[:title] %></h2>
<h3><%= response[:author] %></h3>
<%= inline_svg('medium_icon.svg', size: '27px*27px', aria: true, title: 'medium logo') %> Medium
<div class='ltag__link__taglist'><%= response[:reading_time] %></div>
</div>
</a>
</div>