Class: Rabbit::Theme::Entry

Inherits:
Object
  • Object
show all
Extended by:
ERB::DefMethod
Includes:
ERB::Util, Enumerable, GetText
Defined in:
lib/rabbit/theme/entry.rb

Direct Known Subclasses

DirectoryEntry, SingleFileEntry

Constant Summary collapse

PROPERTY_BASE_NAME =
"property"
@@template_last_modified_time =
nil

Constants included from GetText

GetText::DOMAIN

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GetText

N_, _, bindtextdomain, locale=

Constructor Details

#initialize(theme_dir, name) ⇒ Entry

Returns a new instance of Entry.



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rabbit/theme/entry.rb', line 50

def initialize(theme_dir, name)
  @logger = nil
  @theme_dir = theme_dir
  @name = name
  @title = @name
  @category = nil
  @abstract = nil
  @description = nil
  @dependencies = []
  @parameters = {}
  parse_property if available?
end

Instance Attribute Details

#abstractObject (readonly)

Returns the value of attribute abstract.



46
47
48
# File 'lib/rabbit/theme/entry.rb', line 46

def abstract
  @abstract
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



47
48
49
# File 'lib/rabbit/theme/entry.rb', line 47

def dependencies
  @dependencies
end

#descriptionObject (readonly)

Returns the value of attribute description.



45
46
47
# File 'lib/rabbit/theme/entry.rb', line 45

def description
  @description
end

#loggerObject

Returns the value of attribute logger.



48
49
50
# File 'lib/rabbit/theme/entry.rb', line 48

def logger
  @logger
end

#nameObject (readonly)

Returns the value of attribute name.



45
46
47
# File 'lib/rabbit/theme/entry.rb', line 45

def name
  @name
end

#parametersObject (readonly)

Returns the value of attribute parameters.



47
48
49
# File 'lib/rabbit/theme/entry.rb', line 47

def parameters
  @parameters
end

#titleObject (readonly)

Returns the value of attribute title.



45
46
47
# File 'lib/rabbit/theme/entry.rb', line 45

def title
  @title
end

Class Method Details

.load_template(path = nil) ⇒ Object



28
29
30
31
32
# File 'lib/rabbit/theme/entry.rb', line 28

def load_template(path=nil)
  path ||= template_path
  @@template_last_modified_time = File.mtime(path)
  def_erb_method("to_rd", path)
end

.reload_template(path = nil) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/rabbit/theme/entry.rb', line 34

def reload_template(path=nil)
  path ||= template_path
  if @@template_last_modified_time < File.mtime(path)
    remove_method("to_rd")
    load_template(path)
  end
end

.template_pathObject



19
20
21
22
23
24
25
26
# File 'lib/rabbit/theme/entry.rb', line 19

def template_path
  path = ["rabbit", "theme", "document.erb"]
  template_path = Utils.find_path_in_load_path(*path)
  if template_path.nil?
    raise CantFindThemeRDTemplate.new(File.join(*path))
  end
  template_path
end

Instance Method Details

#<=>(other) ⇒ Object



75
76
77
# File 'lib/rabbit/theme/entry.rb', line 75

def <=>(other)
  @name <=> other.name
end

#available?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/rabbit/theme/entry.rb', line 63

def available?
  File.readable?(theme_file)
end

#categoryObject



87
88
89
# File 'lib/rabbit/theme/entry.rb', line 87

def category
  @category || N_("Etc")
end

#filesObject



95
96
97
98
99
100
# File 'lib/rabbit/theme/entry.rb', line 95

def files
  rejected_files = [theme_file, property_file]
  Dir[File.join(@theme_dir, "*")].delete_if do |name|
    rejected_files.include?(name)
  end.sort
end

#full_path(target) ⇒ Object



83
84
85
# File 'lib/rabbit/theme/entry.rb', line 83

def full_path(target)
  File.join(@theme_dir, target)
end

#have_file?(target) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/rabbit/theme/entry.rb', line 79

def have_file?(target)
  File.exist?(full_path(target))
end

#image_theme?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/rabbit/theme/entry.rb', line 91

def image_theme?
  false
end

#property_editable?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/rabbit/theme/entry.rb', line 67

def property_editable?
  File.writable?(property_file)
end

#theme_fileObject



71
72
73
# File 'lib/rabbit/theme/entry.rb', line 71

def theme_file
  File.join(@theme_dir, "#{@name}.rb")
end