junebug 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ v0.0.13 2006-11-14
2
+
3
+ * Link style improvement/simplification
4
+ * Autolinking urls
5
+ * use user.role to determine admin rights
6
+ * is_admin?, logged_in?
7
+
1
8
  v0.0.12 2006-11-13
2
9
 
3
10
  * content div bugfix
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ Gem.manage_gems
12
12
 
13
13
  gem_spec = Gem::Specification.new do |s|
14
14
  s.name = 'junebug'
15
- s.version = '0.0.12'
15
+ s.version = '0.0.13'
16
16
  s.summary = "Junebug is a minimalist ruby wiki."
17
17
  s.description = "Junebug is a minimalist ruby wiki running on Camping."
18
18
  s.author = "Tim Myrtle"
@@ -1,4 +1,13 @@
1
1
 
2
+ a:link, a:visited {
3
+ text-decoration: none;
4
+ color: #00f;
5
+ }
6
+ a:hover {
7
+ text-decoration: underline;
8
+ color: #00f;
9
+ }
10
+
2
11
 
3
12
  form { display: inline; }
4
13
 
@@ -52,13 +61,6 @@ body {
52
61
  color: #ffffff;
53
62
  }
54
63
 
55
- #hd a:link, #hd a:visited {
56
- text-decoration: none;
57
- }
58
- #hd a:hover {
59
- text-decoration: underline;
60
- }
61
-
62
64
  #hd a {
63
65
  color: #ffffff;
64
66
  }
@@ -77,7 +79,6 @@ body {
77
79
  background-color: #ffffff;
78
80
  border:5px solid #929292;
79
81
  border-width:0 5px 5px 0;
80
- min-height: 300px;
81
82
  }
82
83
 
83
84
  #yui-main{
@@ -87,11 +88,13 @@ body {
87
88
  }
88
89
 
89
90
  #ft {
90
- border: 1px solid #ddd;
91
- background-color: #d7dffd;
91
+ border: 1px solid #eee;
92
+ background-color: #ddd;
93
+ color: #333;
92
94
  font-size: 100%;
93
95
  padding: 8px;
94
96
  margin-bottom: 10px;
97
+ line-height: 150%;
95
98
  }
96
99
 
97
100
  .formbox {
@@ -145,10 +148,7 @@ body {
145
148
  .content {
146
149
  font-size: 114%;
147
150
  padding: 25px;
148
- }
149
-
150
- .content a:link, .content a:visited, .content a:hover {
151
- color: #00f;
151
+ min-height: 300px;
152
152
  }
153
153
 
154
154
  .content h2, .content h3, .content h4 {
@@ -164,14 +164,14 @@ body {
164
164
  .content h2 {
165
165
  font-size: 129%;
166
166
  border-bottom: 2px dotted #bbb;
167
- margin-top: 20px;
167
+ margin-top: 25px;
168
168
  margin-bottom: 10px;
169
169
  /* background-color: #d6fbf4;*/
170
170
  }
171
171
 
172
172
  .content h3 {
173
173
  font-size: 129%;
174
- margin-top: 20px;
174
+ margin-top: 25px;
175
175
  margin-bottom: 10px;
176
176
  /* border-bottom: 1px dotted #bbb;*/
177
177
  }
@@ -229,6 +229,7 @@ body {
229
229
  /* font-family:"Bitstream Vera Sans Mono", "Monaco", "Courier", monospace;*/
230
230
  display: block;
231
231
  background: #eee;
232
+ border: 1px solid #ddd;
232
233
  padding: 8px 20px;
233
234
  }
234
235
 
@@ -21,22 +21,19 @@ module Junebug::Controllers
21
21
 
22
22
  class Edit < R '/(\w+)/edit', '/(\w+)/(\d+)/edit'
23
23
  def get page_name, version = nil
24
- redirect("#{Junebug.config['url']}/login") and return if @state.user_id.blank?
24
+ redirect("#{Junebug.config['url']}/login") and return unless logged_in?
25
25
  @page_title = "Edit #{page_name}"
26
26
  @page = Page.find(:first, :conditions=>['title = ?', page_name])
27
- @page = Page.create(:title => page_name, :user_id=>@state.user_id) unless @page
27
+ @page = Page.create(:title => page_name, :user_id=>@state.user.id) unless @page
28
28
  @page = @page.versions.find_by_version(version) unless version.nil? or version == @page.version.to_s
29
29
  render :edit
30
30
  end
31
31
 
32
32
  def post page_name
33
- redirect("#{Junebug.config['url']}/login") and return if @state.user_id.blank?
34
- if input.submit == 'delete'
35
- Page.find_by_title(page_name).destroy() if @state.user_id == 1
36
- redirect Junebug.startpage
37
- elsif input.submit == 'save'
38
- attrs = { :body => input.post_body, :title => input.post_title, :user_id =>@state.user_id }
39
- attrs[:readonly] = input.post_readonly if @state.user_id == 1
33
+ redirect("#{Junebug.config['url']}/login") and return unless logged_in?
34
+ if input.submit == 'save'
35
+ attrs = { :body => input.post_body, :title => input.post_title, :user_id =>@state.user.id }
36
+ attrs[:readonly] = input.post_readonly if is_admin?
40
37
  if Page.find_or_create_by_title(page_name).update_attributes( attrs )
41
38
  # redirect Show, input.post_title
42
39
  redirect "#{Junebug.config['url']}/#{input.post_title}"
@@ -49,8 +46,8 @@ module Junebug::Controllers
49
46
 
50
47
  class Delete < R '/(\w+)/delete'
51
48
  def get page_name
52
- redirect("#{Junebug.config['url']}/login") and return if @state.user_id.blank?
53
- Page.find_by_title(page_name).destroy() if @state.user_id == 1
49
+ redirect("#{Junebug.config['url']}/login") and return unless logged_in?
50
+ Page.find_by_title(page_name).destroy() if is_admin?
54
51
  redirect Junebug.startpage
55
52
  end
56
53
 
@@ -58,8 +55,8 @@ module Junebug::Controllers
58
55
 
59
56
  class Revert < R '/(\w+)/(\d+)/revert'
60
57
  def get page_name, version
61
- redirect("#{Junebug.config['url']}/login") and return if @state.user_id.blank?
62
- Page.find_by_title(page_name).revert_to!(version) if @state.user_id == 1
58
+ redirect("#{Junebug.config['url']}/login") and return unless logged_in?
59
+ Page.find_by_title(page_name).revert_to!(version) if is_admin?
63
60
  redirect "#{Junebug.config['url']}/#{page_name}"
64
61
  end
65
62
  end
@@ -148,8 +145,7 @@ module Junebug::Controllers
148
145
  @user = User.find :first, :conditions => ['username = ? AND password = ?', input.username, input.password]
149
146
  if @user
150
147
  if @user.password == input.password
151
- @state.user_id = @user.id
152
- @state.user_username = @user.username
148
+ @state.user = @user
153
149
  redirect(Junebug.startpage); return
154
150
  else
155
151
  @notice = 'Authentication failed'
@@ -157,8 +153,7 @@ module Junebug::Controllers
157
153
  else
158
154
  @user = User.create :username=>input.username, :password=>input.password
159
155
  if @user.errors.empty?
160
- @state.user_id = @user.id
161
- @state.user_username = @user.username
156
+ @state.user = @user
162
157
  redirect(Junebug.startpage); return
163
158
  else
164
159
  @notice = @user.errors.full_messages[0]
@@ -170,9 +165,8 @@ module Junebug::Controllers
170
165
 
171
166
  class Logout
172
167
  def get
173
- @state.user_id = nil
174
- @state.user_username = nil
175
- redirect(Junebug.startpage)
168
+ @state.user = nil
169
+ redirect(Junebug.startpage)
176
170
  end
177
171
  end
178
172
  end
@@ -1,5 +1,14 @@
1
1
 
2
2
  module Junebug::Helpers
3
+
4
+ def logged_in?
5
+ !@state.user.blank?
6
+ end
7
+
8
+ def is_admin?
9
+ @state.user && @state.user.role == Junebug::Models::User::ROLE_ADMIN
10
+ end
11
+
3
12
  def last_updated(page)
4
13
  from = page.updated_at.to_i
5
14
  to = Time.now.to_i
@@ -15,4 +24,19 @@ module Junebug::Helpers
15
24
  else "#{(distance / 1440).round} days"
16
25
  end
17
26
  end
27
+
28
+ def auto_link_urls(text)
29
+ extra_options = ""
30
+ text.gsub(/(<\w+.*?>|[^=!:'"\/]|^)((?:http[s]?:\/\/)|(?:www\.))([^\s<]+\/?)([[:punct:]]|\s|<|$)/) do
31
+ all, a, b, c, d = $&, $1, $2, $3, $4
32
+ if a =~ /<a\s/i # don't replace URL's that are already linked
33
+ all
34
+ else
35
+ text = b + c
36
+ text = yield(text) if block_given?
37
+ %(#{a}<a href="#{b=="www."?"http://www.":b}#{c}"#{extra_options}>#{text}</a>#{d})
38
+ end
39
+ end
40
+ end
41
+
18
42
  end
data/lib/junebug/views.rb CHANGED
@@ -23,9 +23,10 @@ module Junebug::Views
23
23
  def show
24
24
  _header (@version.version == @page.version ? :show : :backlinks), @page.title
25
25
  _body {
26
- _button 'edit', R(Edit, @page.title, @version.version), {:style=>'float: right; margin: 0 0 5px 5px;'} if (@version.version == @page.version && (! @page.readonly || @state.user_id == 1))
26
+ _button 'edit', R(Edit, @page.title, @version.version), {:style=>'float: right; margin: 0 0 5px 5px;'} if logged_in? && (@version.version == @page.version && (! @page.readonly || is_admin?))
27
27
  _markup @version.body
28
- _button 'edit', R(Edit, @page.title, @version.version), {:style=>'float: right; margin: 0 0 5px 5px;'} if (@version.version == @page.version && (! @page.readonly || @state.user_id == 1)) && (@version.body && @version.body.size > 100)
28
+ _button 'edit', R(Edit, @page.title, @version.version), {:style=>'float: right; margin: 5px 0 0 5px;'} if logged_in? && (@version.version == @page.version && (! @page.readonly || is_admin?)) && (@version.body && @version.body.size > 100)
29
+ br :clear=>'all'
29
30
  }
30
31
  _footer {
31
32
  text "Last edited by <b>#{@version.user.username}</b> on #{@page.updated_at.strftime('%B %d, %Y %I:%M %p')}"
@@ -46,7 +47,7 @@ module Junebug::Views
46
47
  a 'versions', :href => R(Versions, @page.title)
47
48
  }
48
49
  }
49
- if (@state.user_id == 1)
50
+ if is_admin?
50
51
  div.admin {
51
52
  _button 'delete', R(Delete, @page.title), {:onclick=>'return confirm("Sure you want to delete?")'} if @version.version == @page.version
52
53
  _button 'revert to', R(Revert, @page.title, @version.version), {:onclick=>'return confirm("Sure you want to revert?")'} if @version.version != @page.version
@@ -71,7 +72,7 @@ module Junebug::Views
71
72
  br
72
73
  textarea @page.body, :name => 'post_body', :rows => 17, :cols => 80
73
74
  }
74
- if @state.user_id == 1
75
+ if is_admin?
75
76
  opts = { :type => 'checkbox', :value=>'1', :name => 'post_readonly' }
76
77
  opts[:checked] = 1 if @page.readonly
77
78
  input opts
@@ -215,13 +216,13 @@ module Junebug::Views
215
216
  %Q{<span>#{title}<a href="#{self/R(Edit, page, 1)}">?</a></span>}
216
217
  end
217
218
  end
218
- text RedCloth.new(txt, [ ]).to_html
219
+ text RedCloth.new(auto_link_urls(txt), [ ]).to_html
219
220
  end
220
221
 
221
222
  def _header type, page_title
222
223
  div :id=>'hd' do
223
224
  span :id=>'userlinks', :style=>'float: right;' do
224
- @state.user_id.blank? ? a('sign in', :href=>R(Login)) : (text "Welcome, #{@state.user_username} - " ; a('sign out', :href=>R(Logout)))
225
+ logged_in? ? (text "Welcome, #{@state.user.username} - " ; a('sign out', :href=>R(Logout))) : a('sign in', :href=>R(Login))
225
226
  end
226
227
  if type == :static
227
228
  h1 page_title
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: junebug
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.12
7
- date: 2006-11-13 00:00:00 -08:00
6
+ version: 0.0.13
7
+ date: 2006-11-14 00:00:00 -08:00
8
8
  summary: Junebug is a minimalist ruby wiki.
9
9
  require_paths:
10
10
  - lib