Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow juxtaposed visual test #1168

Merged
merged 8 commits into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 7 additions & 1 deletion spec/visual/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ def query_string
@title = "#{@lexer.class.tag} | Visual Test"
@highlighted = Rouge.highlight(@sample, @lexer, @formatter)

erb :lexer
if params[:juxtaposed]
@raw = Rouge.highlight(@sample, 'plaintext', @formatter)
@comment_color = @theme.class.get_style(Rouge::Token::Tokens::Comment).fg
erb :juxtaposed, layout: nil
ashmaroli marked this conversation as resolved.
Show resolved Hide resolved
else
erb :lexer
end
end


Expand Down
111 changes: 111 additions & 0 deletions spec/visual/templates/juxtaposed.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<!DOCTYPE html>
<html>
<head>
<title><%= @title %></title>
<style type="text/css">
<%= @theme.render %>
<%= @theme.render_base('body') %>
<%= @theme.render_base('a') %>

* { box-sizing: border-box }
html { font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif }
body { margin: 0 }
main { position: relative; padding: 8px 0 }
h2 { margin: 0 }

section {
float: left;
width: calc(100% - 210px);
padding: 8px;
padding-right: 4px;
overflow-y: auto;
}
aside {
width: 200px;
float: right;
padding: 8px 8px 8px 0
}
pre { margin: 0 }

.codehilite {
overflow-x: auto;
border-radius: 5px;
}
.legend .codehilite { font-size: 12px }
.codeviewer {
float: left;
padding: 8px 12px;
width: 49.575%;
border: 1px dotted <%= @comment_color %>
}
.codeviewer:not(:first-of-type) { margin-left: 4px }
.codeviewer:not(:last-of-type) { margin-right: 4px }

.codeviewer header, .legend header {
margin-bottom: 20px;
padding-bottom: 8px;
color: <%= @comment_color %>;
border-bottom: 1px dotted
}
.legend header { padding-top: 8px }

#page-header, #page-footer {
padding: 15px;
text-align: center;
color: <%= @comment_color %>
}
#page-header {
text-transform: capitalize;
border-bottom: 1px dotted
}
#page-header h1 {
margin: 0.25em;
font-size: 1.5em;
}
#page-footer {
height: 60px;
border-top: 1px dotted
}
.clearfix {
clear: both;
display: table;
content: "";
}
</style>
</head>
<body>
<header id="page-header">
<h1><%= @lexer.class.tag %> Lexer Test</h1>
</header>
<main>
<section>
<div class="codeviewer">
<header><h2>Raw</h2></header>
<%= @raw %>
</div>
<div class="codeviewer">
<header><h2>Highlighted</h2></header>
<%= @highlighted %>
</div>
</section>
<aside>
<div class="legend">
<header><h2>Legend</h2></header>
<pre class="codehilite">
<% Rouge::Token.each_token do |token|
%><span class="<%= token.shortname %>"><%= token.qualname %></span>
<% end %>
</pre>
</div>
</aside>
<div class="clearfix"></div>
</main>
<footer id="page-footer">
<small>Rendered with theme
<strong style="text-transform: capitalize">
<%= @theme.class.name.gsub(/_/, ' ') %>
</strong>
</small>
</footer>
</body>
</html>