Class: DcBookRenderer
- Inherits:
-
DcRenderer
- Object
- DcRenderer
- DcBookRenderer
- Includes:
- DcApplicationHelper
- Defined in:
- app/helpers/dc_book_renderer.rb
Instance Method Summary collapse
-
#chapter ⇒ Object
chapter.
-
#list ⇒ Object
List all books.
-
#render_html ⇒ Object
render html.
-
#toc ⇒ Object
Table of contents.
Instance Method Details
#chapter ⇒ Object
chapter
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 'app/helpers/dc_book_renderer.rb', line 59 def chapter html = '' # texts = DcBookChapter.where(_id: @parent.params[:book_id], active: true).sort(chapter: 1).to_a book = DcBook.find_by(link: @parent.params[:book_id]) chapter = DcBookChapter.find_by(dc_book_id: book.id, link: @parent.params[:chapter_id]) if chapter prev_chapter = DcBookChapter.where(dc_book_id: book._id, :chapter.lt => chapter.chapter) .order_by(chapter: -1).limit(1).first next_chapter = DcBookChapter.where(dc_book_id: book._id, :chapter.gt => chapter.chapter) .order_by(chapter: 1).limit(1).first else prev_chapter, next_chapter = nil, nil end # if @opts[:edit_mode] > 1 html << dc_link_for_create({ controller: 'cmsedit', table: 'dc_book_chapter;dc_book_text', ids: chapter._id, title: t('dc_book.new_text') }) ( { "dc_book_text.author" => chapter. } ) if chapter end # if chapter texts = chapter.dc_book_texts.where(active: true).to_a if texts.size > 0 replies = chapter.dc_replies.where(active: true).order(created_at: 1). page(@parent.params[:page]).per(20) versions = texts.inject([]) {|r,e| r << [e.version, e._id] } # display specific version when text_id is specified text = @parent.params[:text_id] ? chapter.dc_book_texts.find(@parent.params[:text_id]) : texts.last html << @parent.render( partial: 'dc_book/chapter', locals: { chapter: chapter, replies: replies, text: text, versions: versions, prev_chapter: prev_chapter, next_chapter: next_chapter}, formats: [:html] ) end end html end |
#list ⇒ Object
List all books
33 34 35 36 37 38 39 40 |
# File 'app/helpers/dc_book_renderer.rb', line 33 def list html = '' if @opts[:edit_mode] > 1 html << dc_link_for_create({ controller: 'cmsedit', table: 'dc_book', title: t('dc_book.new_book') }) end books = DcBook.where(active: true).sort(title: 1).to_a html << @parent.render( partial: 'dc_book/list', locals: { books: books }, formats: [:html] ) end |
#render_html ⇒ Object
render html
98 99 100 101 |
# File 'app/helpers/dc_book_renderer.rb', line 98 def render_html method = @parent.params[:method] || 'list' respond_to?(method) ? send(method) : "Error DcBook: Method #{method} doesn't exist!" end |
#toc ⇒ Object
Table of contents
45 46 47 48 49 50 51 52 53 54 |
# File 'app/helpers/dc_book_renderer.rb', line 45 def toc html = '' if @opts[:edit_mode] > 1 ( { "dc_book_chapter.dc_book_id" => @parent.params[:book_id] } ) html << dc_link_for_create({ controller: 'cmsedit', table: 'dc_book_chapter', title: t('dc_book.new_chapter') }) end book = DcBook.find_by(link: @parent.params[:book_id]) chapters = DcBookChapter.where(dc_book_id: book._id, active: true).sort(chapter: 1).to_a html << @parent.render( partial: 'dc_book/toc', locals: { chapters: chapters, book: book }, formats: [:html] ) end |