-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3040 from raspberrypi/iss-3035
Custom template for integrating book links
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module Slim::Helpers | ||
def book_link | ||
case (self.attr 'booktype') | ||
when 'free' | ||
%(You can <a href="#{self.attr 'link'}" target="_blank">download this book</a> as a PDF file for free, it has been released under a Creative Commons <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" target="_blank">Attribution-NonCommercial-ShareAlike</a> 3.0 Unported (CC BY NC-SA) licence.) | ||
when 'buy' | ||
%(You can <a href="#{self.attr 'link'}" target="_blank">buy this book</a> on the Raspberry Pi Press site.) | ||
when 'donate' | ||
%(You can <a href="#{self.attr 'link'}" target="_blank">download this book</a> for an optional donation on the Raspberry Pi Press site.) | ||
else | ||
return | ||
end | ||
end | ||
|
||
def book_image | ||
src = (self.attr 'image').dup | ||
src = src.gsub(/^image::/, "") | ||
src = src.gsub(/\[.*?\]$/, "") | ||
return src | ||
end | ||
|
||
def section_title | ||
if caption | ||
captioned_title | ||
elsif numbered && level <= (document.attr :sectnumlevels, 3).to_i | ||
if level < 2 && document.doctype == 'book' | ||
case sectname | ||
when 'chapter' | ||
%(#{(signifier = document.attr 'chapter-signifier') ? signifier.to_s + ' ' : ''}#{sectnum} #{title}) | ||
when 'part' | ||
%(#{(signifier = document.attr 'part-signifier') ? signifier.to_s + ' ' : ''}#{sectnum nil, ':'} #{title}) | ||
else | ||
%(#{sectnum} #{title}) | ||
end | ||
else | ||
%(#{sectnum} #{title}) | ||
end | ||
else | ||
title | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
- sect0 = level == 0 | ||
- if sect0 | ||
*{tag: %(h#{level + 1}), id: id, class: ('sect0' if sect0)} | ||
- if id && (document.attr? :sectanchors) | ||
a.anchor href="##{id}" | ||
=section_title | ||
- elsif id && (document.attr? :sectlinks) | ||
a.link href="##{id}" =section_title | ||
- else | ||
=section_title | ||
=content | ||
- else | ||
div class=[%(sect#{level}), role] | ||
*{tag: %(h#{level + 1}), id: id, class: ('sect0' if sect0)} | ||
- if id && (document.attr? :sectanchors) | ||
a.anchor href="##{id}" | ||
=section_title | ||
- elsif id && (document.attr? :sectlinks) | ||
a.link href="##{id}" =section_title | ||
- else | ||
=section_title | ||
- if level == 1 | ||
.sectionbody | ||
- if role? 'booklink' | ||
div class="openblock float-group" | ||
div class="content" | ||
- if attr 'image' | ||
div class="imageblock related thumb right" | ||
div class="content" | ||
a href=(attr 'link') target='_blank' class='image' | ||
img src=(book_image) | ||
=content | ||
div class="paragraph" | ||
p =book_link | ||
- else | ||
=content | ||
- else | ||
- if role? 'booklink' | ||
div class="openblock float-group" | ||
div class="content" | ||
- if attr 'image' | ||
div class="imageblock related thumb right" | ||
div class="content" | ||
a href=(attr 'link') target='_blank' class='image' | ||
img src=(book_image) | ||
=content | ||
div class="paragraph" | ||
p =book_link | ||
- else | ||
=content |