markdown optimization, few other changes

This commit is contained in:
jomo
2014-04-19 01:54:25 +02:00
parent 0264f239ba
commit 097f9b1ba4
12 changed files with 88 additions and 54 deletions

View File

@@ -33,4 +33,11 @@ $(function(){
$('img').css('transform', 'rotate(180deg)');
}
});
$('pre code').each(function() {
if ($(this).attr("class")) {
$(this).parent().attr("lang", $(this).attr("class").replace("hljs", "").trim());
} else {
$(this).parent().attr("lang", "(language unknown)")
}
});
});

View File

@@ -3,5 +3,5 @@
*= require style.css
*= require screen.css
*= require mobi.css
*= require highlight/default.css
*= require highlight/tomorrow-night.css
*/

View File

@@ -230,11 +230,9 @@ and (min-width: 0px) //TODO
}
pre {
background: #3F3F3F;
border-radius: 2px;
box-shadow: 0 0 16px #222 inset;
position: relative;
padding: 1em;
background: #3F3F3F;
&:after {
color: #fff;
content: attr(lang); // show language on top right
@@ -252,17 +250,20 @@ and (min-width: 0px) //TODO
right: 0;
}
code {
background: transparent;
padding: 0;
box-shadow: 0 0 16px #222 inset;
background: #3F3F3F !important;
border: none;
border-radius: 3px;
}
}
code {
background: #3F3F3F;
padding: 0 2px;
border-radius: 3px;
color: #ddd;
text-shadow: 1px 1px #000;
background: #A2A2A2;
padding: 2px 5px 2px 2px;
border-radius: 0 3px 3px 0;
color: #000;
border-left: 3px solid #3F3F3F;
}
table, tr, td, th {
@@ -271,10 +272,10 @@ and (min-width: 0px) //TODO
blockquote {
background: #F9F9F9;
border-left: 10px solid #3F3F3F;
border-left: 3px solid #3F3F3F;
display: inline-block;
margin: 0 0 0 2em;
padding: 0.5em 3em 0 10px;
margin: 0;
padding: 2px 5px 2px 2px;
}
blockquote p {
@@ -598,8 +599,17 @@ and (min-width: 0px) //TODO
font-weight: bold;
}
del {
background: rgba(255, 200, 200, 0.5);
iframe.youtube {
border: none;
width: 640px;
max-width: 100%;
height: 360px;
}
mark {
background: #faa;
padding: 0 2px;
border-radius: 3px;
}
.comment-counter {

View File

@@ -32,11 +32,12 @@ module ApplicationHelper
lax_spacing: true,
disable_indented_code_blocks: false,
space_after_headers: false,
superscript: true,
underline: true,
highlight: true,
footnotes: true
})
md.render(content)
render_youtube(md.render(content))
end
def render_mini_md(content)
@@ -57,10 +58,23 @@ module ApplicationHelper
lax_spacing: false,
disable_indented_code_blocks: true,
space_after_headers: true,
superscript: true,
underline: true,
highlight: true,
footnotes: false
})
md.render(content)
md.render(content.gsub(/([\r\n]+\s*?){3,}/, "\n\n").gsub(/^\s*#/, "\\#"))
end
private
def render_youtube(content)
# TODO: render only in text blocks, not in code/quotes/etc
return content.gsub(
/\[yt:([a-zA-Z0-9\-_]+)\]/,
"<iframe class='youtube' allowfullscreen src='
https://www.youtube-nocookie.com/embed/\\1?theme=light&vq=hd720&hd=1&iv_load_policy=3&showinfo=1&showsearch=0&rel=0&modestbranding&hd=1&autohide=1&html5=1'>
</iframe>")
end
end

View File

@@ -15,12 +15,12 @@ class User < ActiveRecord::Base
validates_length_of :password, in: 8..256, :on => :create
validates_length_of :name, in: 2..30
validates_length_of :about, maximum: 5000
validates_length_of :ign, minimum: 2, maximum: 16
validates_length_of :ign, minimum: 1, maximum: 16
validates :email, uniqueness: {case_sensitive: false}, format: {with: /\A.+@.+\..{2,}\z/i, message: "That doesn't look like an email adress."}
validates :ign, uniqueness: {case_sensitive: false}, format: {with: /\A[a-z\d_]+\z/i, message: "That is probably not your username."}
validates :ign, uniqueness: {case_sensitive: false}, format: {with: /\A[a-z\d_]+\z/i, message: "Username is invalid (a-z, 0-9, _)."}
validate :has_paid, :if => lambda {|user| user.ign_changed? }
validate :account_exists?, :if => lambda {|user| user.ign_changed? }
has_many :blogposts
has_many :comments
@@ -96,31 +96,31 @@ class User < ActiveRecord::Base
end
end
def haspaid?
begin
response = open("https://sessionserver.mojang.com/session/minecraft/profile/#{CGI.escape(self.uuid)}", read_timeout: 0.5)
if response.status[0] == "200"
session_profile = JSON.load(response.read)
# unpaid accounts are called 'demo' accounts
return session_profile["demo"] == true
elsif response.status[0] == "204"
# user doesn't exist
return false
else
puts "---"
puts "ERROR: unexpected response code while checking '#{self.uuid}' for premium account"
puts "code: #{reponse.status}, body: '#{reponse.read}'"
puts "---"
end
rescue => e
puts "---"
puts "ERROR: failed to check for premium account for '#{self.uuid}'. Minecraft servers down?"
puts e.message
puts "---"
end
# mojang servers have trouble
return true
end
# def haspaid?
# begin
# response = open("https://sessionserver.mojang.com/session/minecraft/profile/#{CGI.escape(self.uuid)}", read_timeout: 0.5)
# if response.status[0] == "200"
# session_profile = JSON.load(response.read)
# # unpaid accounts are called 'demo' accounts
# return session_profile["demo"] == true
# elsif response.status[0] == "204"
# # user doesn't exist
# return false
# else
# puts "---"
# puts "ERROR: unexpected response code while checking '#{self.uuid}' for premium account"
# puts "code: #{reponse.status}, body: '#{reponse.read}'"
# puts "---"
# end
# rescue => e
# puts "---"
# puts "ERROR: failed to check for premium account for '#{self.uuid}'. Minecraft servers down?"
# puts e.message
# puts "---"
# end
# # mojang servers have trouble
# return true
# end
# def correct_case?(ign)
# begin
@@ -183,8 +183,11 @@ class User < ActiveRecord::Base
self.role ||= Role.get(:normal)
end
def has_paid
errors.add(:ign, "'#{self.ign}' is not a paid account!") unless self.haspaid?
def account_exists?
profile = self.get_profile
if !profile || profile["demo"] == true
errors.add(:ign, "'#{self.ign}' is not a paid account!")
end
end
def strip_whitespaces

View File

@@ -11,7 +11,7 @@ atom_feed do |feed|
end
entry.url blogpost_url(post)
entry.title post.title
entry.content Sanitize.clean(render_md(post.content), Sanitize::Config::RELAXED).html_safe, :type => 'html'
entry.content render_md(post.content).html_safe, :type => 'html'
end
end
end

View File

@@ -13,7 +13,7 @@
<div class="items">
<div class="item content post">
<h2 class="headline"><%= link_to truncate(p.title, length: 60, omission: " …"), p %></h2>
<%= Sanitize.clean(render_md(p.content), Sanitize::Config::RELAXED).html_safe %>
<%= render_md(p.content).html_safe %>
</div>
</div>
</div>

View File

@@ -8,7 +8,7 @@
<div class="items">
<div class="item content">
<h2 class="headline"><%= link_to truncate(@post.title, length: 60, omission: " …"), p %></h2>
<%= Sanitize.clean(render_md(@post.content), Sanitize::Config::RELAXED).html_safe %>
<%= render_md(@post.content).html_safe %>
</div>
</div>
</div>

View File

@@ -6,7 +6,7 @@
</div>
<div class="items">
<div class="item content">
<%= Sanitize.clean(render_mini_md(c.content.gsub(/([\r\n]+\s*?){3,}/, "\n\n")), Sanitize::Config::BASIC).html_safe %>
<%= render_mini_md(c.content).html_safe %>
</div>
</div>
</div>

View File

@@ -1,7 +1,7 @@
<% if current_user %>
<h3>New comment</h3>
<%= simple_form_for [@post, @comment] do |f| %>
<p>> quote | _underline_ | *italic* | **bold** | `code` | [link](https://example.com)
<p><blockquote>&gt; quote</blockquote> | _underline_ | <i>*italic*</i> | <b>**bold**</b> | <code>`code`</code> | <mark>==mark==</mark> | <a>[link](https://example.com)</a>
<%= f.input :content, :label => false, :as => "text", :placeholder => "Comment", input_html: {class: "comment"} %>
<%= f.submit class: "btn blue" %>
<% end %>

View File

@@ -8,7 +8,7 @@
<div class="items">
<div class="item content">
<h2 class="headline"><%= link_to truncate(@thread.title, length: 60, omission: " …"), p %></h2>
<%= Sanitize.clean(render_md(@thread.content), Sanitize::Config::RELAXED).html_safe %>
<%= render_md(@thread.content).html_safe %>
</div>
</div>
</div>

View File

@@ -82,5 +82,5 @@
</tbody>
</table>
About:<br>
<%= @user.about.blank? ? "<span class=\"no-about\">nothing</span>".html_safe : @user.about %>
<%= @user.about.blank? ? "<span class=\"no-about\">nothing</span>".html_safe : render_mini_md(@user.about).html_safe %>
</div>