Commit 6171a4d8ebd1602b987bc6d93fd19443696c155b

Authored by randx
1 parent 34ba4e13

Fixed dashboard broken messages cause of glm

app/assets/stylesheets/sections/notes.scss
... ... @@ -175,10 +175,17 @@ td .line_note_link {
175 175 top:7px;
176 176 }
177 177  
  178 + .note_advanced_opts {
  179 + h6 {
  180 + line-height: 32px;
  181 + margin-right: 12px;
  182 + }
  183 + }
  184 +
178 185 div.attachments {
179 186 position:relative;
180 187 width: 350px;
181   - height: 36px;
  188 + height: 50px;
182 189 overflow:hidden;
183 190 margin:0 0 5px !important;
184 191 }
... ...
app/helpers/application_helper.rb
... ... @@ -42,86 +42,6 @@ module ApplicationHelper
42 42 grouped_options_for_select(options, @ref || @project.default_branch)
43 43 end
44 44  
45   - def gfm(text, html_options = {})
46   - return text if text.nil?
47   - raise "@project is not set" if @project.nil?
48   -
49   - # Extract pre blocks
50   - # from http://github.github.com/github-flavored-markdown/
51   - extractions = {}
52   - text.gsub!(%r{<pre>.*?</pre>|<code>.*?</code>}m) do |match|
53   - md5 = Digest::MD5.hexdigest(match)
54   - extractions[md5] = match
55   - "{gfm-extraction-#{md5}}"
56   - end
57   -
58   - # match 1 2 3 4 5 6
59   - text.gsub!(/(\W)?(@([\w\._]+)|[#!$](\d+)|([\h]{6,40}))(\W)?/) do |match|
60   - prefix = $1
61   - reference = $2
62   - user_name = $3
63   - issue_id = $4
64   - merge_request_id = $4
65   - snippet_id = $4
66   - commit_id = $5
67   - suffix = $6
68   -
69   - # TODO: add popups with additional information
70   - ref_link = case reference
71   -
72   - # team member: @foo
73   - when /^@/
74   - user = @project.users.where(:name => user_name).first
75   - member = @project.users_projects.where(:user_id => user).first if user
76   - link_to("@#{user_name}", project_team_member_path(@project, member), html_options.merge(:class => "gfm gfm-team_member #{html_options[:class]}")) if member
77   -
78   - # issue: #123
79   - when /^#/
80   - # avoid HTML entities
81   - unless prefix.try(:end_with?, "&") && suffix.try(:start_with?, ";")
82   - issue = @project.issues.where(:id => issue_id).first
83   - link_to("##{issue_id}", project_issue_path(@project, issue), html_options.merge(:title => "Issue: #{issue.title}", :class => "gfm gfm-issue #{html_options[:class]}")) if issue
84   - end
85   -
86   - # merge request: !123
87   - when /^!/
88   - merge_request = @project.merge_requests.where(:id => merge_request_id).first
89   - link_to("!#{merge_request_id}", project_merge_request_path(@project, merge_request), html_options.merge(:title => "Merge Request: #{merge_request.title}", :class => "gfm gfm-merge_request #{html_options[:class]}")) if merge_request
90   -
91   - # snippet: $123
92   - when /^\$/
93   - snippet = @project.snippets.where(:id => snippet_id).first
94   - link_to("$#{snippet_id}", project_snippet_path(@project, snippet), html_options.merge(:title => "Snippet: #{snippet.title}", :class => "gfm gfm-snippet #{html_options[:class]}")) if snippet
95   -
96   - # commit: 123456...
97   - when /^\h/
98   - commit = @project.commit(commit_id)
99   - link_to(commit_id, project_commit_path(@project, :id => commit.id), html_options.merge(:title => "Commit: #{commit.author_name} - #{CommitDecorator.new(commit).title}", :class => "gfm gfm-commit #{html_options[:class]}")) if commit
100   -
101   - end # case
102   -
103   - ref_link.nil? ? match : "#{prefix}#{ref_link}#{suffix}"
104   - end # gsub
105   -
106   - # Insert pre block extractions
107   - text.gsub!(/\{gfm-extraction-(\h{32})\}/) do
108   - extractions[$1]
109   - end
110   -
111   - text.html_safe
112   - end
113   -
114   - # circumvents nesting links, which will behave bad in browsers
115   - def link_to_gfm(body, url, html_options = {})
116   - gfm_body = gfm(body, html_options)
117   -
118   - gfm_body.gsub!(%r{<a.*?>.*?</a>}m) do |match|
119   - "</a>#{match}#{link_to("", url, html_options)[0..-5]}" # "</a>".length +1
120   - end
121   -
122   - link_to(gfm_body.html_safe, url, html_options)
123   - end
124   -
125 45 def markdown(text)
126 46 @__renderer ||= Redcarpet::Markdown.new(Redcarpet::Render::GitlabHTML.new(self, filter_html: true, with_toc_data: true), {
127 47 no_intra_emphasis: true,
... ...
app/helpers/gitlab_markdown_helper.rb 0 → 100644
... ... @@ -0,0 +1,81 @@
  1 +module GitlabMarkdownHelper
  2 + def gfm(text, html_options = {})
  3 + return text if text.nil?
  4 + return text if @project.nil?
  5 +
  6 + # Extract pre blocks
  7 + # from http://github.github.com/github-flavored-markdown/
  8 + extractions = {}
  9 + text.gsub!(%r{<pre>.*?</pre>|<code>.*?</code>}m) do |match|
  10 + md5 = Digest::MD5.hexdigest(match)
  11 + extractions[md5] = match
  12 + "{gfm-extraction-#{md5}}"
  13 + end
  14 +
  15 + # match 1 2 3 4 5 6
  16 + text.gsub!(/(\W)?(@([\w\._]+)|[#!$](\d+)|([\h]{6,40}))(\W)?/) do |match|
  17 + prefix = $1
  18 + reference = $2
  19 + user_name = $3
  20 + issue_id = $4
  21 + merge_request_id = $4
  22 + snippet_id = $4
  23 + commit_id = $5
  24 + suffix = $6
  25 +
  26 + # TODO: add popups with additional information
  27 + ref_link = case reference
  28 +
  29 + # team member: @foo
  30 + when /^@/
  31 + user = @project.users.where(:name => user_name).first
  32 + member = @project.users_projects.where(:user_id => user).first if user
  33 + link_to("@#{user_name}", project_team_member_path(@project, member), html_options.merge(:class => "gfm gfm-team_member #{html_options[:class]}")) if member
  34 +
  35 + # issue: #123
  36 + when /^#/
  37 + # avoid HTML entities
  38 + unless prefix.try(:end_with?, "&") && suffix.try(:start_with?, ";")
  39 + issue = @project.issues.where(:id => issue_id).first
  40 + link_to("##{issue_id}", project_issue_path(@project, issue), html_options.merge(:title => "Issue: #{issue.title}", :class => "gfm gfm-issue #{html_options[:class]}")) if issue
  41 + end
  42 +
  43 + # merge request: !123
  44 + when /^!/
  45 + merge_request = @project.merge_requests.where(:id => merge_request_id).first
  46 + link_to("!#{merge_request_id}", project_merge_request_path(@project, merge_request), html_options.merge(:title => "Merge Request: #{merge_request.title}", :class => "gfm gfm-merge_request #{html_options[:class]}")) if merge_request
  47 +
  48 + # snippet: $123
  49 + when /^\$/
  50 + snippet = @project.snippets.where(:id => snippet_id).first
  51 + link_to("$#{snippet_id}", project_snippet_path(@project, snippet), html_options.merge(:title => "Snippet: #{snippet.title}", :class => "gfm gfm-snippet #{html_options[:class]}")) if snippet
  52 +
  53 + # commit: 123456...
  54 + when /^\h/
  55 + commit = @project.commit(commit_id)
  56 + link_to(commit_id, project_commit_path(@project, :id => commit.id), html_options.merge(:title => "Commit: #{commit.author_name} - #{CommitDecorator.new(commit).title}", :class => "gfm gfm-commit #{html_options[:class]}")) if commit
  57 +
  58 + end # case
  59 +
  60 + ref_link.nil? ? match : "#{prefix}#{ref_link}#{suffix}"
  61 + end # gsub
  62 +
  63 + # Insert pre block extractions
  64 + text.gsub!(/\{gfm-extraction-(\h{32})\}/) do
  65 + extractions[$1]
  66 + end
  67 +
  68 + text.html_safe
  69 + end
  70 +
  71 + # circumvents nesting links, which will behave bad in browsers
  72 + def link_to_gfm(body, url, html_options = {})
  73 + gfm_body = gfm(body, html_options)
  74 +
  75 + gfm_body.gsub!(%r{<a.*?>.*?</a>}m) do |match|
  76 + "</a>#{match}#{link_to("", url, html_options)[0..-5]}" # "</a>".length +1
  77 + end
  78 +
  79 + link_to(gfm_body.html_safe, url, html_options)
  80 + end
  81 +end
... ...
app/views/notes/_form.html.haml
... ... @@ -13,24 +13,21 @@
13 13 is enabled.
14 14  
15 15 .row.note_advanced_opts.hide
16   - .span4
17   - %h5 Notify via email:
18   - .clearfix
19   - = label_tag :notify do
20   - = check_box_tag :notify, 1, @note.noteable_type != "Commit"
21   - %span Project team
  16 + .span4.notify_opts
  17 + %h6.left Notify via email:
  18 + = label_tag :notify do
  19 + = check_box_tag :notify, 1, @note.noteable_type != "Commit"
  20 + %span Project team
22 21  
23   - - if @note.notify_only_author?(current_user)
24   - = label_tag :notify_author do
25   - = check_box_tag :notify_author, 1 , @note.noteable_type == "Commit"
26   - %span Commit author
27   - .span8
28   - %h5 Attachment:
29   - .clearfix
30   - .attachments
31   - %div.file_name File name...
32   - %button.file_upload.btn.small Upload File
33   - .input= f.file_field :attachment, :class => "input-file"
34   - %span Any file less than 10 MB
  22 + - if @note.notify_only_author?(current_user)
  23 + = label_tag :notify_author do
  24 + = check_box_tag :notify_author, 1 , @note.noteable_type == "Commit"
  25 + %span Commit author
  26 + .span8.attachments
  27 + %h6.left Attachment:
  28 + %span.file_name File name...
  29 + %button.file_upload.btn.small Upload File
  30 + .input= f.file_field :attachment, :class => "input-file"
  31 + %span.hint Any file less than 10 MB
35 32  
36 33 = f.submit 'Add Comment', :class => "btn primary submit_note", :id => "submit_note"
... ...