Class: Howdoc::Edition
- Inherits:
-
Object
- Object
- Howdoc::Edition
- Defined in:
- lib/howdoc/edition.rb
Overview
One language's version of a guide.
A guide is recorded once -- the same clicks, the same screenshots -- and written out once per language. Everything that differs between those versions is here: the heading, the sentences, the directory the page lands in and the names of the pictures in it. A template is handed the edition for the language being written, so nothing in a template has to know that a second language exists.
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
Instance Method Summary collapse
- #dir ⇒ Object
- #heading ⇒ Object
- #id ⇒ Object
- #image_dir ⇒ Object
- #image_filename(number) ⇒ Object
-
#initialize(document, locale) ⇒ Edition
constructor
A new instance of Edition.
- #intro ⇒ Object
- #path(extension) ⇒ Object
- #permalink ⇒ Object
-
#slug ⇒ Object
A permalink is the same in every language, so the guides sit beside each other under one name.
- #steps ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(document, locale) ⇒ Edition
Returns a new instance of Edition.
15 16 17 18 |
# File 'lib/howdoc/edition.rb', line 15 def initialize(document, locale) @document = document @locale = locale.to_sym end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
13 14 15 |
# File 'lib/howdoc/edition.rb', line 13 def document @document end |
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
13 14 15 |
# File 'lib/howdoc/edition.rb', line 13 def locale @locale end |
Instance Method Details
#dir ⇒ Object
51 52 53 |
# File 'lib/howdoc/edition.rb', line 51 def dir File.join(Howdoc.config.root, locale.to_s) end |
#heading ⇒ Object
36 37 38 |
# File 'lib/howdoc/edition.rb', line 36 def heading id.nil? ? title : "#{id}. #{title}" end |
#id ⇒ Object
20 21 22 |
# File 'lib/howdoc/edition.rb', line 20 def id document.id end |
#image_dir ⇒ Object
55 56 57 |
# File 'lib/howdoc/edition.rb', line 55 def image_dir File.join(dir, 'images') end |
#image_filename(number) ⇒ Object
63 64 65 |
# File 'lib/howdoc/edition.rb', line 63 def image_filename(number) "#{slug}_#{number}.png" end |
#intro ⇒ Object
32 33 34 |
# File 'lib/howdoc/edition.rb', line 32 def intro @intro ||= document.intro_for(locale) end |
#path(extension) ⇒ Object
59 60 61 |
# File 'lib/howdoc/edition.rb', line 59 def path(extension) File.join(dir, "#{slug}.#{extension}") end |
#permalink ⇒ Object
24 25 26 |
# File 'lib/howdoc/edition.rb', line 24 def permalink document.permalink end |
#slug ⇒ Object
A permalink is the same in every language, so the guides sit beside each other under one name. Without one the file is named after the heading, which means a translated heading gives a translated file name.
43 44 45 |
# File 'lib/howdoc/edition.rb', line 43 def slug @slug ||= (permalink || Document.slugify(title)).to_s end |
#steps ⇒ Object
47 48 49 |
# File 'lib/howdoc/edition.rb', line 47 def steps @steps ||= document.steps.map { |step| step.narrate(self) } end |
#title ⇒ Object
28 29 30 |
# File 'lib/howdoc/edition.rb', line 28 def title @title ||= document.title_for(locale) end |