From a85a95d18a183b854f35f2d0fe54d00030fda344 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Wed, 19 Sep 2012 23:35:43 +0600 Subject: [PATCH] [refs #616] markdown cheat sheet --- app/assets/stylesheets/design/custom.scss | 38 ++++++++ app/helpers/application_helper.rb | 8 +- app/presenters/comment_presenter.rb | 3 +- app/views/projects/comments/_add.html.haml | 1 + app/views/projects/comments/_list.html.haml | 1 + .../comments/_markdown_help.html.haml | 86 +++++++++++++++++++ app/views/projects/issues/_form.html.haml | 1 + app/views/projects/issues/show.html.haml | 1 + config/locales/models/comment.en.yml | 9 +- config/locales/models/comment.ru.yml | 11 +-- 10 files changed, 146 insertions(+), 13 deletions(-) create mode 100644 app/views/projects/comments/_markdown_help.html.haml diff --git a/app/assets/stylesheets/design/custom.scss b/app/assets/stylesheets/design/custom.scss index 4e326a3e2..f61830bb8 100644 --- a/app/assets/stylesheets/design/custom.scss +++ b/app/assets/stylesheets/design/custom.scss @@ -1519,6 +1519,11 @@ table.tablesorter.platform-maintainers.static-search thead tr.search th input[ty margin: 0 2px; padding: 0px 5px; } + + blockquote { + border-left: 4px solid #EDEDED; + padding: 0 15px; + } } #md_tabs { @@ -1553,3 +1558,36 @@ table.tablesorter.platform-maintainers.static-search thead tr.search th input[ty margin-bottom: 0; } +#md_help { + width: 800px; + top: 30%; + left: 42%; + + .modal-body { + max-height: 560px; + padding-top: 0; + } + + .modal-header { + padding-bottom: 0; + } + + .col { + width: 245px; + float: left; + padding: 0; + margin-right: 10px; + + h3 { + margin: 6px 0 0 0; + } + pre { + background: none repeat scroll 0 0 #EDEDED; + box-shadow: 0 3px 3px -1px rgba(18, 86, 135, 0.2); + border: 1px solid #EDEDED; + padding: 5px; + margin-top: 3px; + } + } +} + diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e9f74c870..fe7537c4f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -41,9 +41,11 @@ module ApplicationHelper end def markdown(text) - html_options = {filter_html: true, hard_wrap: true, with_toc_data: true} - options = {no_intraemphasis: true, tables: true, fenced_code_blocks: true, autolink: true, strikethrough: true, lax_html_blocks: true} - @redcarpet ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(html_options), options) + unless @redcarpet + html_options = {filter_html: true, hard_wrap: true, with_toc_data: true} + options = {no_intraemphasis: true, tables: true, fenced_code_blocks: true, autolink: true, strikethrough: true, lax_html_blocks: true} + @redcarpet = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(html_options), options) + end @redcarpet.render(text).html_safe end end diff --git a/app/presenters/comment_presenter.rb b/app/presenters/comment_presenter.rb index 5a8d4231b..0e2d36963 100644 --- a/app/presenters/comment_presenter.rb +++ b/app/presenters/comment_presenter.rb @@ -40,7 +40,8 @@ class CommentPresenter < ApplicationPresenter res = [] if controller.can? :update, @comment - res << link_to(t("layout.edit"), ep, html_options = {:id => "comment-#{comment.id}", :class => "edit_comment"}).html_safe + res << link_to(t('layout.comments.markdown_cheatsheet'), '#md_help', 'data-toggle' => 'modal') + res << link_to(t("layout.edit"), ep, :id => "comment-#{comment.id}", :class => "edit_comment").html_safe end if controller.can? :delete, @comment res << link_to(t("layout.delete"), dp, :method => "delete", diff --git a/app/views/projects/comments/_add.html.haml b/app/views/projects/comments/_add.html.haml index 561ae2e30..80061a8f2 100644 --- a/app/views/projects/comments/_add.html.haml +++ b/app/views/projects/comments/_add.html.haml @@ -1,4 +1,5 @@ #open-comment.comment.view + =link_to t('layout.comments.markdown_cheatsheet'), '#md_help', 'data-toggle' => 'modal', :style => 'float:right;' %h3.tmargin0= t("layout.comments.new_header") - if Comment.issue_comment?(commentable.class) - new_path = project_issue_comments_path(project, commentable) diff --git a/app/views/projects/comments/_list.html.haml b/app/views/projects/comments/_list.html.haml index 663b4014e..268e9b5cd 100644 --- a/app/views/projects/comments/_list.html.haml +++ b/app/views/projects/comments/_list.html.haml @@ -11,3 +11,4 @@ .comment-left{:style => 'margin-top: 0;'} =link_to t('layout.cancel'), '#', :id => "comment-#{comment.id}", :class => 'cancel_edit_comment button' .both += render "projects/comments/markdown_help" diff --git a/app/views/projects/comments/_markdown_help.html.haml b/app/views/projects/comments/_markdown_help.html.haml new file mode 100644 index 000000000..cd871ce27 --- /dev/null +++ b/app/views/projects/comments/_markdown_help.html.haml @@ -0,0 +1,86 @@ +#md_help.modal.hidden + .modal-header + %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"} × + %h3#myModalLabel=t('layout.comments.markdown_cheatsheet') + .modal-body + .mod + .col + %h3 Format Text + %p Headers + %pre + -[1, 3, 6].each do |i| + ="#{'#'*i} This is an tag" + %p Text styles + %pre + :preserve + *This text will be italic* + _This will also be italic_ + **This text will be bold** + __This will also be bold__ + .col + %h3 Lists + %p Unordered + %pre + :preserve + * Item 1 + * Item 2 + * Item 2a + * Item 2b + %p Ordered + %pre + :preserve + 1. Item 1 + 2. Item 2 + 3. Item 3 + * Item 3a + * Item 3b + .col + %h3 Miscellaneous + %p Images + %pre + :preserve + ![GitHub Logo](/images/logo.png) + Format: ![Alt Text](url) + %p Links + %pre + :preserve + http://github.com - automatic! + [GitHub](http://github.com) + %p Blockquotes + %pre + :preserve + As Kanye West said: + + > We're living the future so + > the present is our past. + .both + %hr.bootstrap + %h3 Code Examples in Markdown + .col + %p + Syntax highlighting + %pre + :preserve + ```javascript + function fancyAlert(arg) { + if(arg) { + $.facebox({div:'#foo'}) + } + } + ``` + .col + %p Or, indent your code 4 spaces + %pre + :preserve + Here is a Python code example + without syntax highlighting: + + def foo: + if not bar: + return true + .col + %p Inline code for comments + %pre + :preserve + I think you should use an + `[addr]` element here instead. diff --git a/app/views/projects/issues/_form.html.haml b/app/views/projects/issues/_form.html.haml index 3ce77098c..a72ebf057 100644 --- a/app/views/projects/issues/_form.html.haml +++ b/app/views/projects/issues/_form.html.haml @@ -2,6 +2,7 @@ %h3.tmargin0{:style => 'margin-bottom: 0;'}= t 'activerecord.attributes.issue.title' .wrapper= f.text_area :title, :cols => 80, :rows => 1, :style => 'height: 16px; margin: 0 0 10px;' #open-comment.comment.view + =link_to t('layout.comments.markdown_cheatsheet'), '#md_help', 'data-toggle' => 'modal', :style => 'float:right;' %h3.tmargin0= t 'activerecord.attributes.issue.body' =render 'projects/comments/body', :f => f, :id => 'new' diff --git a/app/views/projects/issues/show.html.haml b/app/views/projects/issues/show.html.haml index 7b5be6244..734040c7c 100644 --- a/app/views/projects/issues/show.html.haml +++ b/app/views/projects/issues/show.html.haml @@ -24,6 +24,7 @@ %h3.tmargin0{:style => 'margin-bottom: 0;'}= t 'activerecord.attributes.issue.title' .wrapper= f.text_area :title, :cols => 80, :rows => 1, :style => 'height: 16px; margin: 0 0 10px;' #open-comment.comment.view + =link_to t('layout.comments.markdown_cheatsheet'), '#md_help', 'data-toggle' => 'modal', :style => 'float:right;' %h3.tmargin0= t 'activerecord.attributes.issue.body' =render 'projects/comments/body', :f => f, :id => 'update' .both diff --git a/config/locales/models/comment.en.yml b/config/locales/models/comment.en.yml index a1bcd69ec..b05769339 100644 --- a/config/locales/models/comment.en.yml +++ b/config/locales/models/comment.en.yml @@ -4,10 +4,11 @@ en: confirm_delete: Are you sure you want to delete the comment? new_header: New comment edit_header: Editing a comment - has_commented: "added a note" - notifications_are: "Notifications for new comments are" - comments_header: "Comments" - back: 'Back' + has_commented: added a note + notifications_are: Notifications for new comments are + comments_header: Comments + back: Back + markdown_cheatsheet: Markdown Cheat Sheet flash: comment: diff --git a/config/locales/models/comment.ru.yml b/config/locales/models/comment.ru.yml index ff9e15dd3..c9b09898f 100644 --- a/config/locales/models/comment.ru.yml +++ b/config/locales/models/comment.ru.yml @@ -4,17 +4,18 @@ ru: confirm_delete: Вы уверены, что хотите удалить комментарий? new_header: Новый комментарий edit_header: Редактирование комментария - has_commented: "оставил комментарий" - notifications_are: "Уведомления о последующих комментариях" - comments_header: "Комментарии" - back: 'Назад' + has_commented: оставил комментарий + notifications_are: Уведомления о последующих комментариях + comments_header: Комментарии + back: Назад + markdown_cheatsheet: Шпаргалка по Markdown flash: comment: saved: Комментарий успешно сохранен save_error: Ошибка сохранения комментария destroyed: Комментарий удален - + activerecord: attributes: comment: