Skip to content

Commit

Permalink
Decompose externalising the links and externalise image urls too.
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyatom committed Nov 19, 2010
1 parent 179f9cc commit e38349b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/vanilla/dynasnips/kind.rb
Expand Up @@ -11,9 +11,9 @@ def handle(kind, limit=10, as=:html)
end
render_entry_collection(snips, entries, as, kind)
end

def render_entry_in_template(snip, as, kind)
rendered_contents = prepare_snip_contents(snip)
rendered_contents = externalise_links(prepare_snip_contents(snip))
case as
when :html
snip_template.
Expand All @@ -33,13 +33,15 @@ def render_entry_in_template(snip, as, kind)
end
end
end

def prepare_snip_contents(snip)
rendered_snip = app.render(snip)
# make all the links absolute
rendered_snip.gsub(/href="\//, "href=\"http://#{domain}/")
app.render(snip)
end

def externalise_links(content)
content.gsub(/href="\//, "href=\"http://#{domain}/").gsub(/src="\//, "src=\"http://#{domain}/")
end

def render_entry_collection(snips, entries, as, kind)
case as
when :html
Expand All @@ -53,7 +55,7 @@ def render_entry_collection(snips, entries, as, kind)
end.to_xml
end
end

attribute :feed_title, "Your Blog"
attribute :domain, "yourdomain.com"
attribute :snip_template, %{
Expand Down

0 comments on commit e38349b

Please sign in to comment.