Class: Yuzu::Core::WebsiteBase

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/yuzu/core/website_base.rb

Direct Known Subclasses

WebsiteFile, WebsiteFolder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, parent) ⇒ WebsiteBase

Returns a new instance of WebsiteBase.



9
10
11
12
13
14
15
16
17
# File 'lib/yuzu/core/website_base.rb', line 9

def initialize(path, parent)
  raise "WebsiteBase not initialized with a Path object." if not path.is_a?(Path)

  @path = path
  raise "@path is nil for #{self}" if @path.nil?
  @parent = parent
  @kind = nil
  @stash = {}
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



7
8
9
# File 'lib/yuzu/core/website_base.rb', line 7

def kind
  @kind
end

#parentObject (readonly)

Returns the value of attribute parent.



7
8
9
# File 'lib/yuzu/core/website_base.rb', line 7

def parent
  @parent
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/yuzu/core/website_base.rb', line 7

def path
  @path
end

Instance Method Details

#==(other) ⇒ Object



19
20
21
22
# File 'lib/yuzu/core/website_base.rb', line 19

def == (other)
  return false if not other.is_a?(WebsiteBase)
  return @path == other.path
end

#asset?Boolean

Returns:

  • (Boolean)


89
90
91
92
# File 'lib/yuzu/core/website_base.rb', line 89

def asset?
  return false if folder?
  config.asset?(@path)
end

#blog_folderObject



36
37
38
# File 'lib/yuzu/core/website_base.rb', line 36

def blog_folder
  @@blog ||= root.find_file_by_path(Path.new(config.blog_dir))
end

#childrenObject



64
65
66
# File 'lib/yuzu/core/website_base.rb', line 64

def children
  nil
end

#configObject



52
53
54
# File 'lib/yuzu/core/website_base.rb', line 52

def config
  @parent.config
end

#default_stashObject



131
132
133
134
135
136
# File 'lib/yuzu/core/website_base.rb', line 131

def default_stash
  {
    :generated_siblings => [],
    :catalog => nil
  }
end

#file?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/yuzu/core/website_base.rb', line 56

def file?
  @kind == :file
end

#folder?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/yuzu/core/website_base.rb', line 60

def folder?
  @kind == :folder
end

#generated?Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/yuzu/core/website_base.rb', line 144

def generated?
  false
end


111
112
113
# File 'lib/yuzu/core/website_base.rb', line 111

def get_link_url
  folder? ? (currentpath + "index.html") : (currentpath + output_filename).full
end

#get_remote_pathObject



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/yuzu/core/website_base.rb', line 119

def get_remote_path
  if processable?
    tr = file? ? @path.with_extension(extension) : @path
    if tr == @path
      raise "Remote path and source path are the same! Got #{tr} and #{@path}."
    end
    tr
  else
    @path
  end
end

#hidden?Boolean

Returns:

  • (Boolean)


94
95
96
97
# File 'lib/yuzu/core/website_base.rb', line 94

def hidden?
  return false if root?
  @parent.hidden? or @path.rootname[0].chr == "_"
end

#image?Boolean

Returns:

  • (Boolean)


84
85
86
87
# File 'lib/yuzu/core/website_base.rb', line 84

def image?
  return false if folder?
  config.image?(@path)
end

#in_blog?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/yuzu/core/website_base.rb', line 40

def in_blog?
  blog_folder.nil? ? false : blog_folder.is_child?(self)
end

#index?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/yuzu/core/website_base.rb', line 48

def index?
  false
end

#is_blog?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/yuzu/core/website_base.rb', line 44

def is_blog?
  self == blog_folder or (index? and self.path.dirname == blog_folder.path.dirname)
end

#is_processable?Boolean

Returns:

  • (Boolean)


72
73
74
75
76
77
# File 'lib/yuzu/core/website_base.rb', line 72

def is_processable?
  return false if folder?
  config_says = config.processable?(@path)
  translators_say = Yuzu::Translators::Translator.can_translate?(self)
  config_says and translators_say
end


103
104
105
# File 'lib/yuzu/core/website_base.rb', line 103

def link_to_self(attr={})
  Html::Link.new({:href => link_url}.merge(attr)) << name
end


107
108
109
# File 'lib/yuzu/core/website_base.rb', line 107

def link_url
  @link_url ||= get_link_url
end

#nameObject



24
25
26
# File 'lib/yuzu/core/website_base.rb', line 24

def name
  @path.basename
end

#processable?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/yuzu/core/website_base.rb', line 68

def processable?
  @processable ||= is_processable?
end

#remote_pathObject



115
116
117
# File 'lib/yuzu/core/website_base.rb', line 115

def remote_path
  @remote_path ||= get_remote_path
end

#resource?Boolean

Returns:

  • (Boolean)


79
80
81
82
# File 'lib/yuzu/core/website_base.rb', line 79

def resource?
  return false if folder?
  config.resource?(@path)
end

#rootObject



28
29
30
# File 'lib/yuzu/core/website_base.rb', line 28

def root
  @root ||= (@parent.nil? ? self : @parent.root)
end

#root?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/yuzu/core/website_base.rb', line 32

def root?
  root == self
end

#stash(kwds = {}) ⇒ Object

Enables other processes to add imbue this node with information.



139
140
141
142
# File 'lib/yuzu/core/website_base.rb', line 139

def stash(kwds={})
  @stash = default_stash if @stash.nil?
  kwds.empty? ? @stash : @stash.update(kwds)
end