Skip to content

Commit

Permalink
Fix asset links on content and template rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Glen committed Feb 1, 2016
1 parent c211a84 commit c09a776
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/models/smithy/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ def types

def liquid_template
@liquid_template ||= Rails.cache.fetch("#{self.cache_key}-liquid_template") do
::Liquid::Template.parse(self.content)
::Liquid::Template.parse(self.content_with_fixed_asset_links)
end
end

private
def content_with_fixed_asset_links
content.gsub(/\/smithy\/assets\/([0-9]+)/) { Smithy::Asset.find($1).url }
end

def load_containers
return unless self.template_type == 'template'
container_names = liquid_template.root.nodelist.select{|n| n.is_a?(::Liquid::Variable) && n.name.match(/^page\.container\.(.*)/) }.map{|n| n.name.match(/^page\.container\.(.*)/)[1] }
Expand Down
7 changes: 6 additions & 1 deletion lib/smithy/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ module Smithy
class Formatter < ::Slodown::Formatter

def render
self.complete.to_s
fix_asset_links.complete
end

private
def fix_asset_links
@current = @current.gsub(/\/smithy\/assets\/([0-9]+)/) { Smithy::Asset.find($1).url }
self
end

def kramdown_options
{ coderay_css: 'style' }
end
Expand Down

0 comments on commit c09a776

Please sign in to comment.