Class: Staticpress::Theme

Inherits:
Object
  • Object
show all
Extended by:
Helpers
Includes:
Helpers
Defined in:
lib/staticpress/theme.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

config, extensionless_basename, extensionless_path, hash_from_array, hash_from_match_data, paginate, settings, spider_map, titleize

Constructor Details

#initialize(name) ⇒ Theme

Returns a new instance of Theme.



10
11
12
13
14
15
16
17
18
# File 'lib/staticpress/theme.rb', line 10

def initialize(name)
  @name = name.to_sym
  custom = Staticpress.blog_path + 'themes' + @name.to_s
  @root = custom.directory? ? custom : Staticpress.root + 'themes' + @name.to_s

  @trail = Hike::Trail.new
  @trail.append_paths custom, Staticpress.root + 'themes' + @name.to_s
  @trail.append_extensions *Tilt.mappings.keys
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/staticpress/theme.rb', line 8

def name
  @name
end

#rootObject (readonly)

Returns the value of attribute root.



8
9
10
# File 'lib/staticpress/theme.rb', line 8

def root
  @root
end

#trailObject (readonly)

Returns the value of attribute trail.



8
9
10
# File 'lib/staticpress/theme.rb', line 8

def trail
  @trail
end

Class Method Details

.themeObject



68
69
70
# File 'lib/staticpress/theme.rb', line 68

def self.theme
  new config.theme
end

Instance Method Details

#==(other) ⇒ Object



20
21
22
# File 'lib/staticpress/theme.rb', line 20

def ==(other)
  other.respond_to?(:name) ? (name == other.name) : super
end

#assetsObject



24
25
26
27
28
29
# File 'lib/staticpress/theme.rb', line 24

def assets
  reply = spider_map (root + 'assets').children do |file|
    file
  end.flatten
  parent ? (parent.assets + reply) : reply
end

#copy_to(name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/staticpress/theme.rb', line 31

def copy_to(name)
  destination = Staticpress.blog_path + 'themes' + name.to_s

  if destination.directory?
    raise Staticpress::Error, "Cannot copy theme. Destination (#{destination}) already exists."
  else
    FileUtils.mkdir_p destination
    FileUtils.cp_r root.children, destination
  end
end

#parentObject



42
43
44
45
46
47
48
49
# File 'lib/staticpress/theme.rb', line 42

def parent
  @parent ||= lambda do
    if config.theme_parent
      reply = self.class.new(config.theme_parent)
      @parent = reply unless self == reply
    end
  end.call
end