Class: Moka::Generators::MokaSiteGenerator

Inherits:
Thor::Group
  • Object
show all
Includes:
SiteTree, Thor::Actions
Defined in:
lib/commands/site/site_generator.rb

Constant Summary

Constants included from SiteTree

SiteTree::RESERVED_NAMES

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



19
20
21
# File 'lib/commands/site/site_generator.rb', line 19

def self.source_root
  File.expand_path('template/', File.dirname(__FILE__))
end

Instance Method Details

#create_app_dirObject



23
24
25
# File 'lib/commands/site/site_generator.rb', line 23

def create_app_dir
  empty_directory(site_name)
end

#create_compiled_dirObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/commands/site/site_generator.rb', line 44

def create_compiled_dir
  unless options[:template].nil?
    directory(File.join(options[:template], 'compiled'), "#{site_name}/compiled")
  else
    empty_directory("#{site_name}/compiled")
    empty_directory("#{site_name}/compiled/javascripts")
    empty_directory("#{site_name}/compiled/images")
    empty_directory("#{site_name}/compiled/stylesheets")
  end
end

#create_manifest_fileObject



55
56
57
58
59
60
61
# File 'lib/commands/site/site_generator.rb', line 55

def create_manifest_file
  unless options[:template].nil?
    template(File.join(options[:template], 'manifest.yml'), File.join("#{site_name}", "manifest.yml"))
  else
    template('manifest.yml', File.join("#{site_name}", "manifest.yml"))
  end
end

#create_project_dirObject



35
36
37
38
39
40
41
42
# File 'lib/commands/site/site_generator.rb', line 35

def create_project_dir
  unless options[:template].nil?
    source_paths << "."
    directory(File.join(options[:template], 'project'), "#{site_name}/project")
  else
    directory('project', "#{site_name}/project")
  end
end

#create_script_dirObject



27
28
29
# File 'lib/commands/site/site_generator.rb', line 27

def create_script_dir
  directory('script', "#{site_name}/script")
end

#set_permissionsObject



31
32
33
# File 'lib/commands/site/site_generator.rb', line 31

def set_permissions
  chmod("#{site_name}/script/moka", 0755)
end

#update_manifest_fileObject



80
81
82
83
84
85
86
87
88
89
# File 'lib/commands/site/site_generator.rb', line 80

def update_manifest_file
  unless options[:template].nil?
    @manifest = YAML.load_file(File.join(site_name, "manifest.yml"))
    @manifest['site']['name'] = site_name
    f = File.open( File.join(site_name, "manifest.yml"), 'w' ) do |out|
      YAML.dump( @manifest, out )
    end
    say_status "update", File.join(site_name, "manifest.yml"), :green
  end
end

#update_variablesObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/commands/site/site_generator.rb', line 63

def update_variables
  unless options[:vars].nil?
    options[:vars].each do |var_name, var_value|
      if Moka::SiteTree::RESERVED_NAMES.include? var_name.to_s
        say_status "WARNING:", "variable '#{var_name}' is a reserved word, and will not be set as a variable", :yellow
      end
    end
    options[:vars].delete_if {|var_name, var_value| Moka::SiteTree::RESERVED_NAMES.include? var_name.to_s }
    @variables = YAML.load_file(File.join(site_name, "project", "site", "variables.yml"))
    @variables.merge! options[:vars]
    f = File.open( File.join(site_name, "project", "site", "variables.yml"), 'w' ) do |out|
      YAML.dump( @variables, out )
    end
    say_status "update", File.join(site_name, "project", "site", "variables.yml"), :green
  end
end