diff --git a/app/assets/javascripts/app.js b/app/assets/javascripts/app.js index 35fc7f5..4e16a35 100644 --- a/app/assets/javascripts/app.js +++ b/app/assets/javascripts/app.js @@ -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)") + } + }); }); \ No newline at end of file diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 650ac36..a2e29b5 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -3,5 +3,5 @@ *= require style.css *= require screen.css *= require mobi.css - *= require highlight/default.css + *= require highlight/tomorrow-night.css */ \ No newline at end of file diff --git a/app/assets/stylesheets/screen.css.scss b/app/assets/stylesheets/screen.css.scss index 83dc9ce..4616849 100644 --- a/app/assets/stylesheets/screen.css.scss +++ b/app/assets/stylesheets/screen.css.scss @@ -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 { diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 89b444d..5444ac9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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\-_]+)\]/, + "") end end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index 81a60fe..1880027 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/blogposts/index.atom.builder b/app/views/blogposts/index.atom.builder index 5f1c05e..25eab0b 100644 --- a/app/views/blogposts/index.atom.builder +++ b/app/views/blogposts/index.atom.builder @@ -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 \ No newline at end of file diff --git a/app/views/blogposts/index.html.erb b/app/views/blogposts/index.html.erb index e973d02..b3bc1aa 100644 --- a/app/views/blogposts/index.html.erb +++ b/app/views/blogposts/index.html.erb @@ -13,7 +13,7 @@
> quote | _underline_ | *italic* | **bold** | `code` | [link](https://example.com) +
> quote| _underline_ | *italic* | **bold** |
`code` | ==mark== | [link](https://example.com)
<%= f.input :content, :label => false, :as => "text", :placeholder => "Comment", input_html: {class: "comment"} %>
<%= f.submit class: "btn blue" %>
<% end %>
diff --git a/app/views/forumthreads/show.html.erb b/app/views/forumthreads/show.html.erb
index 9821d0a..4b9c9ba 100644
--- a/app/views/forumthreads/show.html.erb
+++ b/app/views/forumthreads/show.html.erb
@@ -8,7 +8,7 @@