Module: Junebug::Views

Defined in:
lib/junebug/views.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.feedObject



276
277
278
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
# File 'lib/junebug/views.rb', line 276

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



249
250
251
252
253
254
255
256
257
258
259
# File 'lib/junebug/views.rb', line 249

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

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



203
204
205
206
207
208
# File 'lib/junebug/views.rb', line 203

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


261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/junebug/views.rb', line 261

def _footer
  div :id=>'ft' do
    span :style=>'float: right;' do
      text 'Powered by '
      a 'JunebugWiki', :href => 'http://www.junebugwiki.com/'
      text ' '
      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



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

def _header type, page_title
  div :id=>'hd' do
    span :id=>'userlinks', :style=>'float: right;' do
      @state.user_id.blank? ? a('sign in', :href=>R(Login)) : (text "Welcome, #{@state.user_username} - " ; a('sign out', :href=>R(Logout)))
    end
    if type == :static
      h1 page_title
    elsif type == :show
      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



210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/junebug/views.rb', line 210

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(txt, [ ]).to_html
end


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

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

#diffObject



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

def diff
  _header :backlinks, @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
    div.diff {
      text @difftext
    }
  }
  _footer { '' }
end

#editObject



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

def edit
  _header :backlinks, @page.title
  _body {
    div.content {
      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 " [ CamelCase only ]"
          }
          p {
            label 'Page Content'
            br
            textarea @page.body, :name => 'post_body', :rows => 17, :cols => 80
          }
          if @state.user_id == 1
            opts = { :type => 'checkbox', :value=>'1', :name => 'post_readonly' }
            opts[:checked] = 1 if @page.readonly
            input opts
            text " Readonly"
            br
          end
          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



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

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

#loginObject



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

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 :type => 'submit', :name => 'login', :value => 'Login'
    end
  }
end

#recentObject



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

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

def show
  _header (@version.version == @page.version ? :show : :backlinks), @page.title
  _body {
    div.content {
      _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))
      _markup @version.body
      _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)
    }
  }
  _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 (@state.user_id == 1)
    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



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

def versions
  _header :backlinks, @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