##// END OF EJS Templates
Merged r1505, r1506, r1511, r1512, r1517, r1518, r1524 to 1526 from trunk....
Jean-Philippe Lang -
r1518:2af910e8e61f
parent child
Show More
@@ -1,66 +1,66
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class Journal < ActiveRecord::Base
19 19 belongs_to :journalized, :polymorphic => true
20 20 # added as a quick fix to allow eager loading of the polymorphic association
21 21 # since always associated to an issue, for now
22 22 belongs_to :issue, :foreign_key => :journalized_id
23 23
24 24 belongs_to :user
25 25 has_many :details, :class_name => "JournalDetail", :dependent => :delete_all
26 26 attr_accessor :indice
27 27
28 28 acts_as_searchable :columns => 'notes',
29 29 :include => :issue,
30 30 :project_key => "#{Issue.table_name}.project_id",
31 31 :date_column => "#{Issue.table_name}.created_on"
32 32
33 acts_as_event :title => Proc.new {|o| "#{o.issue.tracker.name} ##{o.issue.id}: #{o.issue.subject}" + ((s = o.new_status) ? " (#{s})" : '') },
33 acts_as_event :title => Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.id}#{status}: #{o.issue.subject}" },
34 34 :description => :notes,
35 35 :author => :user,
36 36 :type => Proc.new {|o| (s = o.new_status) && s.is_closed? ? 'issue-closed' : 'issue-edit' },
37 37 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id, :anchor => "change-#{o.id}"}}
38 38
39 39 def save
40 40 # Do not save an empty journal
41 41 (details.empty? && notes.blank?) ? false : super
42 42 end
43 43
44 44 # Returns the new status if the journal contains a status change, otherwise nil
45 45 def new_status
46 46 c = details.detect {|detail| detail.prop_key == 'status_id'}
47 47 (c && c.value) ? IssueStatus.find_by_id(c.value.to_i) : nil
48 48 end
49 49
50 50 def new_value_for(prop)
51 51 c = details.detect {|detail| detail.prop_key == prop}
52 52 c ? c.value : nil
53 53 end
54 54
55 55 def editable_by?(usr)
56 56 usr && usr.logged? && (usr.allowed_to?(:edit_issue_notes, project) || (self.user == usr && usr.allowed_to?(:edit_own_issue_notes, project)))
57 57 end
58 58
59 59 def project
60 60 journalized.respond_to?(:project) ? journalized.project : nil
61 61 end
62 62
63 63 def attachments
64 64 journalized.respond_to?(:attachments) ? journalized.attachments : nil
65 65 end
66 66 end
@@ -1,155 +1,156
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require 'redmine/scm/adapters/cvs_adapter'
19 19 require 'digest/sha1'
20 20
21 21 class Repository::Cvs < Repository
22 22 validates_presence_of :url, :root_url
23 23
24 24 def scm_adapter
25 25 Redmine::Scm::Adapters::CvsAdapter
26 26 end
27 27
28 28 def self.scm_name
29 29 'CVS'
30 30 end
31 31
32 32 def entry(path, identifier)
33 33 e = entries(path, identifier)
34 34 e ? e.first : nil
35 35 end
36 36
37 37 def entries(path=nil, identifier=nil)
38 38 rev = identifier.nil? ? nil : changesets.find_by_revision(identifier)
39 39 entries = scm.entries(path, rev.nil? ? nil : rev.committed_on)
40 40 if entries
41 41 entries.each() do |entry|
42 42 unless entry.lastrev.nil? || entry.lastrev.identifier
43 43 change=changes.find_by_revision_and_path( entry.lastrev.revision, scm.with_leading_slash(entry.path) )
44 44 if change
45 45 entry.lastrev.identifier=change.changeset.revision
46 46 entry.lastrev.author=change.changeset.committer
47 47 entry.lastrev.revision=change.revision
48 48 entry.lastrev.branch=change.branch
49 49 end
50 50 end
51 51 end
52 52 end
53 53 entries
54 54 end
55 55
56 56 def diff(path, rev, rev_to, type)
57 57 #convert rev to revision. CVS can't handle changesets here
58 58 diff=[]
59 59 changeset_from=changesets.find_by_revision(rev)
60 60 if rev_to.to_i > 0
61 61 changeset_to=changesets.find_by_revision(rev_to)
62 62 end
63 63 changeset_from.changes.each() do |change_from|
64 64
65 65 revision_from=nil
66 66 revision_to=nil
67 67
68 68 revision_from=change_from.revision if path.nil? || (change_from.path.starts_with? scm.with_leading_slash(path))
69 69
70 70 if revision_from
71 71 if changeset_to
72 72 changeset_to.changes.each() do |change_to|
73 73 revision_to=change_to.revision if change_to.path==change_from.path
74 74 end
75 75 end
76 76 unless revision_to
77 77 revision_to=scm.get_previous_revision(revision_from)
78 78 end
79 diff=diff+scm.diff(change_from.path, revision_from, revision_to, type)
79 file_diff = scm.diff(change_from.path, revision_from, revision_to)
80 diff = diff + file_diff unless file_diff.nil?
80 81 end
81 82 end
82 83 return diff
83 84 end
84 85
85 86 def fetch_changesets
86 87 # some nifty bits to introduce a commit-id with cvs
87 88 # natively cvs doesn't provide any kind of changesets, there is only a revision per file.
88 89 # we now take a guess using the author, the commitlog and the commit-date.
89 90
90 91 # last one is the next step to take. the commit-date is not equal for all
91 92 # commits in one changeset. cvs update the commit-date when the *,v file was touched. so
92 93 # we use a small delta here, to merge all changes belonging to _one_ changeset
93 94 time_delta=10.seconds
94 95
95 96 fetch_since = latest_changeset ? latest_changeset.committed_on : nil
96 97 transaction do
97 98 tmp_rev_num = 1
98 99 scm.revisions('', fetch_since, nil, :with_paths => true) do |revision|
99 100 # only add the change to the database, if it doen't exists. the cvs log
100 101 # is not exclusive at all.
101 102 unless changes.find_by_path_and_revision(scm.with_leading_slash(revision.paths[0][:path]), revision.paths[0][:revision])
102 103 revision
103 104 cs = changesets.find(:first, :conditions=>{
104 105 :committed_on=>revision.time-time_delta..revision.time+time_delta,
105 106 :committer=>revision.author,
106 107 :comments=>revision.message
107 108 })
108 109
109 110 # create a new changeset....
110 111 unless cs
111 112 # we use a temporaray revision number here (just for inserting)
112 113 # later on, we calculate a continous positive number
113 114 latest = changesets.find(:first, :order => 'id DESC')
114 115 cs = Changeset.create(:repository => self,
115 116 :revision => "_#{tmp_rev_num}",
116 117 :committer => revision.author,
117 118 :committed_on => revision.time,
118 119 :comments => revision.message)
119 120 tmp_rev_num += 1
120 121 end
121 122
122 123 #convert CVS-File-States to internal Action-abbrevations
123 124 #default action is (M)odified
124 125 action="M"
125 126 if revision.paths[0][:action]=="Exp" && revision.paths[0][:revision]=="1.1"
126 127 action="A" #add-action always at first revision (= 1.1)
127 128 elsif revision.paths[0][:action]=="dead"
128 129 action="D" #dead-state is similar to Delete
129 130 end
130 131
131 132 Change.create(:changeset => cs,
132 133 :action => action,
133 134 :path => scm.with_leading_slash(revision.paths[0][:path]),
134 135 :revision => revision.paths[0][:revision],
135 136 :branch => revision.paths[0][:branch]
136 137 )
137 138 end
138 139 end
139 140
140 141 # Renumber new changesets in chronological order
141 142 changesets.find(:all, :order => 'committed_on ASC, id ASC', :conditions => "revision LIKE '_%'").each do |changeset|
142 143 changeset.update_attribute :revision, next_revision_number
143 144 end
144 145 end # transaction
145 146 end
146 147
147 148 private
148 149
149 150 # Returns the next revision number to assign to a CVS changeset
150 151 def next_revision_number
151 152 # Need to retrieve existing revision numbers to sort them as integers
152 153 @current_revision_number ||= (connection.select_values("SELECT revision FROM #{Changeset.table_name} WHERE repository_id = #{id} AND revision NOT LIKE '_%'").collect(&:to_i).max || 0)
153 154 @current_revision_number += 1
154 155 end
155 156 end
@@ -1,65 +1,65
1 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
3 3 <head>
4 4 <title><%=h html_title %></title>
5 5 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6 6 <meta name="description" content="<%= Redmine::Info.app_name %>" />
7 7 <meta name="keywords" content="issue,bug,tracker" />
8 8 <%= stylesheet_link_tag 'application', :media => 'all' %>
9 9 <%= javascript_include_tag :defaults %>
10 10 <%= stylesheet_link_tag 'jstoolbar' %>
11 11 <!--[if IE]>
12 12 <style type="text/css">
13 13 * html body{ width: expression( document.documentElement.clientWidth < 900 ? '900px' : '100%' ); }
14 14 body {behavior: url(<%= stylesheet_path "csshover.htc" %>);}
15 15 </style>
16 16 <![endif]-->
17 17
18 18 <!-- page specific tags --><%= yield :header_tags %>
19 19 </head>
20 20 <body>
21 21 <div id="wrapper">
22 22 <div id="top-menu">
23 23 <div id="account">
24 24 <%= render_menu :account_menu -%>
25 25 </div>
26 26 <%= content_tag('div', "#{l(:label_logged_as)} #{User.current.login}", :id => 'loggedas') if User.current.logged? %>
27 27 <%= render_menu :top_menu -%>
28 28 </div>
29 29
30 30 <div id="header">
31 31 <div id="quick-search">
32 32 <% form_tag({:controller => 'search', :action => 'index', :id => @project}, :method => :get ) do %>
33 33 <%= link_to l(:label_search), {:controller => 'search', :action => 'index', :id => @project}, :accesskey => accesskey(:search) %>:
34 34 <%= text_field_tag 'q', @question, :size => 20, :class => 'small', :accesskey => accesskey(:quick_search) %>
35 35 <% end %>
36 36 <%= render :partial => 'layouts/project_selector' if User.current.memberships.any? %>
37 37 </div>
38 38
39 <h1><%= h(@project ? @project.name : Setting.app_title) %></h1>
39 <h1><%= h(@project && !@project.new_record? ? @project.name : Setting.app_title) %></h1>
40 40
41 41 <div id="main-menu">
42 42 <%= render_main_menu(@project) %>
43 43 </div>
44 44 </div>
45 45
46 46 <%= tag('div', {:id => 'main', :class => (has_content?(:sidebar) ? '' : 'nosidebar')}, true) %>
47 47 <div id="sidebar">
48 48 <%= yield :sidebar %>
49 49 </div>
50 50
51 51 <div id="content">
52 52 <%= content_tag('div', flash[:error], :class => 'flash error') if flash[:error] %>
53 53 <%= content_tag('div', flash[:notice], :class => 'flash notice') if flash[:notice] %>
54 54 <%= yield %>
55 55 </div>
56 56 </div>
57 57
58 58 <div id="ajax-indicator" style="display:none;"><span><%= l(:label_loading) %></span></div>
59 59
60 60 <div id="footer">
61 61 Powered by <%= link_to Redmine::Info.app_name, Redmine::Info.url %> &copy; 2006-2008 Jean-Philippe Lang
62 62 </div>
63 63 </div>
64 64 </body>
65 65 </html>
@@ -1,32 +1,32
1 1 <% @entries.each do |entry| %>
2 2 <% tr_id = Digest::MD5.hexdigest(entry.path)
3 3 depth = params[:depth].to_i %>
4 4 <tr id="<%= tr_id %>" class="<%= params[:parent_id] %> entry">
5 5 <td class="filename">
6 6 <%= if entry.is_dir?
7 7 link_to_remote h(entry.name),
8 8 {:url => {:action => 'browse', :id => @project, :path => entry.path, :rev => @rev, :depth => (depth + 1), :parent_id => tr_id},
9 9 :update => { :success => tr_id },
10 10 :position => :after,
11 11 :success => "scmEntryLoaded('#{tr_id}')",
12 12 :condition => "scmEntryClick('#{tr_id}')"
13 13 },
14 14 {:href => url_for({:action => 'browse', :id => @project, :path => entry.path, :rev => @rev}),
15 15 :class => ('icon icon-folder'),
16 16 :style => "margin-left: #{18 * depth}px;"
17 17 }
18 18 else
19 19 link_to h(entry.name),
20 20 {:action => (entry.is_dir? ? 'browse' : 'changes'), :id => @project, :path => entry.path, :rev => @rev},
21 21 :class => 'icon icon-file',
22 22 :style => "margin-left: #{18 * depth}px;"
23 23 end %>
24 24 </td>
25 25 <td class="size"><%= (entry.size ? number_to_human_size(entry.size) : "?") unless entry.is_dir? %></td>
26 26 <td class="revision"><%= link_to(format_revision(entry.lastrev.name), :action => 'revision', :id => @project, :rev => entry.lastrev.identifier) if entry.lastrev && entry.lastrev.identifier %></td>
27 27 <td class="age"><%= distance_of_time_in_words(entry.lastrev.time, Time.now) if entry.lastrev && entry.lastrev.time %></td>
28 28 <td class="author"><%=h(entry.lastrev.author.to_s.split('<').first) if entry.lastrev %></td>
29 <% changeset = @project.repository.changesets.find_by_revision(entry.lastrev.identifier) if entry.lastrev %>
29 <% changeset = @project.repository.changesets.find_by_revision(entry.lastrev.identifier) if entry.lastrev && entry.lastrev.identifier %>
30 30 <td class="comments"><%=h truncate(changeset.comments, 50) unless changeset.nil? %></td>
31 31 </tr>
32 32 <% end %>
@@ -1,18 +1,19
1 1 <h2><%= render :partial => 'navigation', :locals => { :path => @path, :kind => (@entry ? @entry.kind : nil), :revision => @rev } %></h2>
2 2
3 3 <h3><%=h @entry.name %></h3>
4 4
5 5 <p>
6 6 <% if @repository.supports_cat? %>
7 7 <%= link_to l(:button_view), {:action => 'entry', :id => @project, :path => @path, :rev => @rev } %> |
8 8 <% end %>
9 9 <% if @repository.supports_annotate? %>
10 10 <%= link_to l(:button_annotate), {:action => 'annotate', :id => @project, :path => @path, :rev => @rev } %> |
11 11 <% end %>
12 12 <%= link_to(l(:button_download), {:action => 'entry', :id => @project, :path => @path, :rev => @rev, :format => 'raw' }) if @repository.supports_cat? %>
13 13 <%= "(#{number_to_human_size(@entry.size)})" if @entry.size %>
14 14 </p>
15 15
16 <%= render :partial => 'revisions', :locals => {:project => @project, :path => @path, :revisions => @changesets, :entry => @entry }%>
16 <%= render(:partial => 'revisions',
17 :locals => {:project => @project, :path => @path, :revisions => @changesets, :entry => @entry }) unless @changesets.empty? %>
17 18
18 19 <% html_title(l(:label_change_plural)) -%>
@@ -1,977 +1,977
1 1 begin
2 2 require 'zlib'
3 3 @@__have_zlib = true
4 4 rescue
5 5 @@__have_zlib = false
6 6 end
7 7
8 8 require 'rexml/document'
9 9
10 10 module SVG
11 11 module Graph
12 12 VERSION = '@ANT_VERSION@'
13 13
14 14 # === Base object for generating SVG Graphs
15 15 #
16 16 # == Synopsis
17 17 #
18 18 # This class is only used as a superclass of specialized charts. Do not
19 19 # attempt to use this class directly, unless creating a new chart type.
20 20 #
21 21 # For examples of how to subclass this class, see the existing specific
22 22 # subclasses, such as SVG::Graph::Pie.
23 23 #
24 24 # == Examples
25 25 #
26 26 # For examples of how to use this package, see either the test files, or
27 27 # the documentation for the specific class you want to use.
28 28 #
29 29 # * file:test/plot.rb
30 30 # * file:test/single.rb
31 31 # * file:test/test.rb
32 32 # * file:test/timeseries.rb
33 33 #
34 34 # == Description
35 35 #
36 36 # This package should be used as a base for creating SVG graphs.
37 37 #
38 38 # == Acknowledgements
39 39 #
40 40 # Leo Lapworth for creating the SVG::TT::Graph package which this Ruby
41 41 # port is based on.
42 42 #
43 43 # Stephen Morgan for creating the TT template and SVG.
44 44 #
45 45 # == See
46 46 #
47 47 # * SVG::Graph::BarHorizontal
48 48 # * SVG::Graph::Bar
49 49 # * SVG::Graph::Line
50 50 # * SVG::Graph::Pie
51 51 # * SVG::Graph::Plot
52 52 # * SVG::Graph::TimeSeries
53 53 #
54 54 # == Author
55 55 #
56 56 # Sean E. Russell <serATgermaneHYPHENsoftwareDOTcom>
57 57 #
58 58 # Copyright 2004 Sean E. Russell
59 59 # This software is available under the Ruby license[LICENSE.txt]
60 60 #
61 61 class Graph
62 62 include REXML
63 63
64 64 # Initialize the graph object with the graph settings. You won't
65 65 # instantiate this class directly; see the subclass for options.
66 66 # [width] 500
67 67 # [height] 300
68 68 # [show_x_guidelines] false
69 69 # [show_y_guidelines] true
70 70 # [show_data_values] true
71 71 # [min_scale_value] 0
72 72 # [show_x_labels] true
73 73 # [stagger_x_labels] false
74 74 # [rotate_x_labels] false
75 75 # [step_x_labels] 1
76 76 # [step_include_first_x_label] true
77 77 # [show_y_labels] true
78 78 # [rotate_y_labels] false
79 79 # [scale_integers] false
80 80 # [show_x_title] false
81 81 # [x_title] 'X Field names'
82 82 # [show_y_title] false
83 83 # [y_title_text_direction] :bt
84 84 # [y_title] 'Y Scale'
85 85 # [show_graph_title] false
86 86 # [graph_title] 'Graph Title'
87 87 # [show_graph_subtitle] false
88 88 # [graph_subtitle] 'Graph Sub Title'
89 89 # [key] true,
90 90 # [key_position] :right, # bottom or righ
91 91 # [font_size] 12
92 92 # [title_font_size] 16
93 93 # [subtitle_font_size] 14
94 94 # [x_label_font_size] 12
95 95 # [x_title_font_size] 14
96 96 # [y_label_font_size] 12
97 97 # [y_title_font_size] 14
98 98 # [key_font_size] 10
99 99 # [no_css] false
100 100 # [add_popups] false
101 101 def initialize( config )
102 102 @config = config
103 103
104 104 self.top_align = self.top_font = self.right_align = self.right_font = 0
105 105
106 106 init_with({
107 107 :width => 500,
108 108 :height => 300,
109 109 :show_x_guidelines => false,
110 110 :show_y_guidelines => true,
111 111 :show_data_values => true,
112 112
113 113 :min_scale_value => 0,
114 114
115 115 :show_x_labels => true,
116 116 :stagger_x_labels => false,
117 117 :rotate_x_labels => false,
118 118 :step_x_labels => 1,
119 119 :step_include_first_x_label => true,
120 120
121 121 :show_y_labels => true,
122 122 :rotate_y_labels => false,
123 123 :stagger_y_labels => false,
124 124 :scale_integers => false,
125 125
126 126 :show_x_title => false,
127 127 :x_title => 'X Field names',
128 128
129 129 :show_y_title => false,
130 130 :y_title_text_direction => :bt,
131 131 :y_title => 'Y Scale',
132 132
133 133 :show_graph_title => false,
134 134 :graph_title => 'Graph Title',
135 135 :show_graph_subtitle => false,
136 136 :graph_subtitle => 'Graph Sub Title',
137 137 :key => true,
138 138 :key_position => :right, # bottom or right
139 139
140 140 :font_size =>10,
141 141 :title_font_size =>12,
142 142 :subtitle_font_size =>14,
143 143 :x_label_font_size =>11,
144 144 :x_title_font_size =>14,
145 145 :y_label_font_size =>11,
146 146 :y_title_font_size =>14,
147 147 :key_font_size => 9,
148 148
149 149 :no_css =>false,
150 150 :add_popups =>false,
151 151 })
152 152
153 153 set_defaults if methods.include? "set_defaults"
154 154
155 155 init_with config
156 156 end
157 157
158 158
159 159 # This method allows you do add data to the graph object.
160 160 # It can be called several times to add more data sets in.
161 161 #
162 162 # data_sales_02 = [12, 45, 21];
163 163 #
164 164 # graph.add_data({
165 165 # :data => data_sales_02,
166 166 # :title => 'Sales 2002'
167 167 # })
168 168 def add_data conf
169 169 @data = [] unless defined? @data
170 170
171 171 if conf[:data] and conf[:data].kind_of? Array
172 172 @data << conf
173 173 else
174 174 raise "No data provided by #{conf.inspect}"
175 175 end
176 176 end
177 177
178 178
179 179 # This method removes all data from the object so that you can
180 180 # reuse it to create a new graph but with the same config options.
181 181 #
182 182 # graph.clear_data
183 183 def clear_data
184 184 @data = []
185 185 end
186 186
187 187
188 188 # This method processes the template with the data and
189 189 # config which has been set and returns the resulting SVG.
190 190 #
191 191 # This method will croak unless at least one data set has
192 192 # been added to the graph object.
193 193 #
194 194 # print graph.burn
195 195 def burn
196 196 raise "No data available" unless @data.size > 0
197 197
198 198 calculations if methods.include? 'calculations'
199 199
200 200 start_svg
201 201 calculate_graph_dimensions
202 202 @foreground = Element.new( "g" )
203 203 draw_graph
204 204 draw_titles
205 205 draw_legend
206 206 draw_data
207 207 @graph.add_element( @foreground )
208 208 style
209 209
210 210 data = ""
211 211 @doc.write( data, 0 )
212 212
213 213 if @config[:compress]
214 214 if @@__have_zlib
215 215 inp, out = IO.pipe
216 216 gz = Zlib::GzipWriter.new( out )
217 217 gz.write data
218 218 gz.close
219 219 data = inp.read
220 220 else
221 221 data << "<!-- Ruby Zlib not available for SVGZ -->";
222 222 end
223 223 end
224 224
225 225 return data
226 226 end
227 227
228 228
229 229 # Set the height of the graph box, this is the total height
230 230 # of the SVG box created - not the graph it self which auto
231 231 # scales to fix the space.
232 232 attr_accessor :height
233 233 # Set the width of the graph box, this is the total width
234 234 # of the SVG box created - not the graph it self which auto
235 235 # scales to fix the space.
236 236 attr_accessor :width
237 237 # Set the path to an external stylesheet, set to '' if
238 238 # you want to revert back to using the defaut internal version.
239 239 #
240 240 # To create an external stylesheet create a graph using the
241 241 # default internal version and copy the stylesheet section to
242 242 # an external file and edit from there.
243 243 attr_accessor :style_sheet
244 244 # (Bool) Show the value of each element of data on the graph
245 245 attr_accessor :show_data_values
246 246 # The point at which the Y axis starts, defaults to '0',
247 247 # if set to nil it will default to the minimum data value.
248 248 attr_accessor :min_scale_value
249 249 # Whether to show labels on the X axis or not, defaults
250 250 # to true, set to false if you want to turn them off.
251 251 attr_accessor :show_x_labels
252 252 # This puts the X labels at alternative levels so if they
253 253 # are long field names they will not overlap so easily.
254 254 # Default it false, to turn on set to true.
255 255 attr_accessor :stagger_x_labels
256 256 # This puts the Y labels at alternative levels so if they
257 257 # are long field names they will not overlap so easily.
258 258 # Default it false, to turn on set to true.
259 259 attr_accessor :stagger_y_labels
260 260 # This turns the X axis labels by 90 degrees.
261 261 # Default it false, to turn on set to true.
262 262 attr_accessor :rotate_x_labels
263 263 # This turns the Y axis labels by 90 degrees.
264 264 # Default it false, to turn on set to true.
265 265 attr_accessor :rotate_y_labels
266 266 # How many "steps" to use between displayed X axis labels,
267 267 # a step of one means display every label, a step of two results
268 268 # in every other label being displayed (label <gap> label <gap> label),
269 269 # a step of three results in every third label being displayed
270 270 # (label <gap> <gap> label <gap> <gap> label) and so on.
271 271 attr_accessor :step_x_labels
272 272 # Whether to (when taking "steps" between X axis labels) step from
273 273 # the first label (i.e. always include the first label) or step from
274 274 # the X axis origin (i.e. start with a gap if step_x_labels is greater
275 275 # than one).
276 276 attr_accessor :step_include_first_x_label
277 277 # Whether to show labels on the Y axis or not, defaults
278 278 # to true, set to false if you want to turn them off.
279 279 attr_accessor :show_y_labels
280 280 # Ensures only whole numbers are used as the scale divisions.
281 281 # Default it false, to turn on set to true. This has no effect if
282 282 # scale divisions are less than 1.
283 283 attr_accessor :scale_integers
284 284 # This defines the gap between markers on the Y axis,
285 285 # default is a 10th of the max_value, e.g. you will have
286 286 # 10 markers on the Y axis. NOTE: do not set this too
287 287 # low - you are limited to 999 markers, after that the
288 288 # graph won't generate.
289 289 attr_accessor :scale_divisions
290 290 # Whether to show the title under the X axis labels,
291 291 # default is false, set to true to show.
292 292 attr_accessor :show_x_title
293 293 # What the title under X axis should be, e.g. 'Months'.
294 294 attr_accessor :x_title
295 295 # Whether to show the title under the Y axis labels,
296 296 # default is false, set to true to show.
297 297 attr_accessor :show_y_title
298 298 # Aligns writing mode for Y axis label.
299 299 # Defaults to :bt (Bottom to Top).
300 300 # Change to :tb (Top to Bottom) to reverse.
301 301 attr_accessor :y_title_text_direction
302 302 # What the title under Y axis should be, e.g. 'Sales in thousands'.
303 303 attr_accessor :y_title
304 304 # Whether to show a title on the graph, defaults
305 305 # to false, set to true to show.
306 306 attr_accessor :show_graph_title
307 307 # What the title on the graph should be.
308 308 attr_accessor :graph_title
309 309 # Whether to show a subtitle on the graph, defaults
310 310 # to false, set to true to show.
311 311 attr_accessor :show_graph_subtitle
312 312 # What the subtitle on the graph should be.
313 313 attr_accessor :graph_subtitle
314 314 # Whether to show a key, defaults to false, set to
315 315 # true if you want to show it.
316 316 attr_accessor :key
317 317 # Where the key should be positioned, defaults to
318 318 # :right, set to :bottom if you want to move it.
319 319 attr_accessor :key_position
320 320 # Set the font size (in points) of the data point labels
321 321 attr_accessor :font_size
322 322 # Set the font size of the X axis labels
323 323 attr_accessor :x_label_font_size
324 324 # Set the font size of the X axis title
325 325 attr_accessor :x_title_font_size
326 326 # Set the font size of the Y axis labels
327 327 attr_accessor :y_label_font_size
328 328 # Set the font size of the Y axis title
329 329 attr_accessor :y_title_font_size
330 330 # Set the title font size
331 331 attr_accessor :title_font_size
332 332 # Set the subtitle font size
333 333 attr_accessor :subtitle_font_size
334 334 # Set the key font size
335 335 attr_accessor :key_font_size
336 336 # Show guidelines for the X axis
337 337 attr_accessor :show_x_guidelines
338 338 # Show guidelines for the Y axis
339 339 attr_accessor :show_y_guidelines
340 340 # Do not use CSS if set to true. Many SVG viewers do not support CSS, but
341 341 # not using CSS can result in larger SVGs as well as making it impossible to
342 342 # change colors after the chart is generated. Defaults to false.
343 343 attr_accessor :no_css
344 344 # Add popups for the data points on some graphs
345 345 attr_accessor :add_popups
346 346
347 347
348 348 protected
349 349
350 350 def sort( *arrys )
351 351 sort_multiple( arrys )
352 352 end
353 353
354 354 # Overwrite configuration options with supplied options. Used
355 355 # by subclasses.
356 356 def init_with config
357 357 config.each { |key, value|
358 358 self.send( key.to_s+"=", value ) if methods.include? key.to_s
359 359 }
360 360 end
361 361
362 362 attr_accessor :top_align, :top_font, :right_align, :right_font
363 363
364 364 KEY_BOX_SIZE = 12
365 365
366 366 # Override this (and call super) to change the margin to the left
367 367 # of the plot area. Results in @border_left being set.
368 368 def calculate_left_margin
369 369 @border_left = 7
370 370 # Check for Y labels
371 371 max_y_label_height_px = rotate_y_labels ?
372 372 y_label_font_size :
373 373 get_y_labels.max{|a,b|
374 374 a.to_s.length<=>b.to_s.length
375 375 }.to_s.length * y_label_font_size * 0.6
376 376 @border_left += max_y_label_height_px if show_y_labels
377 377 @border_left += max_y_label_height_px + 10 if stagger_y_labels
378 378 @border_left += y_title_font_size + 5 if show_y_title
379 379 end
380 380
381 381
382 382 # Calculates the width of the widest Y label. This will be the
383 383 # character height if the Y labels are rotated
384 384 def max_y_label_width_px
385 385 return font_size if rotate_y_labels
386 386 end
387 387
388 388
389 389 # Override this (and call super) to change the margin to the right
390 390 # of the plot area. Results in @border_right being set.
391 391 def calculate_right_margin
392 392 @border_right = 7
393 393 if key and key_position == :right
394 394 val = keys.max { |a,b| a.length <=> b.length }
395 395 @border_right += val.length * key_font_size * 0.7
396 396 @border_right += KEY_BOX_SIZE
397 397 @border_right += 10 # Some padding around the box
398 398 end
399 399 end
400 400
401 401
402 402 # Override this (and call super) to change the margin to the top
403 403 # of the plot area. Results in @border_top being set.
404 404 def calculate_top_margin
405 405 @border_top = 5
406 406 @border_top += title_font_size if show_graph_title
407 407 @border_top += 5
408 408 @border_top += subtitle_font_size if show_graph_subtitle
409 409 end
410 410
411 411
412 412 # Adds pop-up point information to a graph.
413 413 def add_popup( x, y, label )
414 414 txt_width = label.length * font_size * 0.6 + 10
415 415 tx = (x+txt_width > width ? x-5 : x+5)
416 416 t = @foreground.add_element( "text", {
417 417 "x" => tx.to_s,
418 418 "y" => (y - font_size).to_s,
419 419 "visibility" => "hidden",
420 420 })
421 421 t.attributes["style"] = "fill: #000; "+
422 422 (x+txt_width > width ? "text-anchor: end;" : "text-anchor: start;")
423 423 t.text = label.to_s
424 424 t.attributes["id"] = t.id.to_s
425 425
426 426 @foreground.add_element( "circle", {
427 427 "cx" => x.to_s,
428 428 "cy" => y.to_s,
429 429 "r" => "10",
430 430 "style" => "opacity: 0",
431 431 "onmouseover" =>
432 432 "document.getElementById(#{t.id}).setAttribute('visibility', 'visible' )",
433 433 "onmouseout" =>
434 434 "document.getElementById(#{t.id}).setAttribute('visibility', 'hidden' )",
435 435 })
436 436
437 437 end
438 438
439 439
440 440 # Override this (and call super) to change the margin to the bottom
441 441 # of the plot area. Results in @border_bottom being set.
442 442 def calculate_bottom_margin
443 443 @border_bottom = 7
444 444 if key and key_position == :bottom
445 445 @border_bottom += @data.size * (font_size + 5)
446 446 @border_bottom += 10
447 447 end
448 448 if show_x_labels
449 449 max_x_label_height_px = rotate_x_labels ?
450 450 get_x_labels.max{|a,b|
451 451 a.length<=>b.length
452 452 }.length * x_label_font_size * 0.6 :
453 453 x_label_font_size
454 454 @border_bottom += max_x_label_height_px
455 455 @border_bottom += max_x_label_height_px + 10 if stagger_x_labels
456 456 end
457 457 @border_bottom += x_title_font_size + 5 if show_x_title
458 458 end
459 459
460 460
461 461 # Draws the background, axis, and labels.
462 462 def draw_graph
463 463 @graph = @root.add_element( "g", {
464 464 "transform" => "translate( #@border_left #@border_top )"
465 465 })
466 466
467 467 # Background
468 468 @graph.add_element( "rect", {
469 469 "x" => "0",
470 470 "y" => "0",
471 471 "width" => @graph_width.to_s,
472 472 "height" => @graph_height.to_s,
473 473 "class" => "graphBackground"
474 474 })
475 475
476 476 # Axis
477 477 @graph.add_element( "path", {
478 478 "d" => "M 0 0 v#@graph_height",
479 479 "class" => "axis",
480 480 "id" => "xAxis"
481 481 })
482 482 @graph.add_element( "path", {
483 483 "d" => "M 0 #@graph_height h#@graph_width",
484 484 "class" => "axis",
485 485 "id" => "yAxis"
486 486 })
487 487
488 488 draw_x_labels
489 489 draw_y_labels
490 490 end
491 491
492 492
493 493 # Where in the X area the label is drawn
494 494 # Centered in the field, should be width/2. Start, 0.
495 495 def x_label_offset( width )
496 496 0
497 497 end
498 498
499 499 def make_datapoint_text( x, y, value, style="" )
500 500 if show_data_values
501 501 @foreground.add_element( "text", {
502 502 "x" => x.to_s,
503 503 "y" => y.to_s,
504 504 "class" => "dataPointLabel",
505 505 "style" => "#{style} stroke: #fff; stroke-width: 2;"
506 506 }).text = value.to_s
507 507 text = @foreground.add_element( "text", {
508 508 "x" => x.to_s,
509 509 "y" => y.to_s,
510 510 "class" => "dataPointLabel"
511 511 })
512 512 text.text = value.to_s
513 513 text.attributes["style"] = style if style.length > 0
514 514 end
515 515 end
516 516
517 517
518 518 # Draws the X axis labels
519 519 def draw_x_labels
520 520 stagger = x_label_font_size + 5
521 521 if show_x_labels
522 522 label_width = field_width
523 523
524 524 count = 0
525 525 for label in get_x_labels
526 526 if step_include_first_x_label == true then
527 527 step = count % step_x_labels
528 528 else
529 529 step = (count + 1) % step_x_labels
530 530 end
531 531
532 532 if step == 0 then
533 533 text = @graph.add_element( "text" )
534 534 text.attributes["class"] = "xAxisLabels"
535 535 text.text = label.to_s
536 536
537 537 x = count * label_width + x_label_offset( label_width )
538 538 y = @graph_height + x_label_font_size + 3
539 539 t = 0 - (font_size / 2)
540 540
541 541 if stagger_x_labels and count % 2 == 1
542 542 y += stagger
543 543 @graph.add_element( "path", {
544 544 "d" => "M#{x} #@graph_height v#{stagger}",
545 545 "class" => "staggerGuideLine"
546 546 })
547 547 end
548 548
549 549 text.attributes["x"] = x.to_s
550 550 text.attributes["y"] = y.to_s
551 551 if rotate_x_labels
552 552 text.attributes["transform"] =
553 553 "rotate( 90 #{x} #{y-x_label_font_size} )"+
554 554 " translate( 0 -#{x_label_font_size/4} )"
555 555 text.attributes["style"] = "text-anchor: start"
556 556 else
557 557 text.attributes["style"] = "text-anchor: middle"
558 558 end
559 559 end
560 560
561 561 draw_x_guidelines( label_width, count ) if show_x_guidelines
562 562 count += 1
563 563 end
564 564 end
565 565 end
566 566
567 567
568 568 # Where in the Y area the label is drawn
569 569 # Centered in the field, should be width/2. Start, 0.
570 570 def y_label_offset( height )
571 571 0
572 572 end
573 573
574 574
575 575 def field_width
576 576 (@graph_width.to_f - font_size*2*right_font) /
577 577 (get_x_labels.length - right_align)
578 578 end
579 579
580 580
581 581 def field_height
582 582 (@graph_height.to_f - font_size*2*top_font) /
583 583 (get_y_labels.length - top_align)
584 584 end
585 585
586 586
587 587 # Draws the Y axis labels
588 588 def draw_y_labels
589 589 stagger = y_label_font_size + 5
590 590 if show_y_labels
591 591 label_height = field_height
592 592
593 593 count = 0
594 594 y_offset = @graph_height + y_label_offset( label_height )
595 595 y_offset += font_size/1.2 unless rotate_y_labels
596 596 for label in get_y_labels
597 597 y = y_offset - (label_height * count)
598 598 x = rotate_y_labels ? 0 : -3
599 599
600 600 if stagger_y_labels and count % 2 == 1
601 601 x -= stagger
602 602 @graph.add_element( "path", {
603 603 "d" => "M#{x} #{y} h#{stagger}",
604 604 "class" => "staggerGuideLine"
605 605 })
606 606 end
607 607
608 608 text = @graph.add_element( "text", {
609 609 "x" => x.to_s,
610 610 "y" => y.to_s,
611 611 "class" => "yAxisLabels"
612 612 })
613 613 text.text = label.to_s
614 614 if rotate_y_labels
615 615 text.attributes["transform"] = "translate( -#{font_size} 0 ) "+
616 616 "rotate( 90 #{x} #{y} ) "
617 617 text.attributes["style"] = "text-anchor: middle"
618 618 else
619 619 text.attributes["y"] = (y - (y_label_font_size/2)).to_s
620 620 text.attributes["style"] = "text-anchor: end"
621 621 end
622 622 draw_y_guidelines( label_height, count ) if show_y_guidelines
623 623 count += 1
624 624 end
625 625 end
626 626 end
627 627
628 628
629 629 # Draws the X axis guidelines
630 630 def draw_x_guidelines( label_height, count )
631 631 if count != 0
632 632 @graph.add_element( "path", {
633 633 "d" => "M#{label_height*count} 0 v#@graph_height",
634 634 "class" => "guideLines"
635 635 })
636 636 end
637 637 end
638 638
639 639
640 640 # Draws the Y axis guidelines
641 641 def draw_y_guidelines( label_height, count )
642 642 if count != 0
643 643 @graph.add_element( "path", {
644 644 "d" => "M0 #{@graph_height-(label_height*count)} h#@graph_width",
645 645 "class" => "guideLines"
646 646 })
647 647 end
648 648 end
649 649
650 650
651 651 # Draws the graph title and subtitle
652 652 def draw_titles
653 653 if show_graph_title
654 654 @root.add_element( "text", {
655 655 "x" => (width / 2).to_s,
656 656 "y" => (title_font_size).to_s,
657 657 "class" => "mainTitle"
658 658 }).text = graph_title.to_s
659 659 end
660 660
661 661 if show_graph_subtitle
662 662 y_subtitle = show_graph_title ?
663 663 title_font_size + 10 :
664 664 subtitle_font_size
665 665 @root.add_element("text", {
666 666 "x" => (width / 2).to_s,
667 667 "y" => (y_subtitle).to_s,
668 668 "class" => "subTitle"
669 669 }).text = graph_subtitle.to_s
670 670 end
671 671
672 672 if show_x_title
673 673 y = @graph_height + @border_top + x_title_font_size
674 674 if show_x_labels
675 675 y += x_label_font_size + 5 if stagger_x_labels
676 676 y += x_label_font_size + 5
677 677 end
678 678 x = width / 2
679 679
680 680 @root.add_element("text", {
681 681 "x" => x.to_s,
682 682 "y" => y.to_s,
683 683 "class" => "xAxisTitle",
684 684 }).text = x_title.to_s
685 685 end
686 686
687 687 if show_y_title
688 688 x = y_title_font_size + (y_title_text_direction==:bt ? 3 : -3)
689 689 y = height / 2
690 690
691 691 text = @root.add_element("text", {
692 692 "x" => x.to_s,
693 693 "y" => y.to_s,
694 694 "class" => "yAxisTitle",
695 695 })
696 696 text.text = y_title.to_s
697 697 if y_title_text_direction == :bt
698 698 text.attributes["transform"] = "rotate( -90, #{x}, #{y} )"
699 699 else
700 700 text.attributes["transform"] = "rotate( 90, #{x}, #{y} )"
701 701 end
702 702 end
703 703 end
704 704
705 705 def keys
706 706 return @data.collect{ |d| d[:title] }
707 707 end
708 708
709 709 # Draws the legend on the graph
710 710 def draw_legend
711 711 if key
712 712 group = @root.add_element( "g" )
713 713
714 714 key_count = 0
715 715 for key_name in keys
716 716 y_offset = (KEY_BOX_SIZE * key_count) + (key_count * 5)
717 717 group.add_element( "rect", {
718 718 "x" => 0.to_s,
719 719 "y" => y_offset.to_s,
720 720 "width" => KEY_BOX_SIZE.to_s,
721 721 "height" => KEY_BOX_SIZE.to_s,
722 722 "class" => "key#{key_count+1}"
723 723 })
724 724 group.add_element( "text", {
725 725 "x" => (KEY_BOX_SIZE + 5).to_s,
726 726 "y" => (y_offset + KEY_BOX_SIZE - 2).to_s,
727 727 "class" => "keyText"
728 728 }).text = key_name.to_s
729 729 key_count += 1
730 730 end
731 731
732 732 case key_position
733 733 when :right
734 734 x_offset = @graph_width + @border_left + 10
735 735 y_offset = @border_top + 20
736 736 when :bottom
737 737 x_offset = @border_left + 20
738 738 y_offset = @border_top + @graph_height + 5
739 739 if show_x_labels
740 740 max_x_label_height_px = rotate_x_labels ?
741 741 get_x_labels.max{|a,b|
742 742 a.length<=>b.length
743 743 }.length * x_label_font_size :
744 744 x_label_font_size
745 745 y_offset += max_x_label_height_px
746 746 y_offset += max_x_label_height_px + 5 if stagger_x_labels
747 747 end
748 748 y_offset += x_title_font_size + 5 if show_x_title
749 749 end
750 750 group.attributes["transform"] = "translate(#{x_offset} #{y_offset})"
751 751 end
752 752 end
753 753
754 754
755 755 private
756 756
757 757 def sort_multiple( arrys, lo=0, hi=arrys[0].length-1 )
758 758 if lo < hi
759 759 p = partition(arrys,lo,hi)
760 760 sort_multiple(arrys, lo, p-1)
761 761 sort_multiple(arrys, p+1, hi)
762 762 end
763 763 arrys
764 764 end
765 765
766 766 def partition( arrys, lo, hi )
767 767 p = arrys[0][lo]
768 768 l = lo
769 769 z = lo+1
770 770 while z <= hi
771 771 if arrys[0][z] < p
772 772 l += 1
773 773 arrys.each { |arry| arry[z], arry[l] = arry[l], arry[z] }
774 774 end
775 775 z += 1
776 776 end
777 777 arrys.each { |arry| arry[lo], arry[l] = arry[l], arry[lo] }
778 778 l
779 779 end
780 780
781 781 def style
782 782 if no_css
783 783 styles = parse_css
784 784 @root.elements.each("//*[@class]") { |el|
785 785 cl = el.attributes["class"]
786 786 style = styles[cl]
787 787 style += el.attributes["style"] if el.attributes["style"]
788 788 el.attributes["style"] = style
789 789 }
790 790 end
791 791 end
792 792
793 793 def parse_css
794 794 css = get_style
795 795 rv = {}
796 796 while css =~ /^(\.(\w+)(?:\s*,\s*\.\w+)*)\s*\{/m
797 797 names_orig = names = $1
798 798 css = $'
799 799 css =~ /([^}]+)\}/m
800 800 content = $1
801 801 css = $'
802 802
803 803 nms = []
804 804 while names =~ /^\s*,?\s*\.(\w+)/
805 805 nms << $1
806 806 names = $'
807 807 end
808 808
809 809 content = content.tr( "\n\t", " ")
810 810 for name in nms
811 811 current = rv[name]
812 812 current = current ? current+"; "+content : content
813 813 rv[name] = current.strip.squeeze(" ")
814 814 end
815 815 end
816 816 return rv
817 817 end
818 818
819 819
820 820 # Override and place code to add defs here
821 821 def add_defs defs
822 822 end
823 823
824 824
825 825 def start_svg
826 826 # Base document
827 827 @doc = Document.new
828 828 @doc << XMLDecl.new
829 829 @doc << DocType.new( %q{svg PUBLIC "-//W3C//DTD SVG 1.0//EN" } +
830 830 %q{"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"} )
831 831 if style_sheet && style_sheet != ''
832 @doc << ProcessingInstruction.new( "xml-stylesheet",
832 @doc << Instruction.new( "xml-stylesheet",
833 833 %Q{href="#{style_sheet}" type="text/css"} )
834 834 end
835 835 @root = @doc.add_element( "svg", {
836 836 "width" => width.to_s,
837 837 "height" => height.to_s,
838 838 "viewBox" => "0 0 #{width} #{height}",
839 839 "xmlns" => "http://www.w3.org/2000/svg",
840 840 "xmlns:xlink" => "http://www.w3.org/1999/xlink",
841 841 "xmlns:a3" => "http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/",
842 842 "a3:scriptImplementation" => "Adobe"
843 843 })
844 844 @root << Comment.new( " "+"\\"*66 )
845 845 @root << Comment.new( " Created with SVG::Graph " )
846 846 @root << Comment.new( " SVG::Graph by Sean E. Russell " )
847 847 @root << Comment.new( " Losely based on SVG::TT::Graph for Perl by"+
848 848 " Leo Lapworth & Stephan Morgan " )
849 849 @root << Comment.new( " "+"/"*66 )
850 850
851 851 defs = @root.add_element( "defs" )
852 852 add_defs defs
853 853 if not(style_sheet && style_sheet != '') and !no_css
854 854 @root << Comment.new(" include default stylesheet if none specified ")
855 855 style = defs.add_element( "style", {"type"=>"text/css"} )
856 856 style << CData.new( get_style )
857 857 end
858 858
859 859 @root << Comment.new( "SVG Background" )
860 860 @root.add_element( "rect", {
861 861 "width" => width.to_s,
862 862 "height" => height.to_s,
863 863 "x" => "0",
864 864 "y" => "0",
865 865 "class" => "svgBackground"
866 866 })
867 867 end
868 868
869 869
870 870 def calculate_graph_dimensions
871 871 calculate_left_margin
872 872 calculate_right_margin
873 873 calculate_bottom_margin
874 874 calculate_top_margin
875 875 @graph_width = width - @border_left - @border_right
876 876 @graph_height = height - @border_top - @border_bottom
877 877 end
878 878
879 879 def get_style
880 880 return <<EOL
881 881 /* Copy from here for external style sheet */
882 882 .svgBackground{
883 883 fill:#ffffff;
884 884 }
885 885 .graphBackground{
886 886 fill:#f5f5f5;
887 887 }
888 888
889 889 /* graphs titles */
890 890 .mainTitle{
891 891 text-anchor: middle;
892 892 fill: #555555;
893 893 font-size: #{title_font_size}px;
894 894 font-family: "Verdana", sans-serif;
895 895 font-weight: bold;
896 896 }
897 897 .subTitle{
898 898 text-anchor: middle;
899 899 fill: #999999;
900 900 font-size: #{subtitle_font_size}px;
901 901 font-family: "Verdana", sans-serif;
902 902 font-weight: normal;
903 903 }
904 904
905 905 .axis{
906 906 stroke: #666666;
907 907 stroke-width: 1px;
908 908 }
909 909
910 910 .guideLines{
911 911 stroke: #666666;
912 912 stroke-width: 1px;
913 913 stroke-dasharray:2,2,2;
914 914 }
915 915
916 916 .xAxisLabels{
917 917 text-anchor: middle;
918 918 fill: #000000;
919 919 font-size: #{x_label_font_size}px;
920 920 font-family: "Verdana", sans-serif;
921 921 font-weight: normal;
922 922 }
923 923
924 924 .yAxisLabels{
925 925 text-anchor: end;
926 926 fill: #000000;
927 927 font-size: #{y_label_font_size}px;
928 928 font-family: "Verdana", sans-serif;
929 929 font-weight: normal;
930 930 }
931 931
932 932 .xAxisTitle{
933 933 text-anchor: middle;
934 934 fill: #ff0000;
935 935 font-size: #{x_title_font_size}px;
936 936 font-family: "Verdana", sans-serif;
937 937 font-weight: normal;
938 938 }
939 939
940 940 .yAxisTitle{
941 941 fill: #ff0000;
942 942 text-anchor: middle;
943 943 font-size: #{y_title_font_size}px;
944 944 font-family: "Verdana", sans-serif;
945 945 font-weight: normal;
946 946 }
947 947
948 948 .dataPointLabel{
949 949 fill: #000000;
950 950 text-anchor:middle;
951 951 font-size: 10px;
952 952 font-family: "Verdana", sans-serif;
953 953 font-weight: normal;
954 954 }
955 955
956 956 .staggerGuideLine{
957 957 fill: none;
958 958 stroke: #000000;
959 959 stroke-width: 0.5px;
960 960 }
961 961
962 962 #{get_css}
963 963
964 964 .keyText{
965 965 fill: #000000;
966 966 text-anchor:start;
967 967 font-size: #{key_font_size}px;
968 968 font-family: "Verdana", sans-serif;
969 969 font-weight: normal;
970 970 }
971 971 /* End copy for external style sheet */
972 972 EOL
973 973 end
974 974
975 975 end
976 976 end
977 977 end
@@ -1,1140 +1,1140
1 1 # vim:ts=4:sw=4:
2 2 # = RedCloth - Textile and Markdown Hybrid for Ruby
3 3 #
4 4 # Homepage:: http://whytheluckystiff.net/ruby/redcloth/
5 5 # Author:: why the lucky stiff (http://whytheluckystiff.net/)
6 6 # Copyright:: (cc) 2004 why the lucky stiff (and his puppet organizations.)
7 7 # License:: BSD
8 8 #
9 9 # (see http://hobix.com/textile/ for a Textile Reference.)
10 10 #
11 11 # Based on (and also inspired by) both:
12 12 #
13 13 # PyTextile: http://diveintomark.org/projects/textile/textile.py.txt
14 14 # Textism for PHP: http://www.textism.com/tools/textile/
15 15 #
16 16 #
17 17
18 18 # = RedCloth
19 19 #
20 20 # RedCloth is a Ruby library for converting Textile and/or Markdown
21 21 # into HTML. You can use either format, intermingled or separately.
22 22 # You can also extend RedCloth to honor your own custom text stylings.
23 23 #
24 24 # RedCloth users are encouraged to use Textile if they are generating
25 25 # HTML and to use Markdown if others will be viewing the plain text.
26 26 #
27 27 # == What is Textile?
28 28 #
29 29 # Textile is a simple formatting style for text
30 30 # documents, loosely based on some HTML conventions.
31 31 #
32 32 # == Sample Textile Text
33 33 #
34 34 # h2. This is a title
35 35 #
36 36 # h3. This is a subhead
37 37 #
38 38 # This is a bit of paragraph.
39 39 #
40 40 # bq. This is a blockquote.
41 41 #
42 42 # = Writing Textile
43 43 #
44 44 # A Textile document consists of paragraphs. Paragraphs
45 45 # can be specially formatted by adding a small instruction
46 46 # to the beginning of the paragraph.
47 47 #
48 48 # h[n]. Header of size [n].
49 49 # bq. Blockquote.
50 50 # # Numeric list.
51 51 # * Bulleted list.
52 52 #
53 53 # == Quick Phrase Modifiers
54 54 #
55 55 # Quick phrase modifiers are also included, to allow formatting
56 56 # of small portions of text within a paragraph.
57 57 #
58 58 # \_emphasis\_
59 59 # \_\_italicized\_\_
60 60 # \*strong\*
61 61 # \*\*bold\*\*
62 62 # ??citation??
63 63 # -deleted text-
64 64 # +inserted text+
65 65 # ^superscript^
66 66 # ~subscript~
67 67 # @code@
68 68 # %(classname)span%
69 69 #
70 70 # ==notextile== (leave text alone)
71 71 #
72 72 # == Links
73 73 #
74 74 # To make a hypertext link, put the link text in "quotation
75 75 # marks" followed immediately by a colon and the URL of the link.
76 76 #
77 77 # Optional: text in (parentheses) following the link text,
78 78 # but before the closing quotation mark, will become a Title
79 79 # attribute for the link, visible as a tool tip when a cursor is above it.
80 80 #
81 81 # Example:
82 82 #
83 83 # "This is a link (This is a title) ":http://www.textism.com
84 84 #
85 85 # Will become:
86 86 #
87 87 # <a href="http://www.textism.com" title="This is a title">This is a link</a>
88 88 #
89 89 # == Images
90 90 #
91 91 # To insert an image, put the URL for the image inside exclamation marks.
92 92 #
93 93 # Optional: text that immediately follows the URL in (parentheses) will
94 94 # be used as the Alt text for the image. Images on the web should always
95 95 # have descriptive Alt text for the benefit of readers using non-graphical
96 96 # browsers.
97 97 #
98 98 # Optional: place a colon followed by a URL immediately after the
99 99 # closing ! to make the image into a link.
100 100 #
101 101 # Example:
102 102 #
103 103 # !http://www.textism.com/common/textist.gif(Textist)!
104 104 #
105 105 # Will become:
106 106 #
107 107 # <img src="http://www.textism.com/common/textist.gif" alt="Textist" />
108 108 #
109 109 # With a link:
110 110 #
111 111 # !/common/textist.gif(Textist)!:http://textism.com
112 112 #
113 113 # Will become:
114 114 #
115 115 # <a href="http://textism.com"><img src="/common/textist.gif" alt="Textist" /></a>
116 116 #
117 117 # == Defining Acronyms
118 118 #
119 119 # HTML allows authors to define acronyms via the tag. The definition appears as a
120 120 # tool tip when a cursor hovers over the acronym. A crucial aid to clear writing,
121 121 # this should be used at least once for each acronym in documents where they appear.
122 122 #
123 123 # To quickly define an acronym in Textile, place the full text in (parentheses)
124 124 # immediately following the acronym.
125 125 #
126 126 # Example:
127 127 #
128 128 # ACLU(American Civil Liberties Union)
129 129 #
130 130 # Will become:
131 131 #
132 132 # <acronym title="American Civil Liberties Union">ACLU</acronym>
133 133 #
134 134 # == Adding Tables
135 135 #
136 136 # In Textile, simple tables can be added by seperating each column by
137 137 # a pipe.
138 138 #
139 139 # |a|simple|table|row|
140 140 # |And|Another|table|row|
141 141 #
142 142 # Attributes are defined by style definitions in parentheses.
143 143 #
144 144 # table(border:1px solid black).
145 145 # (background:#ddd;color:red). |{}| | | |
146 146 #
147 147 # == Using RedCloth
148 148 #
149 149 # RedCloth is simply an extension of the String class, which can handle
150 150 # Textile formatting. Use it like a String and output HTML with its
151 151 # RedCloth#to_html method.
152 152 #
153 153 # doc = RedCloth.new "
154 154 #
155 155 # h2. Test document
156 156 #
157 157 # Just a simple test."
158 158 #
159 159 # puts doc.to_html
160 160 #
161 161 # By default, RedCloth uses both Textile and Markdown formatting, with
162 162 # Textile formatting taking precedence. If you want to turn off Markdown
163 163 # formatting, to boost speed and limit the processor:
164 164 #
165 165 # class RedCloth::Textile.new( str )
166 166
167 167 class RedCloth < String
168 168
169 169 VERSION = '3.0.4'
170 170 DEFAULT_RULES = [:textile, :markdown]
171 171
172 172 #
173 173 # Two accessor for setting security restrictions.
174 174 #
175 175 # This is a nice thing if you're using RedCloth for
176 176 # formatting in public places (e.g. Wikis) where you
177 177 # don't want users to abuse HTML for bad things.
178 178 #
179 179 # If +:filter_html+ is set, HTML which wasn't
180 180 # created by the Textile processor will be escaped.
181 181 #
182 182 # If +:filter_styles+ is set, it will also disable
183 183 # the style markup specifier. ('{color: red}')
184 184 #
185 185 attr_accessor :filter_html, :filter_styles
186 186
187 187 #
188 188 # Accessor for toggling hard breaks.
189 189 #
190 190 # If +:hard_breaks+ is set, single newlines will
191 191 # be converted to HTML break tags. This is the
192 192 # default behavior for traditional RedCloth.
193 193 #
194 194 attr_accessor :hard_breaks
195 195
196 196 # Accessor for toggling lite mode.
197 197 #
198 198 # In lite mode, block-level rules are ignored. This means
199 199 # that tables, paragraphs, lists, and such aren't available.
200 200 # Only the inline markup for bold, italics, entities and so on.
201 201 #
202 202 # r = RedCloth.new( "And then? She *fell*!", [:lite_mode] )
203 203 # r.to_html
204 204 # #=> "And then? She <strong>fell</strong>!"
205 205 #
206 206 attr_accessor :lite_mode
207 207
208 208 #
209 209 # Accessor for toggling span caps.
210 210 #
211 211 # Textile places `span' tags around capitalized
212 212 # words by default, but this wreaks havoc on Wikis.
213 213 # If +:no_span_caps+ is set, this will be
214 214 # suppressed.
215 215 #
216 216 attr_accessor :no_span_caps
217 217
218 218 #
219 219 # Establishes the markup predence. Available rules include:
220 220 #
221 221 # == Textile Rules
222 222 #
223 223 # The following textile rules can be set individually. Or add the complete
224 224 # set of rules with the single :textile rule, which supplies the rule set in
225 225 # the following precedence:
226 226 #
227 227 # refs_textile:: Textile references (i.e. [hobix]http://hobix.com/)
228 228 # block_textile_table:: Textile table block structures
229 229 # block_textile_lists:: Textile list structures
230 230 # block_textile_prefix:: Textile blocks with prefixes (i.e. bq., h2., etc.)
231 231 # inline_textile_image:: Textile inline images
232 232 # inline_textile_link:: Textile inline links
233 233 # inline_textile_span:: Textile inline spans
234 234 # glyphs_textile:: Textile entities (such as em-dashes and smart quotes)
235 235 #
236 236 # == Markdown
237 237 #
238 238 # refs_markdown:: Markdown references (for example: [hobix]: http://hobix.com/)
239 239 # block_markdown_setext:: Markdown setext headers
240 240 # block_markdown_atx:: Markdown atx headers
241 241 # block_markdown_rule:: Markdown horizontal rules
242 242 # block_markdown_bq:: Markdown blockquotes
243 243 # block_markdown_lists:: Markdown lists
244 244 # inline_markdown_link:: Markdown links
245 245 attr_accessor :rules
246 246
247 247 # Returns a new RedCloth object, based on _string_ and
248 248 # enforcing all the included _restrictions_.
249 249 #
250 250 # r = RedCloth.new( "h1. A <b>bold</b> man", [:filter_html] )
251 251 # r.to_html
252 252 # #=>"<h1>A &lt;b&gt;bold&lt;/b&gt; man</h1>"
253 253 #
254 254 def initialize( string, restrictions = [] )
255 255 restrictions.each { |r| method( "#{ r }=" ).call( true ) }
256 256 super( string )
257 257 end
258 258
259 259 #
260 260 # Generates HTML from the Textile contents.
261 261 #
262 262 # r = RedCloth.new( "And then? She *fell*!" )
263 263 # r.to_html( true )
264 264 # #=>"And then? She <strong>fell</strong>!"
265 265 #
266 266 def to_html( *rules )
267 267 rules = DEFAULT_RULES if rules.empty?
268 268 # make our working copy
269 269 text = self.dup
270 270
271 271 @urlrefs = {}
272 272 @shelf = []
273 273 textile_rules = [:refs_textile, :block_textile_table, :block_textile_lists,
274 274 :block_textile_prefix, :inline_textile_image, :inline_textile_link,
275 275 :inline_textile_code, :inline_textile_span]
276 276 markdown_rules = [:refs_markdown, :block_markdown_setext, :block_markdown_atx, :block_markdown_rule,
277 277 :block_markdown_bq, :block_markdown_lists,
278 278 :inline_markdown_reflink, :inline_markdown_link]
279 279 @rules = rules.collect do |rule|
280 280 case rule
281 281 when :markdown
282 282 markdown_rules
283 283 when :textile
284 284 textile_rules
285 285 else
286 286 rule
287 287 end
288 288 end.flatten
289 289
290 290 # standard clean up
291 291 incoming_entities text
292 292 clean_white_space text
293 293
294 294 # start processor
295 295 @pre_list = []
296 296 rip_offtags text
297 297 no_textile text
298 298 escape_html_tags text
299 299 hard_break text
300 300 unless @lite_mode
301 301 refs text
302 302 blocks text
303 303 end
304 304 inline text
305 305 smooth_offtags text
306 306
307 307 retrieve text
308 308
309 309 text.gsub!( /<\/?notextile>/, '' )
310 310 text.gsub!( /x%x%/, '&#38;' )
311 311 clean_html text if filter_html
312 312 text.strip!
313 313 text
314 314
315 315 end
316 316
317 317 #######
318 318 private
319 319 #######
320 320 #
321 321 # Mapping of 8-bit ASCII codes to HTML numerical entity equivalents.
322 322 # (from PyTextile)
323 323 #
324 324 TEXTILE_TAGS =
325 325
326 326 [[128, 8364], [129, 0], [130, 8218], [131, 402], [132, 8222], [133, 8230],
327 327 [134, 8224], [135, 8225], [136, 710], [137, 8240], [138, 352], [139, 8249],
328 328 [140, 338], [141, 0], [142, 0], [143, 0], [144, 0], [145, 8216], [146, 8217],
329 329 [147, 8220], [148, 8221], [149, 8226], [150, 8211], [151, 8212], [152, 732],
330 330 [153, 8482], [154, 353], [155, 8250], [156, 339], [157, 0], [158, 0], [159, 376]].
331 331
332 332 collect! do |a, b|
333 333 [a.chr, ( b.zero? and "" or "&#{ b };" )]
334 334 end
335 335
336 336 #
337 337 # Regular expressions to convert to HTML.
338 338 #
339 339 A_HLGN = /(?:(?:<>|<|>|\=|[()]+)+)/
340 340 A_VLGN = /[\-^~]/
341 341 C_CLAS = '(?:\([^)]+\))'
342 342 C_LNGE = '(?:\[[^\]]+\])'
343 343 C_STYL = '(?:\{[^}]+\})'
344 344 S_CSPN = '(?:\\\\\d+)'
345 345 S_RSPN = '(?:/\d+)'
346 346 A = "(?:#{A_HLGN}?#{A_VLGN}?|#{A_VLGN}?#{A_HLGN}?)"
347 347 S = "(?:#{S_CSPN}?#{S_RSPN}|#{S_RSPN}?#{S_CSPN}?)"
348 348 C = "(?:#{C_CLAS}?#{C_STYL}?#{C_LNGE}?|#{C_STYL}?#{C_LNGE}?#{C_CLAS}?|#{C_LNGE}?#{C_STYL}?#{C_CLAS}?)"
349 349 # PUNCT = Regexp::quote( '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' )
350 350 PUNCT = Regexp::quote( '!"#$%&\'*+,-./:;=?@\\^_`|~' )
351 351 PUNCT_NOQ = Regexp::quote( '!"#$&\',./:;=?@\\`|' )
352 352 PUNCT_Q = Regexp::quote( '*-_+^~%' )
353 353 HYPERLINK = '(\S+?)([^\w\s/;=\?]*?)(?=\s|<|$)'
354 354
355 355 # Text markup tags, don't conflict with block tags
356 356 SIMPLE_HTML_TAGS = [
357 357 'tt', 'b', 'i', 'big', 'small', 'em', 'strong', 'dfn', 'code',
358 358 'samp', 'kbd', 'var', 'cite', 'abbr', 'acronym', 'a', 'img', 'br',
359 359 'br', 'map', 'q', 'sub', 'sup', 'span', 'bdo'
360 360 ]
361 361
362 362 QTAGS = [
363 363 ['**', 'b', :limit],
364 364 ['*', 'strong', :limit],
365 365 ['??', 'cite', :limit],
366 366 ['-', 'del', :limit],
367 367 ['__', 'i', :limit],
368 368 ['_', 'em', :limit],
369 369 ['%', 'span', :limit],
370 370 ['+', 'ins', :limit],
371 371 ['^', 'sup', :limit],
372 372 ['~', 'sub', :limit]
373 373 ]
374 374 QTAGS.collect! do |rc, ht, rtype|
375 375 rcq = Regexp::quote rc
376 376 re =
377 377 case rtype
378 378 when :limit
379 379 /(^|[>\s\(])
380 380 (#{rcq})
381 381 (#{C})
382 382 (?::(\S+?))?
383 383 ([^\s\-].*?[^\s\-]|\w)
384 384 #{rcq}
385 385 (?=[[:punct:]]|\s|\)|$)/x
386 386 else
387 387 /(#{rcq})
388 388 (#{C})
389 389 (?::(\S+))?
390 390 ([^\s\-].*?[^\s\-]|\w)
391 391 #{rcq}/xm
392 392 end
393 393 [rc, ht, re, rtype]
394 394 end
395 395
396 396 # Elements to handle
397 397 GLYPHS = [
398 398 # [ /([^\s\[{(>])?\'([dmst]\b|ll\b|ve\b|\s|:|$)/, '\1&#8217;\2' ], # single closing
399 399 # [ /([^\s\[{(>#{PUNCT_Q}][#{PUNCT_Q}]*)\'/, '\1&#8217;' ], # single closing
400 400 # [ /\'(?=[#{PUNCT_Q}]*(s\b|[\s#{PUNCT_NOQ}]))/, '&#8217;' ], # single closing
401 401 # [ /\'/, '&#8216;' ], # single opening
402 402 [ /</, '&lt;' ], # less-than
403 403 [ />/, '&gt;' ], # greater-than
404 404 # [ /([^\s\[{(])?"(\s|:|$)/, '\1&#8221;\2' ], # double closing
405 405 # [ /([^\s\[{(>#{PUNCT_Q}][#{PUNCT_Q}]*)"/, '\1&#8221;' ], # double closing
406 406 # [ /"(?=[#{PUNCT_Q}]*[\s#{PUNCT_NOQ}])/, '&#8221;' ], # double closing
407 407 # [ /"/, '&#8220;' ], # double opening
408 408 [ /\b( )?\.{3}/, '\1&#8230;' ], # ellipsis
409 409 [ /\b([A-Z][A-Z0-9]{2,})\b(?:[(]([^)]*)[)])/, '<acronym title="\2">\1</acronym>' ], # 3+ uppercase acronym
410 410 [ /(^|[^"][>\s])([A-Z][A-Z0-9 ]+[A-Z0-9])([^<A-Za-z0-9]|$)/, '\1<span class="caps">\2</span>\3', :no_span_caps ], # 3+ uppercase caps
411 411 [ /(\.\s)?\s?--\s?/, '\1&#8212;' ], # em dash
412 412 [ /\s->\s/, ' &rarr; ' ], # right arrow
413 413 [ /\s-\s/, ' &#8211; ' ], # en dash
414 414 [ /(\d+) ?x ?(\d+)/, '\1&#215;\2' ], # dimension sign
415 415 [ /\b ?[(\[]TM[\])]/i, '&#8482;' ], # trademark
416 416 [ /\b ?[(\[]R[\])]/i, '&#174;' ], # registered
417 417 [ /\b ?[(\[]C[\])]/i, '&#169;' ] # copyright
418 418 ]
419 419
420 420 H_ALGN_VALS = {
421 421 '<' => 'left',
422 422 '=' => 'center',
423 423 '>' => 'right',
424 424 '<>' => 'justify'
425 425 }
426 426
427 427 V_ALGN_VALS = {
428 428 '^' => 'top',
429 429 '-' => 'middle',
430 430 '~' => 'bottom'
431 431 }
432 432
433 433 #
434 434 # Flexible HTML escaping
435 435 #
436 436 def htmlesc( str, mode )
437 437 str.gsub!( '&', '&amp;' )
438 438 str.gsub!( '"', '&quot;' ) if mode != :NoQuotes
439 439 str.gsub!( "'", '&#039;' ) if mode == :Quotes
440 440 str.gsub!( '<', '&lt;')
441 441 str.gsub!( '>', '&gt;')
442 442 end
443 443
444 444 # Search and replace for Textile glyphs (quotes, dashes, other symbols)
445 445 def pgl( text )
446 446 GLYPHS.each do |re, resub, tog|
447 447 next if tog and method( tog ).call
448 448 text.gsub! re, resub
449 449 end
450 450 end
451 451
452 452 # Parses Textile attribute lists and builds an HTML attribute string
453 453 def pba( text_in, element = "" )
454 454
455 455 return '' unless text_in
456 456
457 457 style = []
458 458 text = text_in.dup
459 459 if element == 'td'
460 460 colspan = $1 if text =~ /\\(\d+)/
461 461 rowspan = $1 if text =~ /\/(\d+)/
462 462 style << "vertical-align:#{ v_align( $& ) };" if text =~ A_VLGN
463 463 end
464 464
465 465 style << "#{ $1 };" if not filter_styles and
466 466 text.sub!( /\{([^}]*)\}/, '' )
467 467
468 468 lang = $1 if
469 469 text.sub!( /\[([^)]+?)\]/, '' )
470 470
471 471 cls = $1 if
472 472 text.sub!( /\(([^()]+?)\)/, '' )
473 473
474 474 style << "padding-left:#{ $1.length }em;" if
475 475 text.sub!( /([(]+)/, '' )
476 476
477 477 style << "padding-right:#{ $1.length }em;" if text.sub!( /([)]+)/, '' )
478 478
479 479 style << "text-align:#{ h_align( $& ) };" if text =~ A_HLGN
480 480
481 481 cls, id = $1, $2 if cls =~ /^(.*?)#(.*)$/
482 482
483 483 atts = ''
484 484 atts << " style=\"#{ style.join }\"" unless style.empty?
485 485 atts << " class=\"#{ cls }\"" unless cls.to_s.empty?
486 486 atts << " lang=\"#{ lang }\"" if lang
487 487 atts << " id=\"#{ id }\"" if id
488 488 atts << " colspan=\"#{ colspan }\"" if colspan
489 489 atts << " rowspan=\"#{ rowspan }\"" if rowspan
490 490
491 491 atts
492 492 end
493 493
494 494 TABLE_RE = /^(?:table(_?#{S}#{A}#{C})\. ?\n)?^(#{A}#{C}\.? ?\|.*?\|)(\n\n|\Z)/m
495 495
496 496 # Parses a Textile table block, building HTML from the result.
497 497 def block_textile_table( text )
498 498 text.gsub!( TABLE_RE ) do |matches|
499 499
500 500 tatts, fullrow = $~[1..2]
501 501 tatts = pba( tatts, 'table' )
502 502 tatts = shelve( tatts ) if tatts
503 503 rows = []
504 504
505 505 fullrow.
506 506 split( /\|$/m ).
507 507 delete_if { |x| x.empty? }.
508 508 each do |row|
509 509
510 510 ratts, row = pba( $1, 'tr' ), $2 if row =~ /^(#{A}#{C}\. )(.*)/m
511 511
512 512 cells = []
513 513 #row.split( /\(?!\[\[[^\]])|(?![^\[]\]\])/ ).each do |cell|
514 514 row.split( /\|(?![^\[\|]*\]\])/ ).each do |cell|
515 515 ctyp = 'd'
516 516 ctyp = 'h' if cell =~ /^_/
517 517
518 518 catts = ''
519 519 catts, cell = pba( $1, 'td' ), $2 if cell =~ /^(_?#{S}#{A}#{C}\. ?)(.*)/
520 520
521 521 unless cell.strip.empty?
522 522 catts = shelve( catts ) if catts
523 523 cells << "\t\t\t<t#{ ctyp }#{ catts }>#{ cell }</t#{ ctyp }>"
524 524 end
525 525 end
526 526 ratts = shelve( ratts ) if ratts
527 527 rows << "\t\t<tr#{ ratts }>\n#{ cells.join( "\n" ) }\n\t\t</tr>"
528 528 end
529 529 "\t<table#{ tatts }>\n#{ rows.join( "\n" ) }\n\t</table>\n\n"
530 530 end
531 531 end
532 532
533 533 LISTS_RE = /^([#*]+?#{C} .*?)$(?![^#*])/m
534 534 LISTS_CONTENT_RE = /^([#*]+)(#{A}#{C}) (.*)$/m
535 535
536 536 # Parses Textile lists and generates HTML
537 537 def block_textile_lists( text )
538 538 text.gsub!( LISTS_RE ) do |match|
539 539 lines = match.split( /\n/ )
540 540 last_line = -1
541 541 depth = []
542 542 lines.each_with_index do |line, line_id|
543 543 if line =~ LISTS_CONTENT_RE
544 544 tl,atts,content = $~[1..3]
545 545 if depth.last
546 546 if depth.last.length > tl.length
547 547 (depth.length - 1).downto(0) do |i|
548 548 break if depth[i].length == tl.length
549 549 lines[line_id - 1] << "</li>\n\t</#{ lT( depth[i] ) }l>\n\t"
550 550 depth.pop
551 551 end
552 552 end
553 553 if depth.last and depth.last.length == tl.length
554 554 lines[line_id - 1] << '</li>'
555 555 end
556 556 end
557 557 unless depth.last == tl
558 558 depth << tl
559 559 atts = pba( atts )
560 560 atts = shelve( atts ) if atts
561 561 lines[line_id] = "\t<#{ lT(tl) }l#{ atts }>\n\t<li>#{ content }"
562 562 else
563 563 lines[line_id] = "\t\t<li>#{ content }"
564 564 end
565 565 last_line = line_id
566 566
567 567 else
568 568 last_line = line_id
569 569 end
570 570 if line_id - last_line > 1 or line_id == lines.length - 1
571 571 depth.delete_if do |v|
572 572 lines[last_line] << "</li>\n\t</#{ lT( v ) }l>"
573 573 end
574 574 end
575 575 end
576 576 lines.join( "\n" )
577 577 end
578 578 end
579 579
580 580 CODE_RE = /(\W)
581 581 @
582 582 (?:\|(\w+?)\|)?
583 583 (.+?)
584 584 @
585 585 (?=\W)/x
586 586
587 587 def inline_textile_code( text )
588 588 text.gsub!( CODE_RE ) do |m|
589 589 before,lang,code,after = $~[1..4]
590 590 lang = " lang=\"#{ lang }\"" if lang
591 591 rip_offtags( "#{ before }<code#{ lang }>#{ code }</code>#{ after }" )
592 592 end
593 593 end
594 594
595 595 def lT( text )
596 596 text =~ /\#$/ ? 'o' : 'u'
597 597 end
598 598
599 599 def hard_break( text )
600 600 text.gsub!( /(.)\n(?!\Z| *([#*=]+(\s|$)|[{|]))/, "\\1<br />" ) if hard_breaks
601 601 end
602 602
603 603 BLOCKS_GROUP_RE = /\n{2,}(?! )/m
604 604
605 605 def blocks( text, deep_code = false )
606 606 text.replace( text.split( BLOCKS_GROUP_RE ).collect do |blk|
607 607 plain = blk !~ /\A[#*> ]/
608 608
609 609 # skip blocks that are complex HTML
610 610 if blk =~ /^<\/?(\w+).*>/ and not SIMPLE_HTML_TAGS.include? $1
611 611 blk
612 612 else
613 613 # search for indentation levels
614 614 blk.strip!
615 615 if blk.empty?
616 616 blk
617 617 else
618 618 code_blk = nil
619 619 blk.gsub!( /((?:\n(?:\n^ +[^\n]*)+)+)/m ) do |iblk|
620 620 flush_left iblk
621 621 blocks iblk, plain
622 622 iblk.gsub( /^(\S)/, "\t\\1" )
623 623 if plain
624 624 code_blk = iblk; ""
625 625 else
626 626 iblk
627 627 end
628 628 end
629 629
630 630 block_applied = 0
631 631 @rules.each do |rule_name|
632 632 block_applied += 1 if ( rule_name.to_s.match /^block_/ and method( rule_name ).call( blk ) )
633 633 end
634 634 if block_applied.zero?
635 635 if deep_code
636 636 blk = "\t<pre><code>#{ blk }</code></pre>"
637 637 else
638 638 blk = "\t<p>#{ blk }</p>"
639 639 end
640 640 end
641 641 # hard_break blk
642 642 blk + "\n#{ code_blk }"
643 643 end
644 644 end
645 645
646 646 end.join( "\n\n" ) )
647 647 end
648 648
649 649 def textile_bq( tag, atts, cite, content )
650 650 cite, cite_title = check_refs( cite )
651 651 cite = " cite=\"#{ cite }\"" if cite
652 652 atts = shelve( atts ) if atts
653 653 "\t<blockquote#{ cite }>\n\t\t<p#{ atts }>#{ content }</p>\n\t</blockquote>"
654 654 end
655 655
656 656 def textile_p( tag, atts, cite, content )
657 657 atts = shelve( atts ) if atts
658 658 "\t<#{ tag }#{ atts }>#{ content }</#{ tag }>"
659 659 end
660 660
661 661 alias textile_h1 textile_p
662 662 alias textile_h2 textile_p
663 663 alias textile_h3 textile_p
664 664 alias textile_h4 textile_p
665 665 alias textile_h5 textile_p
666 666 alias textile_h6 textile_p
667 667
668 668 def textile_fn_( tag, num, atts, cite, content )
669 669 atts << " id=\"fn#{ num }\""
670 670 content = "<sup>#{ num }</sup> #{ content }"
671 671 atts = shelve( atts ) if atts
672 672 "\t<p#{ atts }>#{ content }</p>"
673 673 end
674 674
675 675 BLOCK_RE = /^(([a-z]+)(\d*))(#{A}#{C})\.(?::(\S+))? (.*)$/m
676 676
677 677 def block_textile_prefix( text )
678 678 if text =~ BLOCK_RE
679 679 tag,tagpre,num,atts,cite,content = $~[1..6]
680 680 atts = pba( atts )
681 681
682 682 # pass to prefix handler
683 683 if respond_to? "textile_#{ tag }", true
684 684 text.gsub!( $&, method( "textile_#{ tag }" ).call( tag, atts, cite, content ) )
685 685 elsif respond_to? "textile_#{ tagpre }_", true
686 686 text.gsub!( $&, method( "textile_#{ tagpre }_" ).call( tagpre, num, atts, cite, content ) )
687 687 end
688 688 end
689 689 end
690 690
691 691 SETEXT_RE = /\A(.+?)\n([=-])[=-]* *$/m
692 692 def block_markdown_setext( text )
693 693 if text =~ SETEXT_RE
694 694 tag = if $2 == "="; "h1"; else; "h2"; end
695 695 blk, cont = "<#{ tag }>#{ $1 }</#{ tag }>", $'
696 696 blocks cont
697 697 text.replace( blk + cont )
698 698 end
699 699 end
700 700
701 701 ATX_RE = /\A(\#{1,6}) # $1 = string of #'s
702 702 [ ]*
703 703 (.+?) # $2 = Header text
704 704 [ ]*
705 705 \#* # optional closing #'s (not counted)
706 706 $/x
707 707 def block_markdown_atx( text )
708 708 if text =~ ATX_RE
709 709 tag = "h#{ $1.length }"
710 710 blk, cont = "<#{ tag }>#{ $2 }</#{ tag }>\n\n", $'
711 711 blocks cont
712 712 text.replace( blk + cont )
713 713 end
714 714 end
715 715
716 716 MARKDOWN_BQ_RE = /\A(^ *> ?.+$(.+\n)*\n*)+/m
717 717
718 718 def block_markdown_bq( text )
719 719 text.gsub!( MARKDOWN_BQ_RE ) do |blk|
720 720 blk.gsub!( /^ *> ?/, '' )
721 721 flush_left blk
722 722 blocks blk
723 723 blk.gsub!( /^(\S)/, "\t\\1" )
724 724 "<blockquote>\n#{ blk }\n</blockquote>\n\n"
725 725 end
726 726 end
727 727
728 728 MARKDOWN_RULE_RE = /^(#{
729 729 ['*', '-', '_'].collect { |ch| '( ?' + Regexp::quote( ch ) + ' ?){3,}' }.join( '|' )
730 730 })$/
731 731
732 732 def block_markdown_rule( text )
733 733 text.gsub!( MARKDOWN_RULE_RE ) do |blk|
734 734 "<hr />"
735 735 end
736 736 end
737 737
738 738 # XXX TODO XXX
739 739 def block_markdown_lists( text )
740 740 end
741 741
742 742 def inline_textile_span( text )
743 743 QTAGS.each do |qtag_rc, ht, qtag_re, rtype|
744 744 text.gsub!( qtag_re ) do |m|
745 745
746 746 case rtype
747 747 when :limit
748 748 sta,qtag,atts,cite,content = $~[1..5]
749 749 else
750 750 qtag,atts,cite,content = $~[1..4]
751 751 sta = ''
752 752 end
753 753 atts = pba( atts )
754 754 atts << " cite=\"#{ cite }\"" if cite
755 755 atts = shelve( atts ) if atts
756 756
757 757 "#{ sta }<#{ ht }#{ atts }>#{ content }</#{ ht }>"
758 758
759 759 end
760 760 end
761 761 end
762 762
763 763 LINK_RE = /
764 764 ([\s\[{(]|[#{PUNCT}])? # $pre
765 765 " # start
766 766 (#{C}) # $atts
767 767 ([^"\n]+?) # $text
768 768 \s?
769 769 (?:\(([^)]+?)\)(?="))? # $title
770 770 ":
771 771 (\S+?) # $url
772 772 (\/)? # $slash
773 773 ([^\w\/;]*?) # $post
774 774 (?=<|\s|$)
775 775 /x
776 776
777 777 def inline_textile_link( text )
778 778 text.gsub!( LINK_RE ) do |m|
779 779 pre,atts,text,title,url,slash,post = $~[1..7]
780 780
781 781 url, url_title = check_refs( url )
782 782 title ||= url_title
783 783
784 784 atts = pba( atts )
785 785 atts = " href=\"#{ url }#{ slash }\"#{ atts }"
786 786 atts << " title=\"#{ title }\"" if title
787 787 atts = shelve( atts ) if atts
788 788
789 789 external = (url =~ /^https?:\/\//) ? ' class="external"' : ''
790 790
791 791 "#{ pre }<a#{ atts }#{ external }>#{ text }</a>#{ post }"
792 792 end
793 793 end
794 794
795 795 MARKDOWN_REFLINK_RE = /
796 796 \[([^\[\]]+)\] # $text
797 797 [ ]? # opt. space
798 798 (?:\n[ ]*)? # one optional newline followed by spaces
799 799 \[(.*?)\] # $id
800 800 /x
801 801
802 802 def inline_markdown_reflink( text )
803 803 text.gsub!( MARKDOWN_REFLINK_RE ) do |m|
804 804 text, id = $~[1..2]
805 805
806 806 if id.empty?
807 807 url, title = check_refs( text )
808 808 else
809 809 url, title = check_refs( id )
810 810 end
811 811
812 812 atts = " href=\"#{ url }\""
813 813 atts << " title=\"#{ title }\"" if title
814 814 atts = shelve( atts )
815 815
816 816 "<a#{ atts }>#{ text }</a>"
817 817 end
818 818 end
819 819
820 820 MARKDOWN_LINK_RE = /
821 821 \[([^\[\]]+)\] # $text
822 822 \( # open paren
823 823 [ \t]* # opt space
824 824 <?(.+?)>? # $href
825 825 [ \t]* # opt space
826 826 (?: # whole title
827 827 (['"]) # $quote
828 828 (.*?) # $title
829 829 \3 # matching quote
830 830 )? # title is optional
831 831 \)
832 832 /x
833 833
834 834 def inline_markdown_link( text )
835 835 text.gsub!( MARKDOWN_LINK_RE ) do |m|
836 836 text, url, quote, title = $~[1..4]
837 837
838 838 atts = " href=\"#{ url }\""
839 839 atts << " title=\"#{ title }\"" if title
840 840 atts = shelve( atts )
841 841
842 842 "<a#{ atts }>#{ text }</a>"
843 843 end
844 844 end
845 845
846 846 TEXTILE_REFS_RE = /(^ *)\[([^\[\n]+?)\](#{HYPERLINK})(?=\s|$)/
847 847 MARKDOWN_REFS_RE = /(^ *)\[([^\n]+?)\]:\s+<?(#{HYPERLINK})>?(?:\s+"((?:[^"]|\\")+)")?(?=\s|$)/m
848 848
849 849 def refs( text )
850 850 @rules.each do |rule_name|
851 851 method( rule_name ).call( text ) if rule_name.to_s.match /^refs_/
852 852 end
853 853 end
854 854
855 855 def refs_textile( text )
856 856 text.gsub!( TEXTILE_REFS_RE ) do |m|
857 857 flag, url = $~[2..3]
858 858 @urlrefs[flag.downcase] = [url, nil]
859 859 nil
860 860 end
861 861 end
862 862
863 863 def refs_markdown( text )
864 864 text.gsub!( MARKDOWN_REFS_RE ) do |m|
865 865 flag, url = $~[2..3]
866 866 title = $~[6]
867 867 @urlrefs[flag.downcase] = [url, title]
868 868 nil
869 869 end
870 870 end
871 871
872 872 def check_refs( text )
873 873 ret = @urlrefs[text.downcase] if text
874 874 ret || [text, nil]
875 875 end
876 876
877 877 IMAGE_RE = /
878 878 (<p>|.|^) # start of line?
879 879 \! # opening
880 880 (\<|\=|\>)? # optional alignment atts
881 881 (#{C}) # optional style,class atts
882 882 (?:\. )? # optional dot-space
883 883 ([^\s(!]+?) # presume this is the src
884 884 \s? # optional space
885 885 (?:\(((?:[^\(\)]|\([^\)]+\))+?)\))? # optional title
886 886 \! # closing
887 887 (?::#{ HYPERLINK })? # optional href
888 888 /x
889 889
890 890 def inline_textile_image( text )
891 891 text.gsub!( IMAGE_RE ) do |m|
892 892 stln,algn,atts,url,title,href,href_a1,href_a2 = $~[1..8]
893 893 atts = pba( atts )
894 894 atts = " src=\"#{ url }\"#{ atts }"
895 895 atts << " title=\"#{ title }\"" if title
896 896 atts << " alt=\"#{ title }\""
897 897 # size = @getimagesize($url);
898 898 # if($size) $atts.= " $size[3]";
899 899
900 900 href, alt_title = check_refs( href ) if href
901 901 url, url_title = check_refs( url )
902 902
903 903 out = ''
904 904 out << "<a#{ shelve( " href=\"#{ href }\"" ) }>" if href
905 905 out << "<img#{ shelve( atts ) } />"
906 906 out << "</a>#{ href_a1 }#{ href_a2 }" if href
907 907
908 908 if algn
909 909 algn = h_align( algn )
910 910 if stln == "<p>"
911 911 out = "<p style=\"float:#{ algn }\">#{ out }"
912 912 else
913 913 out = "#{ stln }<div style=\"float:#{ algn }\">#{ out }</div>"
914 914 end
915 915 else
916 916 out = stln + out
917 917 end
918 918
919 919 out
920 920 end
921 921 end
922 922
923 923 def shelve( val )
924 924 @shelf << val
925 925 " :redsh##{ @shelf.length }:"
926 926 end
927 927
928 928 def retrieve( text )
929 929 @shelf.each_with_index do |r, i|
930 930 text.gsub!( " :redsh##{ i + 1 }:", r )
931 931 end
932 932 end
933 933
934 934 def incoming_entities( text )
935 935 ## turn any incoming ampersands into a dummy character for now.
936 936 ## This uses a negative lookahead for alphanumerics followed by a semicolon,
937 937 ## implying an incoming html entity, to be skipped
938 938
939 939 text.gsub!( /&(?![#a-z0-9]+;)/i, "x%x%" )
940 940 end
941 941
942 942 def no_textile( text )
943 943 text.gsub!( /(^|\s)==([^=]+.*?)==(\s|$)?/,
944 944 '\1<notextile>\2</notextile>\3' )
945 945 text.gsub!( /^ *==([^=]+.*?)==/m,
946 946 '\1<notextile>\2</notextile>\3' )
947 947 end
948 948
949 949 def clean_white_space( text )
950 950 # normalize line breaks
951 951 text.gsub!( /\r\n/, "\n" )
952 952 text.gsub!( /\r/, "\n" )
953 953 text.gsub!( /\t/, ' ' )
954 954 text.gsub!( /^ +$/, '' )
955 955 text.gsub!( /\n{3,}/, "\n\n" )
956 956 text.gsub!( /"$/, "\" " )
957 957
958 958 # if entire document is indented, flush
959 959 # to the left side
960 960 flush_left text
961 961 end
962 962
963 963 def flush_left( text )
964 964 indt = 0
965 965 if text =~ /^ /
966 966 while text !~ /^ {#{indt}}\S/
967 967 indt += 1
968 968 end unless text.empty?
969 969 if indt.nonzero?
970 970 text.gsub!( /^ {#{indt}}/, '' )
971 971 end
972 972 end
973 973 end
974 974
975 975 def footnote_ref( text )
976 976 text.gsub!( /\b\[([0-9]+?)\](\s)?/,
977 977 '<sup><a href="#fn\1">\1</a></sup>\2' )
978 978 end
979 979
980 980 OFFTAGS = /(code|pre|kbd|notextile)/
981 981 OFFTAG_MATCH = /(?:(<\/#{ OFFTAGS }>)|(<#{ OFFTAGS }[^>]*>))(.*?)(?=<\/?#{ OFFTAGS }|\Z)/mi
982 982 OFFTAG_OPEN = /<#{ OFFTAGS }/
983 983 OFFTAG_CLOSE = /<\/?#{ OFFTAGS }/
984 984 HASTAG_MATCH = /(<\/?\w[^\n]*?>)/m
985 985 ALLTAG_MATCH = /(<\/?\w[^\n]*?>)|.*?(?=<\/?\w[^\n]*?>|$)/m
986 986
987 987 def glyphs_textile( text, level = 0 )
988 988 if text !~ HASTAG_MATCH
989 989 pgl text
990 990 footnote_ref text
991 991 else
992 992 codepre = 0
993 993 text.gsub!( ALLTAG_MATCH ) do |line|
994 994 ## matches are off if we're between <code>, <pre> etc.
995 995 if $1
996 996 if line =~ OFFTAG_OPEN
997 997 codepre += 1
998 998 elsif line =~ OFFTAG_CLOSE
999 999 codepre -= 1
1000 1000 codepre = 0 if codepre < 0
1001 1001 end
1002 1002 elsif codepre.zero?
1003 1003 glyphs_textile( line, level + 1 )
1004 1004 else
1005 1005 htmlesc( line, :NoQuotes )
1006 1006 end
1007 1007 # p [level, codepre, line]
1008 1008
1009 1009 line
1010 1010 end
1011 1011 end
1012 1012 end
1013 1013
1014 1014 def rip_offtags( text )
1015 1015 if text =~ /<.*>/
1016 1016 ## strip and encode <pre> content
1017 1017 codepre, used_offtags = 0, {}
1018 1018 text.gsub!( OFFTAG_MATCH ) do |line|
1019 1019 if $3
1020 1020 offtag, aftertag = $4, $5
1021 1021 codepre += 1
1022 1022 used_offtags[offtag] = true
1023 1023 if codepre - used_offtags.length > 0
1024 1024 htmlesc( line, :NoQuotes ) unless used_offtags['notextile']
1025 1025 @pre_list.last << line
1026 1026 line = ""
1027 1027 else
1028 1028 htmlesc( aftertag, :NoQuotes ) if aftertag and not used_offtags['notextile']
1029 1029 line = "<redpre##{ @pre_list.length }>"
1030 1030 @pre_list << "#{ $3 }#{ aftertag }"
1031 1031 end
1032 1032 elsif $1 and codepre > 0
1033 1033 if codepre - used_offtags.length > 0
1034 1034 htmlesc( line, :NoQuotes ) unless used_offtags['notextile']
1035 1035 @pre_list.last << line
1036 1036 line = ""
1037 1037 end
1038 1038 codepre -= 1 unless codepre.zero?
1039 1039 used_offtags = {} if codepre.zero?
1040 1040 end
1041 1041 line
1042 1042 end
1043 1043 end
1044 1044 text
1045 1045 end
1046 1046
1047 1047 def smooth_offtags( text )
1048 1048 unless @pre_list.empty?
1049 1049 ## replace <pre> content
1050 1050 text.gsub!( /<redpre#(\d+)>/ ) { @pre_list[$1.to_i] }
1051 1051 end
1052 1052 end
1053 1053
1054 1054 def inline( text )
1055 1055 [/^inline_/, /^glyphs_/].each do |meth_re|
1056 1056 @rules.each do |rule_name|
1057 1057 method( rule_name ).call( text ) if rule_name.to_s.match( meth_re )
1058 1058 end
1059 1059 end
1060 1060 end
1061 1061
1062 1062 def h_align( text )
1063 1063 H_ALGN_VALS[text]
1064 1064 end
1065 1065
1066 1066 def v_align( text )
1067 1067 V_ALGN_VALS[text]
1068 1068 end
1069 1069
1070 1070 def textile_popup_help( name, windowW, windowH )
1071 1071 ' <a target="_blank" href="http://hobix.com/textile/#' + helpvar + '" onclick="window.open(this.href, \'popupwindow\', \'width=' + windowW + ',height=' + windowH + ',scrollbars,resizable\'); return false;">' + name + '</a><br />'
1072 1072 end
1073 1073
1074 1074 # HTML cleansing stuff
1075 1075 BASIC_TAGS = {
1076 1076 'a' => ['href', 'title'],
1077 1077 'img' => ['src', 'alt', 'title'],
1078 1078 'br' => [],
1079 1079 'i' => nil,
1080 1080 'u' => nil,
1081 1081 'b' => nil,
1082 1082 'pre' => nil,
1083 1083 'kbd' => nil,
1084 1084 'code' => ['lang'],
1085 1085 'cite' => nil,
1086 1086 'strong' => nil,
1087 1087 'em' => nil,
1088 1088 'ins' => nil,
1089 1089 'sup' => nil,
1090 1090 'sub' => nil,
1091 1091 'del' => nil,
1092 1092 'table' => nil,
1093 1093 'tr' => nil,
1094 1094 'td' => ['colspan', 'rowspan'],
1095 1095 'th' => nil,
1096 1096 'ol' => nil,
1097 1097 'ul' => nil,
1098 1098 'li' => nil,
1099 1099 'p' => nil,
1100 1100 'h1' => nil,
1101 1101 'h2' => nil,
1102 1102 'h3' => nil,
1103 1103 'h4' => nil,
1104 1104 'h5' => nil,
1105 1105 'h6' => nil,
1106 1106 'blockquote' => ['cite']
1107 1107 }
1108 1108
1109 1109 def clean_html( text, tags = BASIC_TAGS )
1110 1110 text.gsub!( /<!\[CDATA\[/, '' )
1111 1111 text.gsub!( /<(\/*)(\w+)([^>]*)>/ ) do
1112 1112 raw = $~
1113 1113 tag = raw[2].downcase
1114 1114 if tags.has_key? tag
1115 1115 pcs = [tag]
1116 1116 tags[tag].each do |prop|
1117 1117 ['"', "'", ''].each do |q|
1118 1118 q2 = ( q != '' ? q : '\s' )
1119 1119 if raw[3] =~ /#{prop}\s*=\s*#{q}([^#{q2}]+)#{q}/i
1120 1120 attrv = $1
1121 1121 next if prop == 'src' and attrv =~ %r{^(?!http)\w+:}
1122 1122 pcs << "#{prop}=\"#{$1.gsub('"', '\\"')}\""
1123 1123 break
1124 1124 end
1125 1125 end
1126 1126 end if tags[tag]
1127 1127 "<#{raw[1]}#{pcs.join " "}>"
1128 1128 else
1129 1129 " "
1130 1130 end
1131 1131 end
1132 1132 end
1133 1133
1134 ALLOWED_TAGS = %w(redpre pre code)
1134 ALLOWED_TAGS = %w(redpre pre code notextile)
1135 1135
1136 1136 def escape_html_tags(text)
1137 1137 text.gsub!(%r{<(\/?([!\w]+)[^<>\n]*)(>?)}) {|m| ALLOWED_TAGS.include?($2) ? "<#{$1}#{$3}" : "&lt;#{$1}#{'&gt;' unless $3.blank?}" }
1138 1138 end
1139 1139 end
1140 1140
@@ -1,598 +1,598
1 1 body { font-family: Verdana, sans-serif; font-size: 12px; color:#484848; margin: 0; padding: 0; min-width: 900px; }
2 2
3 3 h1, h2, h3, h4 { font-family: "Trebuchet MS", Verdana, sans-serif;}
4 4 h1 {margin:0; padding:0; font-size: 24px;}
5 5 h2, .wiki h1 {font-size: 20px;padding: 2px 10px 1px 0px;margin: 0 0 10px 0; border-bottom: 1px solid #bbbbbb; color: #444;}
6 6 h3, .wiki h2 {font-size: 16px;padding: 2px 10px 1px 0px;margin: 0 0 10px 0; border-bottom: 1px solid #bbbbbb; color: #444;}
7 7 h4, .wiki h3 {font-size: 13px;padding: 2px 10px 1px 0px;margin-bottom: 5px; border-bottom: 1px dotted #bbbbbb; color: #444;}
8 8
9 9 /***** Layout *****/
10 10 #wrapper {background: white;}
11 11
12 12 #top-menu {background: #2C4056; color: #fff; height:1.8em; font-size: 0.8em; padding: 2px 2px 0px 6px;}
13 13 #top-menu ul {margin: 0; padding: 0;}
14 14 #top-menu li {
15 15 float:left;
16 16 list-style-type:none;
17 17 margin: 0px 0px 0px 0px;
18 18 padding: 0px 0px 0px 0px;
19 19 white-space:nowrap;
20 20 }
21 21 #top-menu a {color: #fff; padding-right: 8px; font-weight: bold;}
22 22 #top-menu #loggedas { float: right; margin-right: 0.5em; color: #fff; }
23 23
24 24 #account {float:right;}
25 25
26 26 #header {height:5.3em;margin:0;background-color:#507AAA;color:#f8f8f8; padding: 4px 8px 0px 6px; position:relative;}
27 27 #header a {color:#f8f8f8;}
28 28 #quick-search {float:right;}
29 29
30 30 #main-menu {position: absolute; bottom: 0px; left:6px; margin-right: -500px;}
31 31 #main-menu ul {margin: 0; padding: 0;}
32 32 #main-menu li {
33 33 float:left;
34 34 list-style-type:none;
35 35 margin: 0px 2px 0px 0px;
36 36 padding: 0px 0px 0px 0px;
37 37 white-space:nowrap;
38 38 }
39 39 #main-menu li a {
40 40 display: block;
41 41 color: #fff;
42 42 text-decoration: none;
43 43 font-weight: bold;
44 44 margin: 0;
45 45 padding: 4px 10px 4px 10px;
46 46 }
47 47 #main-menu li a:hover {background:#759FCF; color:#fff;}
48 48 #main-menu li a.selected, #main-menu li a.selected:hover {background:#fff; color:#555;}
49 49
50 50 #main {background-color:#EEEEEE;}
51 51
52 52 #sidebar{ float: right; width: 17%; position: relative; z-index: 9; min-height: 600px; padding: 0; margin: 0;}
53 53 * html #sidebar{ width: 17%; }
54 54 #sidebar h3{ font-size: 14px; margin-top:14px; color: #666; }
55 55 #sidebar hr{ width: 100%; margin: 0 auto; height: 1px; background: #ccc; border: 0; }
56 56 * html #sidebar hr{ width: 95%; position: relative; left: -6px; color: #ccc; }
57 57
58 58 #content { width: 80%; background-color: #fff; margin: 0px; border-right: 1px solid #ddd; padding: 6px 10px 10px 10px; z-index: 10; height:600px; min-height: 600px;}
59 59 * html #content{ width: 80%; padding-left: 0; margin-top: 0px; padding: 6px 10px 10px 10px;}
60 60 html>body #content { height: auto; min-height: 600px; overflow: auto; }
61 61
62 62 #main.nosidebar #sidebar{ display: none; }
63 63 #main.nosidebar #content{ width: auto; border-right: 0; }
64 64
65 65 #footer {clear: both; border-top: 1px solid #bbb; font-size: 0.9em; color: #aaa; padding: 5px; text-align:center; background:#fff;}
66 66
67 67 #login-form table {margin-top:5em; padding:1em; margin-left: auto; margin-right: auto; border: 2px solid #FDBF3B; background-color:#FFEBC1; }
68 68 #login-form table td {padding: 6px;}
69 69 #login-form label {font-weight: bold;}
70 70
71 71 .clear:after{ content: "."; display: block; height: 0; clear: both; visibility: hidden; }
72 72
73 73 /***** Links *****/
74 74 a, a:link, a:visited{ color: #2A5685; text-decoration: none; }
75 75 a:hover, a:active{ color: #c61a1a; text-decoration: underline;}
76 76 a img{ border: 0; }
77 77
78 78 a.issue.closed, .issue.closed a { text-decoration: line-through; }
79 79
80 80 /***** Tables *****/
81 81 table.list { border: 1px solid #e4e4e4; border-collapse: collapse; width: 100%; margin-bottom: 4px; }
82 82 table.list th { background-color:#EEEEEE; padding: 4px; white-space:nowrap; }
83 83 table.list td { vertical-align: top; }
84 84 table.list td.id { width: 2%; text-align: center;}
85 85 table.list td.checkbox { width: 15px; padding: 0px;}
86 86
87 87 table.list.issues { margin-top: 10px; }
88 88 tr.issue { text-align: center; white-space: nowrap; }
89 89 tr.issue td.subject, tr.issue td.category { white-space: normal; }
90 90 tr.issue td.subject { text-align: left; }
91 91 tr.issue td.done_ratio table.progress { margin-left:auto; margin-right: auto;}
92 92
93 93 tr.entry { border: 1px solid #f8f8f8; }
94 94 tr.entry td { white-space: nowrap; }
95 95 tr.entry td.filename { width: 30%; }
96 96 tr.entry td.size { text-align: right; font-size: 90%; }
97 97 tr.entry td.revision, tr.entry td.author { text-align: center; }
98 98 tr.entry td.age { text-align: right; }
99 99
100 100 tr.changeset td.author { text-align: center; width: 15%; }
101 101 tr.changeset td.committed_on { text-align: center; width: 15%; }
102 102
103 103 tr.message { height: 2.6em; }
104 104 tr.message td.last_message { font-size: 80%; }
105 105 tr.message.locked td.subject a { background-image: url(../images/locked.png); }
106 106 tr.message.sticky td.subject a { background-image: url(../images/sticky.png); font-weight: bold; }
107 107
108 108 tr.user td { width:13%; }
109 109 tr.user td.email { width:18%; }
110 110 tr.user td { white-space: nowrap; }
111 111 tr.user.locked, tr.user.registered { color: #aaa; }
112 112 tr.user.locked a, tr.user.registered a { color: #aaa; }
113 113
114 114 tr.time-entry { text-align: center; white-space: nowrap; }
115 115 tr.time-entry td.subject, tr.time-entry td.comments { text-align: left; white-space: normal; }
116 116 td.hours { text-align: right; font-weight: bold; padding-right: 0.5em; }
117 117 td.hours .hours-dec { font-size: 0.9em; }
118 118
119 119 table.list tbody tr:hover { background-color:#ffffdd; }
120 120 table td {padding:2px;}
121 121 table p {margin:0;}
122 122 .odd {background-color:#f6f7f8;}
123 123 .even {background-color: #fff;}
124 124
125 125 .highlight { background-color: #FCFD8D;}
126 126 .highlight.token-1 { background-color: #faa;}
127 127 .highlight.token-2 { background-color: #afa;}
128 128 .highlight.token-3 { background-color: #aaf;}
129 129
130 130 .box{
131 131 padding:6px;
132 132 margin-bottom: 10px;
133 133 background-color:#f6f6f6;
134 134 color:#505050;
135 135 line-height:1.5em;
136 136 border: 1px solid #e4e4e4;
137 137 }
138 138
139 139 div.square {
140 140 border: 1px solid #999;
141 141 float: left;
142 142 margin: .3em .4em 0 .4em;
143 143 overflow: hidden;
144 144 width: .6em; height: .6em;
145 145 }
146 146 .contextual {float:right; white-space: nowrap; line-height:1.4em;margin-top:5px; padding-left: 10px; font-size:0.9em;}
147 147 .contextual input {font-size:0.9em;}
148 148
149 149 .splitcontentleft{float:left; width:49%;}
150 150 .splitcontentright{float:right; width:49%;}
151 151 form {display: inline;}
152 152 input, select {vertical-align: middle; margin-top: 1px; margin-bottom: 1px;}
153 153 fieldset {border: 1px solid #e4e4e4; margin:0;}
154 154 legend {color: #484848;}
155 155 hr { width: 100%; height: 1px; background: #ccc; border: 0;}
156 156 textarea.wiki-edit { width: 99%; }
157 157 li p {margin-top: 0;}
158 158 div.issue {background:#ffffdd; padding:6px; margin-bottom:6px;border: 1px solid #d7d7d7;}
159 159 p.breadcrumb { font-size: 0.9em; margin: 4px 0 4px 0;}
160 160 p.subtitle { font-size: 0.9em; margin: -6px 0 12px 0; font-style: italic; }
161 161
162 162 fieldset#filters { padding: 0.7em; }
163 163 fieldset#filters p { margin: 1.2em 0 0.8em 2px; }
164 164 fieldset#filters .buttons { font-size: 0.9em; }
165 165 fieldset#filters table { border-collapse: collapse; }
166 166 fieldset#filters table td { padding: 0; vertical-align: middle; }
167 167 fieldset#filters tr.filter { height: 2em; }
168 168 fieldset#filters td.add-filter { text-align: right; vertical-align: top; }
169 169
170 170 div#issue-changesets {float:right; width:45%; margin-left: 1em; margin-bottom: 1em; background: #fff; padding-left: 1em; font-size: 90%;}
171 171 div#issue-changesets .changeset { padding: 4px;}
172 172 div#issue-changesets .changeset { border-bottom: 1px solid #ddd; }
173 173 div#issue-changesets p { margin-top: 0; margin-bottom: 1em;}
174 174
175 175 div#activity dl { margin-left: 2em; }
176 176 div#activity dd { margin-bottom: 1em; padding-left: 18px; }
177 177 div#activity dt { margin-bottom: 1px; padding-left: 20px; line-height: 18px; background-position: 0 50%; background-repeat: no-repeat; }
178 178 div#activity dt .time { color: #777; font-size: 80%; }
179 179 div#activity dd .description { font-style: italic; }
180 180 div#activity span.project:after { content: " -"; }
181 181 div#activity dt.issue { background-image: url(../images/ticket.png); }
182 182 div#activity dt.issue-edit { background-image: url(../images/ticket_edit.png); }
183 183 div#activity dt.issue-closed { background-image: url(../images/ticket_checked.png); }
184 184 div#activity dt.changeset { background-image: url(../images/changeset.png); }
185 185 div#activity dt.news { background-image: url(../images/news.png); }
186 186 div#activity dt.message { background-image: url(../images/message.png); }
187 187 div#activity dt.reply { background-image: url(../images/comments.png); }
188 188 div#activity dt.wiki-page { background-image: url(../images/wiki_edit.png); }
189 189 div#activity dt.attachment { background-image: url(../images/attachment.png); }
190 190 div#activity dt.document { background-image: url(../images/document.png); }
191 191
192 192 div#roadmap fieldset.related-issues { margin-bottom: 1em; }
193 193 div#roadmap fieldset.related-issues ul { margin-top: 0.3em; margin-bottom: 0.3em; }
194 194 div#roadmap .wiki h1:first-child { display: none; }
195 195 div#roadmap .wiki h1 { font-size: 120%; }
196 196 div#roadmap .wiki h2 { font-size: 110%; }
197 197
198 198 div#version-summary { float:right; width:380px; margin-left: 16px; margin-bottom: 16px; background-color: #fff; }
199 199 div#version-summary fieldset { margin-bottom: 1em; }
200 200 div#version-summary .total-hours { text-align: right; }
201 201
202 202 table#time-report td.hours, table#time-report th.period, table#time-report th.total { text-align: right; padding-right: 0.5em; }
203 203 table#time-report tbody tr { font-style: italic; color: #777; }
204 204 table#time-report tbody tr.last-level { font-style: normal; color: #555; }
205 205 table#time-report tbody tr.total { font-style: normal; font-weight: bold; color: #555; background-color:#EEEEEE; }
206 206 table#time-report .hours-dec { font-size: 0.9em; }
207 207
208 208 .total-hours { font-size: 110%; font-weight: bold; }
209 209 .total-hours span.hours-int { font-size: 120%; }
210 210
211 211 .autoscroll {overflow-x: auto; padding:1px; margin-bottom: 1.2em;}
212 212 #user_firstname, #user_lastname, #user_mail, #my_account_form select { width: 90%; }
213 213
214 214 .pagination {font-size: 90%}
215 215 p.pagination {margin-top:8px;}
216 216
217 217 /***** Tabular forms ******/
218 218 .tabular p{
219 219 margin: 0;
220 220 padding: 5px 0 8px 0;
221 221 padding-left: 180px; /*width of left column containing the label elements*/
222 222 height: 1%;
223 223 clear:left;
224 224 }
225 225
226 html>body .tabular p {overflow:auto;}
226 html>body .tabular p {overflow:hidden;}
227 227
228 228 .tabular label{
229 229 font-weight: bold;
230 230 float: left;
231 231 text-align: right;
232 232 margin-left: -180px; /*width of left column*/
233 233 width: 175px; /*width of labels. Should be smaller than left column to create some right
234 234 margin*/
235 235 }
236 236
237 237 .tabular label.floating{
238 238 font-weight: normal;
239 239 margin-left: 0px;
240 240 text-align: left;
241 241 width: 200px;
242 242 }
243 243
244 244 input#time_entry_comments { width: 90%;}
245 245
246 246 #preview fieldset {margin-top: 1em; background: url(../images/draft.png)}
247 247
248 248 .tabular.settings p{ padding-left: 300px; }
249 249 .tabular.settings label{ margin-left: -300px; width: 295px; }
250 250
251 251 .required {color: #bb0000;}
252 252 .summary {font-style: italic;}
253 253
254 254 #attachments_fields input[type=text] {margin-left: 8px; }
255 255
256 256 div.attachments p { margin:4px 0 2px 0; }
257 257 div.attachments img { vertical-align: middle; }
258 258 div.attachments span.author { font-size: 0.9em; color: #888; }
259 259
260 260 p.other-formats { text-align: right; font-size:0.9em; color: #666; }
261 261 .other-formats span + span:before { content: "| "; }
262 262
263 263 a.feed { background: url(../images/feed.png) no-repeat 1px 50%; padding: 2px 0px 3px 16px; }
264 264
265 265 /***** Flash & error messages ****/
266 266 #errorExplanation, div.flash, .nodata, .warning {
267 267 padding: 4px 4px 4px 30px;
268 268 margin-bottom: 12px;
269 269 font-size: 1.1em;
270 270 border: 2px solid;
271 271 }
272 272
273 273 div.flash {margin-top: 8px;}
274 274
275 275 div.flash.error, #errorExplanation {
276 276 background: url(../images/false.png) 8px 5px no-repeat;
277 277 background-color: #ffe3e3;
278 278 border-color: #dd0000;
279 279 color: #550000;
280 280 }
281 281
282 282 div.flash.notice {
283 283 background: url(../images/true.png) 8px 5px no-repeat;
284 284 background-color: #dfffdf;
285 285 border-color: #9fcf9f;
286 286 color: #005f00;
287 287 }
288 288
289 289 .nodata, .warning {
290 290 text-align: center;
291 291 background-color: #FFEBC1;
292 292 border-color: #FDBF3B;
293 293 color: #A6750C;
294 294 }
295 295
296 296 #errorExplanation ul { font-size: 0.9em;}
297 297
298 298 /***** Ajax indicator ******/
299 299 #ajax-indicator {
300 300 position: absolute; /* fixed not supported by IE */
301 301 background-color:#eee;
302 302 border: 1px solid #bbb;
303 303 top:35%;
304 304 left:40%;
305 305 width:20%;
306 306 font-weight:bold;
307 307 text-align:center;
308 308 padding:0.6em;
309 309 z-index:100;
310 310 filter:alpha(opacity=50);
311 311 opacity: 0.5;
312 312 }
313 313
314 314 html>body #ajax-indicator { position: fixed; }
315 315
316 316 #ajax-indicator span {
317 317 background-position: 0% 40%;
318 318 background-repeat: no-repeat;
319 319 background-image: url(../images/loading.gif);
320 320 padding-left: 26px;
321 321 vertical-align: bottom;
322 322 }
323 323
324 324 /***** Calendar *****/
325 325 table.cal {border-collapse: collapse; width: 100%; margin: 8px 0 6px 0;border: 1px solid #d7d7d7;}
326 326 table.cal thead th {width: 14%;}
327 327 table.cal tbody tr {height: 100px;}
328 328 table.cal th { background-color:#EEEEEE; padding: 4px; }
329 329 table.cal td {border: 1px solid #d7d7d7; vertical-align: top; font-size: 0.9em;}
330 330 table.cal td p.day-num {font-size: 1.1em; text-align:right;}
331 331 table.cal td.odd p.day-num {color: #bbb;}
332 332 table.cal td.today {background:#ffffdd;}
333 333 table.cal td.today p.day-num {font-weight: bold;}
334 334
335 335 /***** Tooltips ******/
336 336 .tooltip{position:relative;z-index:24;}
337 337 .tooltip:hover{z-index:25;color:#000;}
338 338 .tooltip span.tip{display: none; text-align:left;}
339 339
340 340 div.tooltip:hover span.tip{
341 341 display:block;
342 342 position:absolute;
343 343 top:12px; left:24px; width:270px;
344 344 border:1px solid #555;
345 345 background-color:#fff;
346 346 padding: 4px;
347 347 font-size: 0.8em;
348 348 color:#505050;
349 349 }
350 350
351 351 /***** Progress bar *****/
352 352 table.progress {
353 353 border: 1px solid #D7D7D7;
354 354 border-collapse: collapse;
355 355 border-spacing: 0pt;
356 356 empty-cells: show;
357 357 text-align: center;
358 358 float:left;
359 359 margin: 1px 6px 1px 0px;
360 360 }
361 361
362 362 table.progress td { height: 0.9em; }
363 363 table.progress td.closed { background: #BAE0BA none repeat scroll 0%; }
364 364 table.progress td.done { background: #DEF0DE none repeat scroll 0%; }
365 365 table.progress td.open { background: #FFF none repeat scroll 0%; }
366 366 p.pourcent {font-size: 80%;}
367 367 p.progress-info {clear: left; font-style: italic; font-size: 80%;}
368 368
369 369 /***** Tabs *****/
370 370 #content .tabs {height: 2.6em; border-bottom: 1px solid #bbbbbb; margin-bottom:1.2em; position:relative;}
371 371 #content .tabs ul {margin:0; position:absolute; bottom:-2px; padding-left:1em;}
372 372 #content .tabs>ul { bottom:-1px; } /* others */
373 373 #content .tabs ul li {
374 374 float:left;
375 375 list-style-type:none;
376 376 white-space:nowrap;
377 377 margin-right:8px;
378 378 background:#fff;
379 379 }
380 380 #content .tabs ul li a{
381 381 display:block;
382 382 font-size: 0.9em;
383 383 text-decoration:none;
384 384 line-height:1.3em;
385 385 padding:4px 6px 4px 6px;
386 386 border: 1px solid #ccc;
387 387 border-bottom: 1px solid #bbbbbb;
388 388 background-color: #eeeeee;
389 389 color:#777;
390 390 font-weight:bold;
391 391 }
392 392
393 393 #content .tabs ul li a:hover {
394 394 background-color: #ffffdd;
395 395 text-decoration:none;
396 396 }
397 397
398 398 #content .tabs ul li a.selected {
399 399 background-color: #fff;
400 400 border: 1px solid #bbbbbb;
401 401 border-bottom: 1px solid #fff;
402 402 }
403 403
404 404 #content .tabs ul li a.selected:hover {
405 405 background-color: #fff;
406 406 }
407 407
408 408 /***** Diff *****/
409 409 .diff_out { background: #fcc; }
410 410 .diff_in { background: #cfc; }
411 411
412 412 /***** Wiki *****/
413 413 div.wiki table {
414 414 border: 1px solid #505050;
415 415 border-collapse: collapse;
416 416 margin-bottom: 1em;
417 417 }
418 418
419 419 div.wiki table, div.wiki td, div.wiki th {
420 420 border: 1px solid #bbb;
421 421 padding: 4px;
422 422 }
423 423
424 424 div.wiki .external {
425 425 background-position: 0% 60%;
426 426 background-repeat: no-repeat;
427 427 padding-left: 12px;
428 428 background-image: url(../images/external.png);
429 429 }
430 430
431 431 div.wiki a.new {
432 432 color: #b73535;
433 433 }
434 434
435 435 div.wiki pre {
436 436 margin: 1em 1em 1em 1.6em;
437 437 padding: 2px;
438 438 background-color: #fafafa;
439 439 border: 1px solid #dadada;
440 440 width:95%;
441 441 overflow-x: auto;
442 442 }
443 443
444 444 div.wiki div.toc {
445 445 background-color: #ffffdd;
446 446 border: 1px solid #e4e4e4;
447 447 padding: 4px;
448 448 line-height: 1.2em;
449 449 margin-bottom: 12px;
450 450 margin-right: 12px;
451 451 display: table
452 452 }
453 453 * html div.wiki div.toc { width: 50%; } /* IE6 doesn't autosize div */
454 454
455 455 div.wiki div.toc.right { float: right; margin-left: 12px; margin-right: 0; width: auto; }
456 456 div.wiki div.toc.left { float: left; margin-right: 12px; margin-left: 0; width: auto; }
457 457
458 458 div.wiki div.toc a {
459 459 display: block;
460 460 font-size: 0.9em;
461 461 font-weight: normal;
462 462 text-decoration: none;
463 463 color: #606060;
464 464 }
465 465 div.wiki div.toc a:hover { color: #c61a1a; text-decoration: underline;}
466 466
467 467 div.wiki div.toc a.heading2 { margin-left: 6px; }
468 468 div.wiki div.toc a.heading3 { margin-left: 12px; font-size: 0.8em; }
469 469
470 470 /***** My page layout *****/
471 471 .block-receiver {
472 472 border:1px dashed #c0c0c0;
473 473 margin-bottom: 20px;
474 474 padding: 15px 0 15px 0;
475 475 }
476 476
477 477 .mypage-box {
478 478 margin:0 0 20px 0;
479 479 color:#505050;
480 480 line-height:1.5em;
481 481 }
482 482
483 483 .handle {
484 484 cursor: move;
485 485 }
486 486
487 487 a.close-icon {
488 488 display:block;
489 489 margin-top:3px;
490 490 overflow:hidden;
491 491 width:12px;
492 492 height:12px;
493 493 background-repeat: no-repeat;
494 494 cursor:pointer;
495 495 background-image:url('../images/close.png');
496 496 }
497 497
498 498 a.close-icon:hover {
499 499 background-image:url('../images/close_hl.png');
500 500 }
501 501
502 502 /***** Gantt chart *****/
503 503 .gantt_hdr {
504 504 position:absolute;
505 505 top:0;
506 506 height:16px;
507 507 border-top: 1px solid #c0c0c0;
508 508 border-bottom: 1px solid #c0c0c0;
509 509 border-right: 1px solid #c0c0c0;
510 510 text-align: center;
511 511 overflow: hidden;
512 512 }
513 513
514 514 .task {
515 515 position: absolute;
516 516 height:8px;
517 517 font-size:0.8em;
518 518 color:#888;
519 519 padding:0;
520 520 margin:0;
521 521 line-height:0.8em;
522 522 }
523 523
524 524 .task_late { background:#f66 url(../images/task_late.png); border: 1px solid #f66; }
525 525 .task_done { background:#66f url(../images/task_done.png); border: 1px solid #66f; }
526 526 .task_todo { background:#aaa url(../images/task_todo.png); border: 1px solid #aaa; }
527 527 .milestone { background-image:url(../images/milestone.png); background-repeat: no-repeat; border: 0; }
528 528
529 529 /***** Icons *****/
530 530 .icon {
531 531 background-position: 0% 40%;
532 532 background-repeat: no-repeat;
533 533 padding-left: 20px;
534 534 padding-top: 2px;
535 535 padding-bottom: 3px;
536 536 }
537 537
538 538 .icon22 {
539 539 background-position: 0% 40%;
540 540 background-repeat: no-repeat;
541 541 padding-left: 26px;
542 542 line-height: 22px;
543 543 vertical-align: middle;
544 544 }
545 545
546 546 .icon-add { background-image: url(../images/add.png); }
547 547 .icon-edit { background-image: url(../images/edit.png); }
548 548 .icon-copy { background-image: url(../images/copy.png); }
549 549 .icon-del { background-image: url(../images/delete.png); }
550 550 .icon-move { background-image: url(../images/move.png); }
551 551 .icon-save { background-image: url(../images/save.png); }
552 552 .icon-cancel { background-image: url(../images/cancel.png); }
553 553 .icon-file { background-image: url(../images/file.png); }
554 554 .icon-folder { background-image: url(../images/folder.png); }
555 555 .open .icon-folder { background-image: url(../images/folder_open.png); }
556 556 .icon-package { background-image: url(../images/package.png); }
557 557 .icon-home { background-image: url(../images/home.png); }
558 558 .icon-user { background-image: url(../images/user.png); }
559 559 .icon-mypage { background-image: url(../images/user_page.png); }
560 560 .icon-admin { background-image: url(../images/admin.png); }
561 561 .icon-projects { background-image: url(../images/projects.png); }
562 562 .icon-logout { background-image: url(../images/logout.png); }
563 563 .icon-help { background-image: url(../images/help.png); }
564 564 .icon-attachment { background-image: url(../images/attachment.png); }
565 565 .icon-index { background-image: url(../images/index.png); }
566 566 .icon-history { background-image: url(../images/history.png); }
567 567 .icon-time { background-image: url(../images/time.png); }
568 568 .icon-stats { background-image: url(../images/stats.png); }
569 569 .icon-warning { background-image: url(../images/warning.png); }
570 570 .icon-fav { background-image: url(../images/fav.png); }
571 571 .icon-fav-off { background-image: url(../images/fav_off.png); }
572 572 .icon-reload { background-image: url(../images/reload.png); }
573 573 .icon-lock { background-image: url(../images/locked.png); }
574 574 .icon-unlock { background-image: url(../images/unlock.png); }
575 575 .icon-checked { background-image: url(../images/true.png); }
576 576 .icon-details { background-image: url(../images/zoom_in.png); }
577 577 .icon-report { background-image: url(../images/report.png); }
578 578
579 579 .icon22-projects { background-image: url(../images/22x22/projects.png); }
580 580 .icon22-users { background-image: url(../images/22x22/users.png); }
581 581 .icon22-tracker { background-image: url(../images/22x22/tracker.png); }
582 582 .icon22-role { background-image: url(../images/22x22/role.png); }
583 583 .icon22-workflow { background-image: url(../images/22x22/workflow.png); }
584 584 .icon22-options { background-image: url(../images/22x22/options.png); }
585 585 .icon22-notifications { background-image: url(../images/22x22/notifications.png); }
586 586 .icon22-authent { background-image: url(../images/22x22/authent.png); }
587 587 .icon22-info { background-image: url(../images/22x22/info.png); }
588 588 .icon22-comment { background-image: url(../images/22x22/comment.png); }
589 589 .icon22-package { background-image: url(../images/22x22/package.png); }
590 590 .icon22-settings { background-image: url(../images/22x22/settings.png); }
591 591 .icon22-plugin { background-image: url(../images/22x22/plugin.png); }
592 592
593 593 /***** Media print specific styles *****/
594 594 @media print {
595 595 #top-menu, #header, #main-menu, #sidebar, #footer, .contextual, .other-formats { display:none; }
596 596 #main { background: #fff; }
597 597 #content { width: 99%; margin: 0; padding: 0; border: 0; background: #fff; }
598 598 }
@@ -1,234 +1,242
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../../test_helper'
19 19
20 20 class ApplicationHelperTest < HelperTestCase
21 21 include ApplicationHelper
22 22 include ActionView::Helpers::TextHelper
23 23 fixtures :projects, :repositories, :changesets, :trackers, :issue_statuses, :issues, :documents, :versions, :wikis, :wiki_pages, :wiki_contents, :roles, :enabled_modules
24 24
25 25 def setup
26 26 super
27 27 end
28 28
29 29 def test_auto_links
30 30 to_test = {
31 31 'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>',
32 32 'http://foo.bar/~user' => '<a class="external" href="http://foo.bar/~user">http://foo.bar/~user</a>',
33 33 'http://foo.bar.' => '<a class="external" href="http://foo.bar">http://foo.bar</a>.',
34 34 'http://foo.bar/foo.bar#foo.bar.' => '<a class="external" href="http://foo.bar/foo.bar#foo.bar">http://foo.bar/foo.bar#foo.bar</a>.',
35 35 'www.foo.bar' => '<a class="external" href="http://www.foo.bar">www.foo.bar</a>',
36 36 'http://foo.bar/page?p=1&t=z&s=' => '<a class="external" href="http://foo.bar/page?p=1&#38;t=z&#38;s=">http://foo.bar/page?p=1&#38;t=z&#38;s=</a>',
37 37 'http://foo.bar/page#125' => '<a class="external" href="http://foo.bar/page#125">http://foo.bar/page#125</a>'
38 38 }
39 39 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
40 40 end
41 41
42 42 def test_auto_mailto
43 43 assert_equal '<p><a href="mailto:test@foo.bar" class="email">test@foo.bar</a></p>',
44 44 textilizable('test@foo.bar')
45 45 end
46 46
47 47 def test_inline_images
48 48 to_test = {
49 49 '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
50 50 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>',
51 51 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />',
52 52 'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" style="width:100px;height100px;" alt="" />',
53 53 }
54 54 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
55 55 end
56 56
57 57 def test_textile_external_links
58 58 to_test = {
59 59 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
60 60 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>',
61 61 '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>',
62 62 # no multiline link text
63 63 "This is a double quote \"on the first line\nand another on a second line\":test" => "This is a double quote \"on the first line<br />\nand another on a second line\":test"
64 64 }
65 65 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
66 66 end
67 67
68 68 def test_redmine_links
69 69 issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
70 70 :class => 'issue', :title => 'Error 281 when updating a recipe (New)')
71 71
72 72 changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
73 73 :class => 'changeset', :title => 'My very first commit')
74 74
75 75 document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1},
76 76 :class => 'document')
77 77
78 78 version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
79 79 :class => 'version')
80 80
81 81 source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => 'some/file'}
82 82
83 83 to_test = {
84 84 # tickets
85 85 '#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.",
86 86 # changesets
87 87 'r1' => changeset_link,
88 88 # documents
89 89 'document#1' => document_link,
90 90 'document:"Test document"' => document_link,
91 91 # versions
92 92 'version#2' => version_link,
93 93 'version:1.0' => version_link,
94 94 'version:"1.0"' => version_link,
95 95 # source
96 96 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'),
97 97 'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'),
98 98 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'),
99 99 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'),
100 100 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'),
101 101 # escaping
102 102 '!#3.' => '#3.',
103 103 '!r1' => 'r1',
104 104 '!document#1' => 'document#1',
105 105 '!document:"Test document"' => 'document:"Test document"',
106 106 '!version#2' => 'version#2',
107 107 '!version:1.0' => 'version:1.0',
108 108 '!version:"1.0"' => 'version:"1.0"',
109 109 '!source:/some/file' => 'source:/some/file',
110 110 # invalid expressions
111 111 'source:' => 'source:',
112 112 # url hash
113 113 "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>',
114 114 }
115 115 @project = Project.find(1)
116 116 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
117 117 end
118 118
119 119 def test_wiki_links
120 120 to_test = {
121 121 '[[CookBook documentation]]' => '<a href="/wiki/ecookbook/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
122 122 '[[Another page|Page]]' => '<a href="/wiki/ecookbook/Another_page" class="wiki-page">Page</a>',
123 123 # page that doesn't exist
124 124 '[[Unknown page]]' => '<a href="/wiki/ecookbook/Unknown_page" class="wiki-page new">Unknown page</a>',
125 125 '[[Unknown page|404]]' => '<a href="/wiki/ecookbook/Unknown_page" class="wiki-page new">404</a>',
126 126 # link to another project wiki
127 127 '[[onlinestore:]]' => '<a href="/wiki/onlinestore/" class="wiki-page">onlinestore</a>',
128 128 '[[onlinestore:|Wiki]]' => '<a href="/wiki/onlinestore/" class="wiki-page">Wiki</a>',
129 129 '[[onlinestore:Start page]]' => '<a href="/wiki/onlinestore/Start_page" class="wiki-page">Start page</a>',
130 130 '[[onlinestore:Start page|Text]]' => '<a href="/wiki/onlinestore/Start_page" class="wiki-page">Text</a>',
131 131 '[[onlinestore:Unknown page]]' => '<a href="/wiki/onlinestore/Unknown_page" class="wiki-page new">Unknown page</a>',
132 132 # escaping
133 133 '![[Another page|Page]]' => '[[Another page|Page]]',
134 134 }
135 135 @project = Project.find(1)
136 136 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
137 137 end
138 138
139 139 def test_html_tags
140 140 to_test = {
141 141 "<div>content</div>" => "<p>&lt;div&gt;content&lt;/div&gt;</p>",
142 142 "<div class=\"bold\">content</div>" => "<p>&lt;div class=\"bold\"&gt;content&lt;/div&gt;</p>",
143 143 "<script>some script;</script>" => "<p>&lt;script&gt;some script;&lt;/script&gt;</p>",
144 144 # do not escape pre/code tags
145 145 "<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>",
146 146 "<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>",
147 147 "<pre><div>content</div></pre>" => "<pre>&lt;div&gt;content&lt;/div&gt;</pre>",
148 148 "HTML comment: <!-- no comments -->" => "<p>HTML comment: &lt;!-- no comments --&gt;</p>",
149 149 "<!-- opening comment" => "<p>&lt;!-- opening comment</p>"
150 150 }
151 151 to_test.each { |text, result| assert_equal result, textilizable(text) }
152 152 end
153 153
154 def test_allowed_html_tags
155 to_test = {
156 "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>",
157 "<notextile>no *textile* formatting</notextile>" => "no *textile* formatting",
158 }
159 to_test.each { |text, result| assert_equal result, textilizable(text) }
160 end
161
154 162 def test_wiki_links_in_tables
155 163 to_test = {"|Cell 11|Cell 12|Cell 13|\n|Cell 21|Cell 22||\n|Cell 31||Cell 33|" =>
156 164 '<tr><td>Cell 11</td><td>Cell 12</td><td>Cell 13</td></tr>' +
157 165 '<tr><td>Cell 21</td><td>Cell 22</td></tr>' +
158 166 '<tr><td>Cell 31</td><td>Cell 33</td></tr>',
159 167
160 168 "|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" =>
161 169 '<tr><td><a href="/wiki/ecookbook/Page" class="wiki-page new">Link title</a></td>' +
162 170 '<td><a href="/wiki/ecookbook/Other_Page" class="wiki-page new">Other title</a></td>' +
163 171 '</tr><tr><td>Cell 21</td><td><a href="/wiki/ecookbook/Last_page" class="wiki-page new">Last page</a></td></tr>'
164 172 }
165 173 @project = Project.find(1)
166 174 to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') }
167 175 end
168 176
169 177 def test_text_formatting
170 178 to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>',
171 179 '(_text within parentheses_)' => '(<em>text within parentheses</em>)'
172 180 }
173 181 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
174 182 end
175 183
176 184 def test_wiki_horizontal_rule
177 185 assert_equal '<hr />', textilizable('---')
178 186 assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
179 187 end
180 188
181 189 def test_macro_hello_world
182 190 text = "{{hello_world}}"
183 191 assert textilizable(text).match(/Hello world!/)
184 192 # escaping
185 193 text = "!{{hello_world}}"
186 194 assert_equal '<p>{{hello_world}}</p>', textilizable(text)
187 195 end
188 196
189 197 def test_macro_include
190 198 @project = Project.find(1)
191 199 # include a page of the current project wiki
192 200 text = "{{include(Another page)}}"
193 201 assert textilizable(text).match(/This is a link to a ticket/)
194 202
195 203 @project = nil
196 204 # include a page of a specific project wiki
197 205 text = "{{include(ecookbook:Another page)}}"
198 206 assert textilizable(text).match(/This is a link to a ticket/)
199 207
200 208 text = "{{include(ecookbook:)}}"
201 209 assert textilizable(text).match(/CookBook documentation/)
202 210
203 211 text = "{{include(unknowidentifier:somepage)}}"
204 212 assert textilizable(text).match(/Unknow project/)
205 213 end
206 214
207 215 def test_date_format_default
208 216 today = Date.today
209 217 Setting.date_format = ''
210 218 assert_equal l_date(today), format_date(today)
211 219 end
212 220
213 221 def test_date_format
214 222 today = Date.today
215 223 Setting.date_format = '%d %m %Y'
216 224 assert_equal today.strftime('%d %m %Y'), format_date(today)
217 225 end
218 226
219 227 def test_time_format_default
220 228 now = Time.now
221 229 Setting.date_format = ''
222 230 Setting.time_format = ''
223 231 assert_equal l_datetime(now), format_time(now)
224 232 assert_equal l_time(now), format_time(now, false)
225 233 end
226 234
227 235 def test_time_format
228 236 now = Time.now
229 237 Setting.date_format = '%d %m %Y'
230 238 Setting.time_format = '%H %M'
231 239 assert_equal now.strftime('%d %m %Y %H %M'), format_time(now)
232 240 assert_equal now.strftime('%H %M'), format_time(now, false)
233 241 end
234 242 end
General Comments 0
You need to be logged in to leave comments. Login now