Class: Howdoc::Edition

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#documentObject (readonly)

Returns the value of attribute document.



13
14
15
# File 'lib/howdoc/edition.rb', line 13

def document
  @document
end

#localeObject (readonly)

Returns the value of attribute locale.



13
14
15
# File 'lib/howdoc/edition.rb', line 13

def locale
  @locale
end

Instance Method Details

#dirObject



51
52
53
# File 'lib/howdoc/edition.rb', line 51

def dir
  File.join(Howdoc.config.root, locale.to_s)
end

#headingObject



36
37
38
# File 'lib/howdoc/edition.rb', line 36

def heading
  id.nil? ? title : "#{id}. #{title}"
end

#idObject



20
21
22
# File 'lib/howdoc/edition.rb', line 20

def id
  document.id
end

#image_dirObject



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

#introObject



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


24
25
26
# File 'lib/howdoc/edition.rb', line 24

def permalink
  document.permalink
end

#slugObject

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

#stepsObject



47
48
49
# File 'lib/howdoc/edition.rb', line 47

def steps
  @steps ||= document.steps.map { |step| step.narrate(self) }
end

#titleObject



28
29
30
# File 'lib/howdoc/edition.rb', line 28

def title
  @title ||= document.title_for(locale)
end