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

Style visual test app views #1181

Merged
merged 3 commits into from
Jun 18, 2019
Merged
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: 2 additions & 0 deletions spec/visual/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def query_string
theme_class = Rouge::Theme.find(params[:theme] || 'thankful_eyes')
halt 404 unless theme_class
@theme = theme_class.new(scope: '.codehilite')
@comment_color = @theme.class.get_style(Rouge::Token::Tokens::Comment).fg

formatter_opts = { :line_numbers => params[:line_numbers] }
formatter_opts[:inline_theme] = @theme if params[:inline]
Expand All @@ -53,6 +54,7 @@ def query_string
@sample = File.read(SAMPLES.join(@lexer.class.tag), encoding: 'utf-8')

@title = "#{@lexer.class.tag} | Visual Test"
@raw = Rouge.highlight(@sample, 'plaintext', @formatter)
@highlighted = Rouge.highlight(@sample, @lexer, @formatter)

erb :lexer
Expand Down
34 changes: 23 additions & 11 deletions spec/visual/templates/index.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
<style type="text/css">
body {
main {
padding: 15px;
column-count: 2;
-webkit-column-count: 2;
-moz-column-count: 2;
}
div {
.preview {
display: inline-block;
margin-bottom: 15px;
padding: 15px;
width: 100%;
color: <%= @comment_color %>;
border: 1px dotted;
break-inside: avoid-column;
-webkit-column-break-inside: avoid;
}
}
</style>

<h1>Lexers supported by Rouge v<%= Rouge.version %></h1>

<% @samples.each do |sample| %>
<div>
<h2><a href="/<%= sample.tag %>"><%= sample.tag %></a></h2>
<%= Rouge.highlight(sample.demo, sample, @formatter) %>
</div>
<% end %>
<header id="page-header">
<h1>Lexers supported by Rouge v<%= Rouge.version %></h1>
</header>
<main>
<% @samples.each do |sample| %>
<section class="preview">
<header class="section-header">
<h2><a href="/<%= sample.tag %>"><%= sample.tag %></a></h2>
</header>
<%= Rouge.highlight(sample.demo, sample, @formatter) %>
</section>
<% end %>
</main>
34 changes: 31 additions & 3 deletions spec/visual/templates/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,54 @@
<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, main, h2 { margin: 0 }
pre, code {
font-family: 'Source Code Pro', 'Menlo', 'Ubuntu Mono', 'Monaco', monospace;
font-size: 14px;
white-space: pre-wrap;
}
a { text-decoration: none }

#page-header, #page-footer {
padding: 15px;
text-align: center;
color: <%= @comment_color %>
}
#page-header {
border-bottom: 1px dotted
}
#page-header h1 {
margin: 0.25em;
font-size: 1.5em;
}
.section-header {
margin-bottom: 20px;
padding-bottom: 8px;
color: <%= @comment_color %>;
border-bottom: 1px dotted
}
#page-footer {
border-top: 1px dotted
}
</style>
</head>

<body>
<%= yield %>
<footer id="page-footer">
<small>Rendered with theme
<strong style="text-transform: capitalize">
<%= @theme.class.name.gsub(/_/, ' ') %>
</strong>
</small>
</footer>
</body>



</html>
42 changes: 28 additions & 14 deletions spec/visual/templates/lexer.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
<style type="text/css">
main {
display: inline-block;
margin-right: -300px;
padding: 15px 300px 15px 15px;
width: 100%;
}

.legend {
width: 200px;
margin-right: 30px;
padding: 15px;
padding-left: 0;
float: right;
width: 250px;
}
</style>

<section class="legend">
<h2>Legend</h2>
<pre class="codehilite"><%
Rouge::Token.each_token do |token|
%><span class="<%= token.shortname %>"><%= token.qualname %></span>
<% end
%></pre>
</section>
<h2>Highlighted</h2>
<%= @highlighted %>
<header id="page-header">
<h1><%= @lexer.class.tag %> lexer visual test</h1>
</header>
<main>
<header class="section-header"><h2>Highlighted</h2></header>
<%= @highlighted %>

<header class="section-header"><h2>Raw</h2></header>
<pre><%= @raw %></pre>
</main>

<h2>Raw</h2>
<pre><%= CGI.escape_html(@sample) %></pre>
<aside class="legend">
<header class="section-header"><h2>Legend</h2></header>
<pre class="codehilite">
<% Rouge::Token.each_token do |token|
%><span class="<%= token.shortname %>"><%= token.qualname %></span>
<% end %>
</pre>
</aside>