Sha256: 546bf92122196e33f1c8fd75f4233a8e84f86ba65d8f89fce60458ca24bb7535

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

description 'Document browser aspect'
dependencies 'utils/shell'

Aspect.create(:documentbrowser, :priority => 1, :layout => true, :cacheable => true, :accepts => %r{^application/pdf$|postscript$}) do
  def count_pages
    content = @page.content
    page_count = 0
    if @page.mime == 'application/pdf'
      page_count = $1.to_i if Shell.pdfinfo('-').run(content) =~ /Pages:\s+(\d+)/
    else
      content = Shell.cmd($1 == 'gz' ? 'gunzip' : 'bunzip2').run(content) if @page.mime.to_s =~ /(gz|bz)/
      page_count = $1.to_i if content =~ /^%%Pages:\s+(\d+)$/
    end
    page_count
  end

  def call(context, page)
    @page = page
    @page_nr = [context.params[:page].to_i, 1].max
    @page_count = count_pages
    render :browser
  end
end

__END__

@@ browser.slim
= pagination(@page, @page_count, @page_nr, :aspect => 'documentbrowser')
p
  img src=build_path(@page, :aspect => 'image', :geometry => '480x>', :trim => 1, :page => @page_nr)
= pagination(@page, @page_count, @page_nr, :aspect => 'documentbrowser')
h3= :information.t
table
  tbody
    tr
      td= :name.t
      td= @page.name
    tr
      td= :title.t
      td= @page.title
    tr
      td= :description.t
      td= @page.attributes['description']
    - if @page.version
      tr
        td= :last_modified.t
        td= date @page.version.date
      tr
        td= :version.t
        td.version= @page.version
    tr
      td= :type.t
      td= @page.mime.comment.blank? ? @page.mime : "#{@page.mime.comment} (#{@page.mime})"
    tr
      td= :download.t
      td
        a href=build_path(@page, :aspect => 'download') = :download.t

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
olelo-0.9.3 plugins/aspects/documentbrowser.rb
olelo-0.9.2 plugins/aspects/documentbrowser.rb
olelo-0.9.1 plugins/aspects/documentbrowser.rb
olelo-0.9.0 plugins/aspects/documentbrowser.rb