Class: Lanes::Command::GenerateScreen
Constant Summary
collapse
- OPTIONS =
{
title: '',
description: '',
icon: '',
group_id: 'system',
model_class: '',
namespace: nil
}
- ROOT_EL_FUNC =
/rootComponent: \(viewport\) -> null/
Instance Attribute Summary collapse
Attributes inherited from NamedCommand
#class_name, #client_dir, #identifier, #namespace, #spec_dir
Instance Method Summary
collapse
#load_namespace, source_root
Instance Attribute Details
#screen_class ⇒ Object
Returns the value of attribute screen_class.
17
18
19
|
# File 'lib/lanes/command/generate_screen.rb', line 17
def screen_class
@screen_class
end
|
#screen_id ⇒ Object
Returns the value of attribute screen_id.
17
18
19
|
# File 'lib/lanes/command/generate_screen.rb', line 17
def screen_id
@screen_id
end
|
Instance Method Details
#add_definition ⇒ Object
33
34
35
36
37
38
|
# File 'lib/lanes/command/generate_screen.rb', line 33
def add_definition
insert_into_file "config/screens.rb", :after => /Lanes::Screen.for_extension.*?\n/ do
source = File.expand_path(find_in_source_paths("config/screen.rb"))
ERB.new(::File.binread(source), nil, "-","@output_buffer").result(binding)
end
end
|
#create_screen ⇒ Object
26
27
28
29
30
31
|
# File 'lib/lanes/command/generate_screen.rb', line 26
def create_screen
template "client/screens/index.js", "#{client_dir}/screens/#{screen_id}/index.js"
template "client/screens/styles.scss", "#{client_dir}/screens/#{screen_id}/index.scss"
template "client/screens/Screen.cjsx", "#{client_dir}/screens/#{screen_id}/#{class_name}.cjsx"
template "spec/client/Screen.coffee", "#{spec_dir}/screens/#{screen_id}/#{class_name}Spec.coffee"
end
|
#maybe_set_as_default ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/lanes/command/generate_screen.rb', line 42
def maybe_set_as_default
path = "#{client_dir}/Extension.coffee"
content = File.binread(path)
return unless content.match(ROOT_EL_FUNC)
content = "##=require ./screens/#{screen_id}\n\n" + content
content.gsub! ROOT_EL_FUNC, <<-LOADFN.strip_heredoc.chomp
rootComponent: (viewport) ->
# render #{screen_class} by default. If this is changed the
# ##=require ./screens/#{screen_id} at the top of file must also be updated
# to ensure that the correct screen's definition will be available at boot
#{screen_class}
LOADFN
File.open(path, "wb") { |file| file.write(content) }
end
|
#set_variables ⇒ Object
19
20
21
22
23
24
|
# File 'lib/lanes/command/generate_screen.rb', line 19
def set_variables
super
options[:title] = name.titleize if options[:title].blank?
@screen_id = class_name.underscore.dasherize
@screen_class = "#{namespace}.Screens.#{class_name}"
end
|