Class: FluidCLI::Theme::Theme
- Inherits:
-
Root
- Object
- Root
- FluidCLI::Theme::Theme
show all
- Defined in:
- lib/fluid_cli/theme/theme.rb
Instance Attribute Summary collapse
Attributes inherited from Root
#ctx
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Root
#[], #file?, #glob, #json_files, #liquid_files, #static_asset_file?, #static_asset_files, #static_asset_paths
Constructor Details
#initialize(ctx, root: nil, id: nil, name: nil, status: "development") ⇒ Theme
Returns a new instance of Theme.
15
16
17
18
19
20
|
# File 'lib/fluid_cli/theme/theme.rb', line 15
def initialize(ctx, root: nil, id: nil, name: nil, status: "development")
super(ctx, root: root)
@id = id
@name = name
@status = status
end
|
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
13
14
15
|
# File 'lib/fluid_cli/theme/theme.rb', line 13
def id
@id
end
|
#root ⇒ Object
Returns the value of attribute root.
13
14
15
|
# File 'lib/fluid_cli/theme/theme.rb', line 13
def root
@root
end
|
Class Method Details
.all(ctx, root: nil) ⇒ Object
121
122
123
124
125
126
127
|
# File 'lib/fluid_cli/theme/theme.rb', line 121
def all(ctx, root: nil)
_status, body = fetch_themes(ctx)
body['application_themes']
.sort_by { |theme_attrs| Time.parse(theme_attrs["updated_at"]) }
.reverse
.map { |theme_attrs| new(ctx, root: root, **allowed_attrs(theme_attrs)) }
end
|
.create_unpublished(ctx, root: nil, name: nil) ⇒ Object
114
115
116
117
118
119
|
# File 'lib/fluid_cli/theme/theme.rb', line 114
def create_unpublished(ctx, root: nil, name: nil)
name ||= random_name
theme = new(ctx, root: root, name: name, status: "draft")
theme.create
theme
end
|
.find_by_identifier(ctx, root: nil, identifier:) ⇒ Object
Finds a Theme by its identifier
Parameters
ctx - current running context of your command
root - theme root
identifier - theme ID or theme name
139
140
141
142
143
|
# File 'lib/fluid_cli/theme/theme.rb', line 139
def find_by_identifier(ctx, root: nil, identifier:)
find(ctx, root) do |attrs|
attrs.slice("name", "id").values.map(&:to_s).include?(identifier)
end
end
|
.live(ctx, root: nil) ⇒ Object
129
130
131
|
# File 'lib/fluid_cli/theme/theme.rb', line 129
def live(ctx, root: nil)
find(ctx, root) { |attrs| attrs["status"] == "active" }
end
|
Instance Method Details
#company ⇒ Object
30
31
32
|
# File 'lib/fluid_cli/theme/theme.rb', line 30
def company
api_client.get_company_or_abort
end
|
#create ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/fluid_cli/theme/theme.rb', line 58
def create
raise InvalidThemeStatus, "Can't create live theme. Use publish." if live?
_status, body = api_client.post(
path: "application_themes",
body: JSON.generate({
application_theme: {
name: name,
status: status,
},
}),
)
@id = body["application_theme"]["id"]
@created_at_runtime = true
end
|
#created_at_runtime? ⇒ Boolean
99
100
101
|
# File 'lib/fluid_cli/theme/theme.rb', line 99
def created_at_runtime?
@created_at_runtime ||= false
end
|
#current_development? ⇒ Boolean
91
92
93
|
# File 'lib/fluid_cli/theme/theme.rb', line 91
def current_development?
development? && id == FluidCLI::DB.get(:development_theme_id)
end
|
#delete ⇒ Object
76
77
78
|
# File 'lib/fluid_cli/theme/theme.rb', line 76
def delete
delete_theme
end
|
#development? ⇒ Boolean
50
51
52
|
# File 'lib/fluid_cli/theme/theme.rb', line 50
def development?
status == "development"
end
|
#editor_url ⇒ Object
34
35
36
|
# File 'lib/fluid_cli/theme/theme.rb', line 34
def editor_url
"https://admin.fluid.app/themes/#{id}/editor"
end
|
#foreign_development? ⇒ Boolean
95
96
97
|
# File 'lib/fluid_cli/theme/theme.rb', line 95
def foreign_development?
development? && id != FluidCLI::DB.get(:development_theme_id)
end
|
#live? ⇒ Boolean
46
47
48
|
# File 'lib/fluid_cli/theme/theme.rb', line 46
def live?
status == "active"
end
|
#name ⇒ Object
38
39
40
|
# File 'lib/fluid_cli/theme/theme.rb', line 38
def name
@name
end
|
#preview_url ⇒ Object
54
55
56
|
# File 'lib/fluid_cli/theme/theme.rb', line 54
def preview_url
"https://#{company}.fluid.app?preview_theme_id=#{id}"
end
|
#publish ⇒ Object
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/fluid_cli/theme/theme.rb', line 80
def publish
return if live?
api_client.put(
path: "themes/#{id}.json",
body: JSON.generate(theme: {
status: "active",
})
)
@status = "live"
end
|
#status ⇒ Object
42
43
44
|
# File 'lib/fluid_cli/theme/theme.rb', line 42
def status
@status
end
|
#theme_file?(file) ⇒ Boolean
26
27
28
|
# File 'lib/fluid_cli/theme/theme.rb', line 26
def theme_file?(file)
theme_files.include?(self[file])
end
|
#theme_files ⇒ Object
22
23
24
|
# File 'lib/fluid_cli/theme/theme.rb', line 22
def theme_files
(glob(["*.css", "*.json", "**/*.liquid", "**/*.json", "**/*.css"]) - glob(["styleguide/*.liquid", "styleguide/*.css"]) + static_asset_files).uniq
end
|
#to_h ⇒ Object
103
104
105
106
107
108
109
110
111
|
# File 'lib/fluid_cli/theme/theme.rb', line 103
def to_h
{
id: id,
name: name,
status: status,
editor_url: editor_url,
preview_url: preview_url,
}
end
|