Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/views/style_guide/style/_partial.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<input id="style-guide-toggle-<%= partial.id %>" type="checkbox" />
<label for="style-guide-toggle-<%= partial.id %>">
<pre class="style-guide-partial-source prettyprint linenums"><%= escape_for_display(partial.render) %></pre>
<pre class="style-guide-partial-source prettyprint linenums"><%= escape_for_display(partial.render_source_code) %></pre>
<div class="style-guide-toggle show">Show source code</div>
<div class="style-guide-toggle hide">Hide source code</div>
</label>
Expand Down
6 changes: 5 additions & 1 deletion lib/style_guide/partial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ def identifiers
end

def render
@render ||= action_view.render(:file => path)
@render = action_view.render(file: path)
end

def render_source_code
@render = Nokogiri::HTML.fragment(render, 'utf-8').to_xhtml
end

private
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/style_guide/partial_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,14 @@

it { should == "hi" }
end

describe "#render_source" do
let(:mock_view) { double(:view, :render => '<h1>Hello world</h1><div><h2>More stuff</h2><div><p>Mooooore stuff</p></div></div>') }

before { partial.stub(:action_view).and_return(mock_view) }

subject { partial.render_source_code }

it { should == "<h1>Hello world</h1><div>\n <h2>More stuff</h2>\n <div>\n <p>Mooooore stuff</p>\n </div>\n</div>" }
end
end