4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/nexmo_markdown_renderer/filters/partial_filter.rb', line 4
def call(input)
input.gsub(/```partial(.+?)```/m) do |_s|
config = YAML.safe_load($1)
file_path = if config['source'].start_with? 'app/views'
"#{Rails.root}/#{config['source']}"
else
"#{Nexmo::Markdown::Config.docs_base_path}/#{config['source']}"
end
content = File.read(file_path)
active = options[:code_language] ? options[:code_language].key == config['platform'] : false
if config['platform']
<<~HEREDOC
<div class="js-platform" data-platform="#{config['platform']}" data-active="#{active}">
#{content.render_markdown}
</div>
HEREDOC
else
content
end
end
end
|