Class: BooticCli::Themes::FSTheme
- Inherits:
-
Object
- Object
- BooticCli::Themes::FSTheme
show all
- Defined in:
- lib/bootic_cli/themes/fs_theme.rb
Defined Under Namespace
Classes: Template, ThemeAsset
Constant Summary
collapse
- ASSETS_DIR =
'assets'.freeze
- TEMPLATE_PATTERNS =
['*.liquid', '*.html', '*.css', '*.js', 'theme.yml'].freeze
- ASSET_PATTERNS =
[File.join(ASSETS_DIR, '*')].freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(dir, subdomain: nil) ⇒ FSTheme
Returns a new instance of FSTheme.
34
35
36
37
38
|
# File 'lib/bootic_cli/themes/fs_theme.rb', line 34
def initialize(dir, subdomain: nil)
@dir = dir
@setup = false
@subdomain = subdomain
end
|
Class Method Details
.resolve_file(path) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/bootic_cli/themes/fs_theme.rb', line 20
def self.resolve_file(path)
file = File.new(path)
file_name = File.basename(path)
type = resolve_type(path)
item = if path =~ /assets\//
ThemeAsset.new(file_name, file.read, file.mtime.utc)
else
Template.new(file_name, file.read, file.mtime.utc)
end
[item, type]
end
|
.resolve_type(path) ⇒ Object
helper to resolve the right type (Template or Asset) from a local path this is not part of the generic Theme interface
16
17
18
|
# File 'lib/bootic_cli/themes/fs_theme.rb', line 16
def self.resolve_type(path)
path =~ /assets\// ? :asset : :template
end
|
Instance Method Details
#add_asset(file_name, file) ⇒ Object
102
103
104
105
106
107
108
109
110
|
# File 'lib/bootic_cli/themes/fs_theme.rb', line 102
def add_asset(file_name, file)
setup
path = File.join(dir, ASSETS_DIR, file_name)
File.open(path, 'wb') do |io|
io.write file.read
end
@assets = nil
end
|
#add_template(file_name, body) ⇒ Object
85
86
87
88
89
90
91
92
93
|
# File 'lib/bootic_cli/themes/fs_theme.rb', line 85
def add_template(file_name, body)
setup
path = File.join(dir, file_name)
File.open(path, 'w') do |io|
io.write body
end
@templates = nil
end
|
#assets ⇒ Object
75
76
77
78
79
80
81
82
83
|
# File 'lib/bootic_cli/themes/fs_theme.rb', line 75
def assets
@assets ||= (
paths_for(ASSET_PATTERNS).sort.map do |path|
fname = File.basename(path)
file = File.new(path)
ThemeAsset.new(fname, file, file.mtime.utc)
end
)
end
|
#path ⇒ Object
55
56
57
|
# File 'lib/bootic_cli/themes/fs_theme.rb', line 55
def path
File.expand_path(dir)
end
|
#reload! ⇒ Object
Implement generic Theme interface
60
61
62
63
|
# File 'lib/bootic_cli/themes/fs_theme.rb', line 60
def reload!
@templates = nil
@assets = nil
end
|
#remove_asset(file_name) ⇒ Object
112
113
114
115
116
117
118
|
# File 'lib/bootic_cli/themes/fs_theme.rb', line 112
def remove_asset(file_name)
path = File.join(dir, ASSETS_DIR, file_name)
return false unless File.exists?(path)
File.unlink path
@assets = nil
end
|
#remove_template(file_name) ⇒ Object
95
96
97
98
99
100
|
# File 'lib/bootic_cli/themes/fs_theme.rb', line 95
def remove_template(file_name)
path = File.join(dir, file_name)
return false unless File.exists?(path)
File.unlink path
@templates = nil
end
|
#reset! ⇒ Object
50
51
52
53
|
# File 'lib/bootic_cli/themes/fs_theme.rb', line 50
def reset!
return false unless @setup
FileUtils.rm_rf dir
end
|
#subdomain ⇒ Object
40
41
42
|
# File 'lib/bootic_cli/themes/fs_theme.rb', line 40
def subdomain
@subdomain || read_subdomain
end
|
#templates ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/bootic_cli/themes/fs_theme.rb', line 65
def templates
@templates ||= (
paths_for(TEMPLATE_PATTERNS).sort.map do |path|
name = File.basename(path)
file = File.new(path)
Template.new(name, file.read, file.mtime.utc)
end
)
end
|
#write_subdomain ⇒ Object
44
45
46
47
48
|
# File 'lib/bootic_cli/themes/fs_theme.rb', line 44
def write_subdomain
store.transaction do
store['subdomain'] = @subdomain
end
end
|