Class: Moka::Generators::MokaGroupGenerator
- Includes:
- SiteTree, Thor::Actions
- Defined in:
- lib/commands/group/group_generator.rb
Constant Summary
Constants included from SiteTree
Class Method Summary collapse
Instance Method Summary collapse
- #create_group_dir_and_files ⇒ Object
- #delete_variables_using_reserved_name ⇒ Object
- #dump_variables ⇒ Object
- #load_manifest ⇒ Object
- #notify_about_creation ⇒ Object
- #update_manifest ⇒ Object
- #verify_if_group_exists ⇒ Object
Class Method Details
.source_root ⇒ Object
19 20 21 |
# File 'lib/commands/group/group_generator.rb', line 19 def self.source_root File.('template/', File.dirname(__FILE__)) end |
Instance Method Details
#create_group_dir_and_files ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/commands/group/group_generator.rb', line 59 def create_group_dir_and_files unless [:template].nil? directory(File.("project/site/#{@template_group}", MOKA_ROOT), File.("project/site/#{@group}", MOKA_ROOT)) else directory("groupdir", File.("project/site/#{@group}", MOKA_ROOT)) end end |
#delete_variables_using_reserved_name ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/commands/group/group_generator.rb', line 67 def delete_variables_using_reserved_name unless [:vars].nil? [: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 [:vars].delete_if {|var_name, var_value| Moka::SiteTree::RESERVED_NAMES.include? var_name.to_s } end end |
#dump_variables ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/commands/group/group_generator.rb', line 78 def dump_variables if File.exists? File.("project/site/#{@group}/variables.yml", MOKA_ROOT) @group_variables = YAML.load_file(File.("project/site/#{@group}/variables.yml", MOKA_ROOT)) else @group_variables = {} end unless [:vars].nil? @group_variables.merge! [:vars] f = File.open( File.("project/site/#{@group}/variables.yml", MOKA_ROOT), 'w' ) do |out| YAML.dump( @group_variables, out ) end say_status "update", "project/site/#{@group}/variables.yml", :green end end |
#load_manifest ⇒ Object
23 24 25 26 |
# File 'lib/commands/group/group_generator.rb', line 23 def load_manifest @manifest = YAML.load_file(File.("manifest.yml", MOKA_ROOT)) @site = SiteNode.new("site", @manifest["site"]) end |
#notify_about_creation ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/commands/group/group_generator.rb', line 93 def notify_about_creation say "" if [:template].nil? say "Generated group #{@group}" else say "Generated group #{@group} using group #{@template_group} as a template" end say "" say " Group Parameters:" @group_params.each do |param_name, param_value| say " #{param_name} = #{param_value}" end say "" say " Group Variables:" @group_variables.each do |var_name, var_value| puts " #{var_name} = #{var_value}" end say "" end |
#update_manifest ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/commands/group/group_generator.rb', line 36 def update_manifest unless [:template].nil? @template_group = [:template] if @site.find_group(@template_group).nil? say_status "ERROR:", "cannot find group '#{@template_group}'", :red exit end template_manifest = Moka::Utilities.deepcopy(@manifest["site"][@template_group]) @site.find_group(@template_group).pages.each do |page| template_manifest[page.name]["path"] = File.join "#{@group}", "#{page.name}.#{@site.respond_to?(:default_extension) ? @site.default_extension : "html"}" end else template_manifest = {} end @group_params = {"order" => Time.new.utc.to_i} @manifest["site"][@group] = template_manifest.merge @group_params # dump manifest f = File.open( File.('manifest.yml', MOKA_ROOT), 'w' ) do |out| YAML.dump( @manifest, out ) end say_status "update", "manifest.yml", :green end |
#verify_if_group_exists ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/commands/group/group_generator.rb', line 28 def verify_if_group_exists @group = name unless @site.find_group(@group).nil? say_status "ERROR:", "group '#{@group}' already exists!", :red exit end end |