Module: Isomorfeus::Installer::DSL

Included in:
Gemfile, NewProject, Target::Web, TestAppFiles
Defined in:
lib/isomorfeus/installer/dsl.rb

Instance Method Summary collapse

Instance Method Details

#config_path(config_file) ⇒ Object



67
68
69
# File 'lib/isomorfeus/installer/dsl.rb', line 67

def config_path(config_file)
  File.join('config', config_file)
end

#copy_file(from, to) ⇒ Object



4
5
6
7
# File 'lib/isomorfeus/installer/dsl.rb', line 4

def copy_file(from, to)
  puts "Copying #{from} to #{to}."
  FileUtils.copy(from, to)
end

#create_common_framework_directoriesObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/isomorfeus/installer/dsl.rb', line 27

def create_common_framework_directories
  # no created: handlers
  %w[channels components data layouts locales mail_components operations policies server].each do |isomorfeus_dir|
    create_directory(File.join('app', isomorfeus_dir))
  end
  create_directory('storage')
  create_directory('public')
  create_directory('spec')
  create_directory('config')
end

#create_directory(directory) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/isomorfeus/installer/dsl.rb', line 9

def create_directory(directory)
  unless Dir.exist?(directory)
    puts "Creating directory #{directory}."
    FileUtils.mkdir_p(directory)
    FileUtils.touch(File.join(directory, '.keep'))
  end
end

#create_file_from_template(templates_path, template_file, target_file_path, data_hash) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/isomorfeus/installer/dsl.rb', line 17

def create_file_from_template(templates_path, template_file, target_file_path, data_hash)
  template = ERB.new(File.read(File.join(templates_path, template_file), mode: 'r'))
  result = template.result_with_hash(data_hash)
  ext = File.exist?(target_file_path) ? '_new' : ''
  puts "Generating #{target_file_path + ext}."
  File.write(target_file_path + ext, result, mode: 'w')
  keep_file = File.join(File.dirname(target_file_path), '.keep')
  File.delete(keep_file) if File.exist?(keep_file)
end

#install_basic_componentsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/isomorfeus/installer/dsl.rb', line 38

def install_basic_components
  data_hash = { app_class: Isomorfeus::Installer.app_class }
  create_file_from_template(Isomorfeus::Installer.templates_path, 'my_app.rb.erb',
                            File.join('app', 'components', Isomorfeus::Installer.app_class.underscore + '.rb'), data_hash)
  create_file_from_template(Isomorfeus::Installer.templates_path,'hello_component.rb.erb',
                            File.join('app', 'components', 'hello_component.rb'), {})
  create_file_from_template(Isomorfeus::Installer.templates_path, 'navigation_links.rb.erb',
                            File.join('app', 'components', 'navigation_links.rb'), {})
  create_file_from_template(Isomorfeus::Installer.templates_path, 'not_found_404_component.rb.erb',
                            File.join('app', 'components', 'not_found_404_component.rb'), {})
  create_file_from_template(Isomorfeus::Installer.templates_path, 'welcome_component.rb.erb',
                            File.join('app', 'components', 'welcome_component.rb'), {})
end

#install_basic_policyObject



52
53
54
55
# File 'lib/isomorfeus/installer/dsl.rb', line 52

def install_basic_policy
  create_file_from_template(Isomorfeus::Installer.templates_path, 'anonymous_policy.rb.erb',
                            File.join('app', 'policies', 'anonymous_policy.rb'), {})
end

#install_rake_fileObject



57
58
59
# File 'lib/isomorfeus/installer/dsl.rb', line 57

def install_rake_file
  create_file_from_template(Isomorfeus::Installer.templates_path, 'Rakefile.erb', 'Rakefile', {})
end

#install_spec_filesObject



61
62
63
64
65
# File 'lib/isomorfeus/installer/dsl.rb', line 61

def install_spec_files
  data_hash = { roda_app_class: Isomorfeus::Installer.roda_app_class, roda_app_path: Isomorfeus::Installer.roda_app_path,
                rack_server: Isomorfeus::Installer.rack_server_name }
  create_file_from_template(Isomorfeus::Installer.templates_path, 'spec_helper.rb.erb', File.join('spec', 'spec_helper.rb'), data_hash)
end