Module: Junebug::Views

Defined in:
lib/junebug/views.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.feedObject



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/junebug/views.rb', line 279

def self.feed
  xml = Builder::XmlMarkup.new(:indent => 2)

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

    xml.title "Recently Updated Wiki Pages"
    xml.id Junebug.config['url'] + '/'
    xml.link "rel" => "self", "href" => Junebug.config['feed']

    pages = Junebug::Models::Page.find(:all, :order => 'updated_at DESC', :limit => 20)
    xml.updated pages.first.updated_at.xmlschema

    pages.each do |page|
      xml.entry do
        xml.id Junebug.config['url'] + '/' + page.title
        xml.title page.title
        xml.author { xml.name page.user.username }
        xml.updated page.updated_at.xmlschema
        xml.link "rel" => "alternate", "href" => Junebug.config['url'] + '/' + page.title
        xml.summary "#{page.title}"
        xml.content 'type' => 'html' do 
          xml.text! page.body.gsub("\n", '<br/>').gsub("\r", '') 
        end
      end
    end   
  end
end

Instance Method Details

#_bodyObject



252
253
254
255
256
257
258
259
260
261
262
# File 'lib/junebug/views.rb', line 252

def _body
  div :id=>'bd' do
    div :id=>'yui-main' do
      div :class=>'yui-b' do
        div.content do
          yield
        end
      end
    end
  end
end

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



206
207
208
209
210
211
# File 'lib/junebug/views.rb', line 206

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


264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/junebug/views.rb', line 264

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['feed'] do
        img :src => '/static/images/feed-icon-14x14.png'
      end
    end
    yield
    br :clear=>'all'
  end
end

#_header(type, page_title) ⇒ Object



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

def _header type, page_title
  div :id=>'hd' do
    span :id=>'userlinks', :style=>'float: right;' do
      logged_in? ? (text "Welcome, #{@state.user.username} - " ; a('sign out', :href=>"#{R(Logout)}?return_to=#{@env['REQUEST_URI']}")) : a('sign in', :href=> "#{R(Login)}?return_to=#{@env['REQUEST_URI']}")
    end
    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
    span {
      a 'Home',  :href => R(Show, Junebug.config['startpage'])
      text ' | '
      a 'RecentChanges', :href => R(Recent)
      text ' | '
      a 'All Pages', :href => R(List)
      text ' | '
      a 'Help', :href => R(Show, "JunebugHelp") 
    }
  end
end

#_markup(txt) ⇒ Object



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

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


121
122
123
124
125
126
127
128
129
130
# File 'lib/junebug/views.rb', line 121

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

#diffObject



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/junebug/views.rb', line 170

def diff
  _header :show, @page.title
  _body {
    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)
    br
    br
    pre.diff {
        text @difftext
    }
  }
  _footer { '' }
end

#editObject



58
59
60
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
# File 'lib/junebug/views.rb', line 58

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

#layoutObject



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

def layout
  html {
    head {
      title @page_title ? @page_title : @page.title
      link :href=>'/static/style/yui/reset.css', :type=>'text/css', :rel=>'stylesheet'
      link :href=>'/static/style/yui/fonts.css', :type=>'text/css', :rel=>'stylesheet'
      link :href=>'/static/style/yui/grids.css', :type=>'text/css', :rel=>'stylesheet'
      link :href=>'/static/style/base.css',      :type=>'text/css', :rel=>'stylesheet'
      link :href=>Junebug.config['feed'], :rel => "alternate", :title => "Recently Updated Pages", :type => "application/atom+xml"
      
    }
    body {
      div :id=>'doc', :class=>'yui-t7' do
        self << yield
      end
    }
  }
end

#listObject



132
133
134
135
136
137
138
139
140
141
# File 'lib/junebug/views.rb', line 132

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

#loginObject



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/junebug/views.rb', line 188

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

#recentObject



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/junebug/views.rb', line 144

def recent
  _header :static, @page_title
  _body {
    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)
            text ' ('
            a 'versions', :href => R(Versions, page.title)
            text ') '
            span page.updated_at.strftime('%I:%M %p')
          }
          page = @pages.shift
          break unless page && (page.updated_at.yday == yday)
        end
      }
    end
  }
  _footer { '' }
end

#showObject



23
24
25
26
27
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
# File 'lib/junebug/views.rb', line 23

def show
  _header (@version.version == @page.version ? :backlinks : :show), @page.title
  _body {
    _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?))
    _markup @version.body
    _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 > 200)
    br :clear=>'all'
  }
  _footer {
    text "Last edited by <b>#{@version.user.username}</b> on #{@page.updated_at.strftime('%B %d, %Y %I:%M %p')}"
    if @version.version > 1
      text " ("
      a 'diff', :href => R(Diff,@page.title,@version.version-1,@version.version)
      text ")"
    end
    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, @version.version-1) unless @version.version == 1
      a 'newer»', :href => R(Show, @page.title, @version.version+1) unless @version.version == @page.version
      a 'current', :href => R(Show, @page.title) unless @version.version == @page.version
      a 'versions', :href => R(Versions, @page.title)
    }
  }
  if is_admin?
    div.admin {
      _button 'delete', R(Delete, @page.title), {:onclick=>"return confirm('Sure you want to delete?')"} if @version.version == @page.version
      _button 'revert to', R(Revert, @page.title, @version.version), {:onclick=>"return confirm('Sure you want to revert?')"} if @version.version != @page.version
    }
  end
end

#versionsObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/junebug/views.rb', line 96

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