Module: Junebug::Views

Defined in:
lib/junebug/views.rb

Instance Method Summary collapse

Instance Method Details

#_bodyObject



363
364
365
366
367
368
369
# File 'lib/junebug/views.rb', line 363

def _body
  div :id=>'bd' do
    div.content do
      yield
    end
  end
end

#_button(text, href, options = {}) ⇒ Object



291
292
293
294
295
296
# File 'lib/junebug/views.rb', line 291

def _button(text, href, options={})
  form :method=>:get, :action=>href do
    opts = {:type=>'submit', :name=>'submit', :value=>text}.merge(options)
    input.button opts
  end
end


371
372
373
374
375
376
377
378
379
380
381
382
383
384
# File 'lib/junebug/views.rb', line 371

def _footer
  div :id=>'ft' do
    span :style=>'float: right;' do
      text 'Powered by '
      a 'JunebugWiki', :href => 'http://www.junebugwiki.com/'
      text " <small>v#{Junebug::VERSION::STRING}</small> "
      a :href => Junebug.config['feedurl'] do
        img :src => '/images/feed-icon-14x14.png'
      end
    end
    yield
    br :clear=>'all'
  end
end

#_header(type) ⇒ Object



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/junebug/views.rb', line 315

def _header type
  div :id=>'hd' do
    
    span :id=>'userlinks' do
      if logged_in?
        text "Hi, #{@state.user.username} - "
        a 'sign out', :href=>"#{R(Logout)}?return_to=#{@env['REQUEST_URI']}"
      else
        a 'sign in', :href=> "#{R(Login)}?return_to=#{@env['REQUEST_URI']}"
      end
    end

    span :id=>'search' do
      # text 'Search: '
      form :action => R(Search), :method => 'post' do
        input :name => 'q', :type => 'text', :value=>(''), :accesskey => 's' 
        #input :type => 'submit', :name => 'search', :value => 'Search',
        #  :style=>'margin: 0 0 5px 5px;'
      end
    end
 
    span :id=>'navlinks' do
      a 'Home',  :href => R(Show, Junebug.config['startpage'])
      text ' | '
      a 'Updates', :href => R(Recent)
      text ' | '
      a 'Pages', :href => R(List)
      text ' | '
      a 'Users', :href => R(Users)
      text ' | '
      a 'Admin', :href => R(Orphans)
      text ' | '
      a 'Help', :href => R(Show, "Junebug_help") 
    end
    
    br :clear => 'all'
    
    # if type == :static
    #   h1 page_title
    # elsif type == :backlinks
    #   h1 { a page_title, :href => R(Backlinks, page_title) }
    # else
    #   h1 { a page_title, :href => R(Show, page_title) }
    # end
    
  end
end

#_markup(txt) ⇒ Object



298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/junebug/views.rb', line 298

def _markup txt
  return '' if txt.blank?
  titles = Junebug::Models::Page.find(:all, :select => 'title').collect { |p| p.title }
  txt = txt.gsub(Junebug::Models::Page::PAGE_LINK) do
    page = title = $1.strip
    title = $2 unless $2.empty?
    page_url = page.gsub(/ /, '_')
    if titles.include?(page)
      %Q{<a href="#{self/R(Show, page_url)}">#{title}</a>}
    else
      %Q{<span>#{title}<a href="#{self/R(Edit, page_url, 1)}">?</a></span>}
    end
  end
  #text RedCloth.new(auto_link_urls(txt), [ ]).to_html
  text RedCloth.new(txt, [ ]).to_html
end


148
149
150
151
152
153
154
155
156
157
# File 'lib/junebug/views.rb', line 148

def backlinks
  _header :show
  _body do
    h1 "Backlinks to #{@page.title}"
    ul {
      @pages.each { |p| li{ a p.title, :href => R(Show, p.title) } }
    }
  end
  _footer { '' }
end

#diffObject



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/junebug/views.rb', line 255

def diff
  _header :show
  _body do
    text 'Comparing '
    span "version #{@v2.version}", :style=>"background-color: #cfc; padding: 1px 4px;"
    text ' and '
    span "version #{@v1.version}", :style=>"background-color: #ddd; padding: 1px 4px;"
    text ' '
    a "back", :href => R(Show, @page.title_url)
    br
    br
    pre.diff {
      text @difftext
    }
  end
  _footer { '' }
end

#editObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/junebug/views.rb', line 61

def edit
  _header :show
  _body do
    if @show_preview
      div.preview {
        h1 "#{@page.title}"
        _markup @page.body
      }
    end
    div.formbox {
      form :method => 'post', :action => R(Edit, @page.title_url) do
        p { 
          label 'Page Title'
          br
          input :value => @page.title, :name => 'post_title', :size => 30, 
                :type => 'text'
          small " word characters (0-9A-Za-z), dashes, and spaces only"
        }
        p {
          a 'syntax help', :href => 'http://hobix.com/textile/', :target=>'_blank', :style => 'float: right;'
          label 'Page Content '
          br
          textarea @page.body, :name => 'post_body', :rows => 17, :cols => 80
        }
        input :type => 'submit', :name=>'submit', :value=>'cancel', :class=>'button', :style=>'float: right;'
        if @page.user_id == @state.user.id
          input :type => 'submit', :name=>'submit', :value=>'minor edit', :class=>'button', :style=>'float: right;', :accesskey => 'm'
        end
        input :type => 'submit', :name=>'submit', :value=>'save', :class=>'button', :style=>'float: right;', :accesskey => 's'
        input :type => 'submit', :name=>'submit', :value=>'preview', :class=>'button', :style=>'float: right;', :accesskey => 'p'
        if is_admin?
          opts = { :type => 'checkbox', :value=>'1', :name => 'post_readonly' }
          opts[:checked] = 1 if @page.readonly
          input opts
          text " Readonly "
          br
        end

      end
      br :clear=>'all'
    }
  end
  _footer { '' }
end

#feedObject



386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/junebug/views.rb', line 386

def feed
  site_url = Junebug.config['siteurl'] || "http://#{Junebug.config['host']}:#{Junebug.config['port']}"
  site_domain = site_url.gsub(/^http:\/\//, '').gsub(/:/,'_')
  feed_url = site_url + R(Feed)

  xml = Builder::XmlMarkup.new(:target => self, :indent => 2)

  xml.instruct!
  xml.feed "xmlns"=>"http://www.w3.org/2005/Atom" do

    xml.title Junebug.config['feedtitle'] || "Wiki Updates"
    xml.id site_url
    xml.link "rel" => "self", "href" => feed_url

    pages = Junebug::Models::Page.find(:all, :order => 'updated_at DESC', :limit => 20)
    xml.updated pages.first.updated_at.xmlschema
    
    pages.each do |page|
      atom_id = "tag:#{site_domain},#{page.created_at.strftime("%Y-%m-%d")}:page/#{page.id}/#{page.version}"
      xml.entry do
        xml.id atom_id
        xml.title page.title
        xml.updated page.updated_at.xmlschema
        
        xml.author { xml.name page.user.username }
        xml.link "rel" => "alternate", "href" => site_url + R(Show, page.title_url)
        xml.summary :type=>'html' do
          xml.text! %|<a href="#{site_url + R(Show, page.title_url)}">#{page.title}</a> updated by #{page.user.username}|
          xml.text! %| (<a href="#{site_url + R(Diff,page.title_url,page.version-1,page.version)}">diff</a>)| if page.version > 1
          xml.text! "\n"
        end
        # xml.content do 
        #   xml.text! CGI::escapeHTML(page.body)+"\n"
        # end
      end
    end   
  end
end

#layoutObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/junebug/views.rb', line 5

def layout
  if @skip_layout
    yield
  else
    html {
      head {
        title @page_title ? @page_title : @page.title
        link :href=>'http://yui.yahooapis.com/2.4.0/build/reset-fonts-grids/reset-fonts-grids.css', :type=>'text/css', :rel=>'stylesheet'
        link :href=>'http://yui.yahooapis.com/2.4.0/build/base/base-min.css', :type=>'text/css', :rel=>'stylesheet'
        link :href=>'/style/base.css', :type=>'text/css', :rel=>'stylesheet'
        script( :type=>'text/javascript', :src=>'/javascripts/ASCIIMathML.js') if Junebug.config['mathml_enable']
        link :href=>Junebug.config['feedurl'], :rel => "alternate", :title => "Recently Updated Pages", :type => "application/atom+xml"
      }
      body {
        div :id=>'doc' do
          self << yield
        end
      }
    }
  end
end

#listObject



216
217
218
219
220
221
222
223
224
225
# File 'lib/junebug/views.rb', line 216

def list
  _header :static
  _body do
    h1 "All wiki pages"
    ul {
      @pages.each { |p| li{ a p.title, :href => R(Show, p.title_url) } }
    }
  end
  _footer { '' }
end

#loginObject



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/junebug/views.rb', line 273

def 
  div. {
    h1 @page_title
    p.notice { @notice } if @notice
    form :action => R(Login), :method => 'post' do
      label 'Username', :for => 'username'; br
      input :name => 'username', :type => 'text', :value=>( @user ? @user.username : '') ; br

      label 'Password', :for => 'password'; br
      input :name => 'password', :type => 'password'; br
      
      input :name => 'return_to', :type => 'hidden', :value=>@return_to

      input :type => 'submit', :name => 'login', :value => 'Login'
    end
  }
end

#orphansObject



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/junebug/views.rb', line 159

def orphans
  _header :show
  _body do
    h1 @page_title
    ul {
      @pages.each { |p|
        li{
          a p.title, :href => R(Show, p.title_url)
          text ' - empty page' if p.body.nil? or p.body.empty? 
        }
      }
    }
  end
  _footer { '' }
end

#recentObject



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/junebug/views.rb', line 228

def recent
  _header :static
  _body do
    h1 "Updates in the last 30 days"
    page = @pages.shift 
    while page
      yday = page.updated_at.yday
      h2 page.updated_at.strftime('%B %d, %Y')
      ul {
        loop do
          li {
            a page.title, :href => R(Show, page.title_url)
            text ' ('
            a 'versions', :href => R(Versions, page.title_url)
            text ",#{diff_link(page)}" if page.version > 1
            text ') '
            span page.updated_at.strftime('%I:%M %p')
          }
          page = @pages.shift
          break unless page && (page.updated_at.yday == yday)
        end
      }
    end
  end
  _footer { '' }
end

#searchObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/junebug/views.rb', line 129

def search
  _header :show
  _body do
    h1 "Search results"

    form :action => R(Search), :method => 'post' do
      input :name => 'q', :type => 'text', :value=>@search_term, :accesskey => 's' 
      input :type => 'submit', :name => 'search', :value => 'Search',
        :style=>'margin: 0 0 5px 5px;'
    end

    ul {
      @pages.each { |p| li{ a p.title, :href => R(Show, p.title_url) } }
    }
  end
  _footer { '' }
end

#showObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/junebug/views.rb', line 28

def show
  _header (@version.version == @page.version ? :backlinks : :show)
  _body do
    _button 'edit', R(Edit, @page.title_url, @version.version), {:style=>'float: right; margin: 0 0 5px 5px;', :accesskey => 'e'} if (@version.version == @page.version && (! @page.readonly || is_admin?))
    h1 @page.title
    _markup @version.body
    _button 'edit', R(Edit, @page.title_url, @version.version), {:style=>'float: right; margin: 5px 0 0 5px;'} if (@version.version == @page.version && (! @page.readonly || is_admin?)) && (@version.body && @version.body.size > 200)
    br :clear=>'all'
  end
  _footer {
    text "Page last edited by <b>#{@version.user.username}</b> on #{@page.updated_at.strftime('%B %d, %Y %I:%M %p')}"
    text " (#{diff_link(@page, @version)}) " if @version.version > 1
    br
    text '<b>[readonly]</b> ' if @page.readonly
    span.actions {
      text "Version #{@version.version} "
      text "(current) " if @version.version == @page.version
      #text 'Other versions: '
      a '«older', :href => R(Show, @page.title_url, @version.version-1) unless @version.version == 1
      a 'newer»', :href => R(Show, @page.title_url, @version.version+1) unless @version.version == @page.version
      a 'current', :href => R(Show, @page.title_url) unless @version.version == @page.version
      a 'versions', :href => R(Versions, @page.title_url)
    }
  }
  if is_admin?
    div.admin {
      _button 'delete', R(Delete, @page.title_url), {:onclick=>"return confirm('Sure you want to delete?')"} if @version.version == @page.version
      _button 'revert to', R(Revert, @page.title_url, @version.version), {:onclick=>"return confirm('Sure you want to revert?')"} if @version.version != @page.version
    }
  end
end

#userinfoObject



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/junebug/views.rb', line 191

def userinfo
  _header :static
  _body do
    h1 "Edit history: #{@user.username}"
    
    @groups.keys.sort.reverse.each { |key|
      @versions = @groups[key]
      h2 key
      ul {
        @versions.each { |pv|
          li{
            a pv.page.title, :href => R(Show, pv.page.title_url)
            text ", v#{pv.version}"
            text " (#{diff_link(pv.page, pv)}) " if pv.version > 1
            # text' - edited '
            # text last_updated(pv)
            # text ' ago'
          }
        }
      }
    }
  end
  _footer { '' }
end

#usersObject



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/junebug/views.rb', line 175

def users
  _header :static
  _body do
    h1 "Users"
    ul {
      @users.each { |u|
        li {
          a u.username, :href => R(Userinfo, u.username)
          text " - #{u.count} edits"
        }
      }
    }
  end
  _footer { '' }
end

#versionsObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/junebug/views.rb', line 107

def versions
  _header :show
  _body do
    h1 @page_title
    ul {
      @versions.each_with_index do |page,i|
        li {
          a "version #{page.version}", :href => R(Show, @page.title_url, page.version)
          text " (#{diff_link(@page, page)}) " if page.version > 1
          text' - edited '
          text last_updated(page)
          text ' ago by '
          strong page.user.username
          text ' (current)' if @page.version == page.version
        }
      end
    }
  end
  _footer { '' }
end