Class: Yuzu::Content::SampleProject

Inherits:
Object
  • Object
show all
Defined in:
lib/yuzu/content/sample_project.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sample_project_name) ⇒ SampleProject

Returns a new instance of SampleProject.



19
20
21
22
23
24
25
26
27
# File 'lib/yuzu/content/sample_project.rb', line 19

def initialize(sample_project_name)
  @name = sample_project_name

  if SampleProject.registered_projects.has_key?(@name)
    @project_info = SampleProject.registered_projects[@name]
  else
    raise ProjectNotFound, "#{@name} is not a known sample project."
  end
end

Class Method Details

.destination_folderObject



122
123
124
# File 'lib/yuzu/content/sample_project.rb', line 122

def self.destination_folder
  Dir.pwd
end

.exists?(sample_project_name) ⇒ Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/yuzu/content/sample_project.rb', line 130

def self.exists?(sample_project_name)
  registered_projects.has_key?(sample_project_name)
end

.project_folder_nameObject



126
127
128
# File 'lib/yuzu/content/sample_project.rb', line 126

def self.project_folder_name
  File.basename(destination_folder)
end

.registered_projectsObject



11
12
13
# File 'lib/yuzu/content/sample_project.rb', line 11

def self.registered_projects
  @@registry ||= YAML.load_file(registry_file)
end

.registry_fileObject



15
16
17
# File 'lib/yuzu/content/sample_project.rb', line 15

def self.registry_file
  File.join(resources_folder, "sample_projects.yml")
end

.resources_folderObject



118
119
120
# File 'lib/yuzu/content/sample_project.rb', line 118

def self.resources_folder
  File.join(File.dirname(__FILE__), "..", "..", "..", "resources")
end

.sample_content_folderObject



114
115
116
# File 'lib/yuzu/content/sample_project.rb', line 114

def self.sample_content_folder
  File.join(resources_folder, "sample_content")
end

.theme_folderObject



110
111
112
# File 'lib/yuzu/content/sample_project.rb', line 110

def self.theme_folder
  File.join(resources_folder, "themes")
end

Instance Method Details

#copy_config!Object



61
62
63
64
65
# File 'lib/yuzu/content/sample_project.rb', line 61

def copy_config!
  config_folder = File.join(SampleProject.resources_folder, "config")
  copy_folder!(config_folder)
  post_process_config!
end

#copy_content!Object



52
53
54
55
56
57
58
59
# File 'lib/yuzu/content/sample_project.rb', line 52

def copy_content!
  content_folder = File.join(SampleProject.sample_content_folder, sample_content_name)
  if File.exists?(content_folder)
    copy_folder_contents!(content_folder)
  else
    throw SampleContentNotFound, "#{sample_content_name} is not a known set of sample content."
  end
end

#copy_folder!(folder_name) ⇒ Object



67
68
69
# File 'lib/yuzu/content/sample_project.rb', line 67

def copy_folder!(folder_name)
  FileUtils.cp_r(folder_name, SampleProject.destination_folder)
end

#copy_folder_contents!(folder) ⇒ Object



71
72
73
74
# File 'lib/yuzu/content/sample_project.rb', line 71

def copy_folder_contents!(folder)
  source = File.join(folder, "*")
  FileUtils.cp_r(Dir[source], SampleProject.destination_folder)
end

#copy_theme!Object



43
44
45
46
47
48
49
50
# File 'lib/yuzu/content/sample_project.rb', line 43

def copy_theme!
  theme_folder = File.join(SampleProject.theme_folder, theme_name)
  if File.exists?(theme_folder)
    copy_folder_contents!(theme_folder)
  else
    throw ThemeNotFound, "#{theme_name} is not a known theme."
  end
end

#deliver!Object



29
30
31
32
33
# File 'lib/yuzu/content/sample_project.rb', line 29

def deliver!
  copy_theme!
  copy_content!
  copy_config!
end

#load_new_config!(destination_config_path) ⇒ Object



98
99
100
# File 'lib/yuzu/content/sample_project.rb', line 98

def load_new_config!(destination_config_path)
  @new_config ||= YAML.load_file(destination_config_path)
end

#new_configObject



102
103
104
105
106
107
108
# File 'lib/yuzu/content/sample_project.rb', line 102

def new_config
  if @new_config.nil?
    raise ConfigNotFound, "New config file not found."
  else
    @new_config
  end
end

#post_process_config!Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/yuzu/content/sample_project.rb', line 76

def post_process_config!
  destination_config = File.join(SampleProject.destination_folder, "config", "yuzu.yml")
  if File.exists?(destination_config)
    user_home_folder = File.expand_path("~")
    username = Etc.getlogin

    config_contents = File.read(destination_config)

    config_contents.gsub!("HOME", user_home_folder)
    config_contents.gsub!("USERNAME", username)
    config_contents.gsub!("PROJECTFOLDER", SampleProject.project_folder_name)

    File.open(destination_config, "w") do |config|
      config.puts(config_contents)
    end

    load_new_config!(destination_config)
  else
    raise ConfigNotFound, "The yuzu.yml file wasn't found in the expected place: #{destination_config}."
  end
end

#sample_content_nameObject



39
40
41
# File 'lib/yuzu/content/sample_project.rb', line 39

def sample_content_name
  @project_info['content']
end

#theme_nameObject



35
36
37
# File 'lib/yuzu/content/sample_project.rb', line 35

def theme_name
  @project_info['theme']
end