Class: Pocketbook::Theme
- Inherits:
-
Object
show all
- Defined in:
- lib/pocketbook/theme.rb,
lib/pocketbook/theme/manifest.rb
Defined Under Namespace
Classes: AssetPaths, Location, Manifest
Constant Summary
collapse
- DEFAULT_MANIFEST =
"theme.yml"
- DEFAULT_TEMPLATE_CANDIDATES =
["template.html.erb", "layout.html.erb"].freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(theme_path:, style: nil, template_override: nil, cwd: Dir.pwd) ⇒ Theme
Returns a new instance of Theme.
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
# File 'lib/pocketbook/theme.rb', line 211
def initialize(theme_path:, style: nil, template_override: nil, cwd: Dir.pwd)
location = Location.new(theme_reference: theme_path, cwd: cwd)
@root_path = location.root_path
@manifest = location.manifest_path ? Manifest.new(path: location.manifest_path) : nil
assets = AssetPaths.new(
root_path: @root_path,
manifest: @manifest,
style: style,
template_override: template_override
)
@template_path = assets.template_path
@style_name = assets.style_name
@style_paths = assets.style_paths
@available_styles = assets.available_styles
end
|
Instance Attribute Details
#available_styles ⇒ Object
Returns the value of attribute available_styles.
185
186
187
|
# File 'lib/pocketbook/theme.rb', line 185
def available_styles
@available_styles
end
|
#root_path ⇒ Object
Returns the value of attribute root_path.
185
186
187
|
# File 'lib/pocketbook/theme.rb', line 185
def root_path
@root_path
end
|
#style_name ⇒ Object
Returns the value of attribute style_name.
185
186
187
|
# File 'lib/pocketbook/theme.rb', line 185
def style_name
@style_name
end
|
#style_paths ⇒ Object
Returns the value of attribute style_paths.
185
186
187
|
# File 'lib/pocketbook/theme.rb', line 185
def style_paths
@style_paths
end
|
#template_path ⇒ Object
Returns the value of attribute template_path.
185
186
187
|
# File 'lib/pocketbook/theme.rb', line 185
def template_path
@template_path
end
|
Class Method Details
.path_reference?(value) ⇒ Boolean
257
258
259
260
261
262
|
# File 'lib/pocketbook/theme.rb', line 257
def self.path_reference?(value)
return true if value.start_with?("~", ".", "/")
separators = [File::SEPARATOR, File::ALT_SEPARATOR].compact.uniq
separators.any? { |separator| value.include?(separator) }
end
|
.resolve_theme_path(theme_reference, cwd: Dir.pwd) ⇒ Object
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/pocketbook/theme.rb', line 195
def self.resolve_theme_path(theme_reference, cwd: Dir.pwd)
reference = theme_reference.to_s.strip
return File.expand_path(reference, cwd) if path_reference?(reference)
project_theme_path = File.expand_path(File.join("themes", reference), cwd)
return project_theme_path if theme_location_exists?(project_theme_path)
user_theme_path = Pocketbook.user_themes_path(reference)
return user_theme_path if theme_location_exists?(user_theme_path)
bundled_path = Pocketbook.bundled_theme_path(reference)
return bundled_path if theme_location_exists?(bundled_path)
File.expand_path(reference, cwd)
end
|
.supported_manifest_defaults ⇒ Object
.supported_manifest_fields ⇒ Object
.theme_location_exists?(path) ⇒ Boolean
264
265
266
|
# File 'lib/pocketbook/theme.rb', line 264
def self.theme_location_exists?(path)
File.directory?(path) || File.file?(path)
end
|
Instance Method Details
241
242
243
244
245
|
# File 'lib/pocketbook/theme.rb', line 241
def defaults_metadata
return {} unless @manifest
@manifest.defaults_metadata
end
|
#name ⇒ Object
228
229
230
231
232
233
|
# File 'lib/pocketbook/theme.rb', line 228
def name
default_name = File.basename(root_path)
return default_name unless @manifest
@manifest.name(default_name)
end
|
#styles_css ⇒ Object
251
252
253
|
# File 'lib/pocketbook/theme.rb', line 251
def styles_css
style_paths.map { |path| File.read(path) }.join("\n\n")
end
|
#template_source ⇒ Object
247
248
249
|
# File 'lib/pocketbook/theme.rb', line 247
def template_source
File.read(template_path)
end
|
#version ⇒ Object
235
236
237
238
239
|
# File 'lib/pocketbook/theme.rb', line 235
def version
return "0.1.0" unless @manifest
@manifest.version
end
|