Module: Docfu::Skeleton
- Defined in:
- lib/docfu/skeleton.rb
Class Method Summary collapse
-
.files_location ⇒ Object
The location of the files folder.
-
.generate_info_yml(config) ⇒ String
Takes an info hash and converts it into it’s yaml equivalent config.yml.
-
.setup_directory_structure(folder) ⇒ Object
Sets up a new directory structure for a document project.
-
.setup_readme(project) ⇒ Object
Sets up the README for the project.
-
.templates_location ⇒ Object
The location of the templates folder.
-
.write_config_yml(project) ⇒ Object
Writes the config.yml if it’s missing for the current project, otherwise it returns early.
-
.write_info_yml(project, info) ⇒ Object
Writes the info.yml if it’s missing for the current project, otherwise it returns early.
Class Method Details
.files_location ⇒ Object
The location of the files folder.
16 17 18 |
# File 'lib/docfu/skeleton.rb', line 16 def files_location File.join(File.(File.dirname(__FILE__)), 'files') end |
.generate_info_yml(config) ⇒ String
Takes an info hash and converts it into it’s yaml equivalent config.yml.
54 55 56 57 58 59 60 61 62 |
# File 'lib/docfu/skeleton.rb', line 54 def generate_info_yml(config) sane_config = config.inject({}) {|res, (k,v)| res[k.to_s] = v; res } sane_config['author'] ||= 'author' sane_config['title'] ||= 'title' sane_config['exclude'] = sane_config['exclude'].split(",") info_erb_file = "#{templates_location}/info.yml.erb" info_template = ERB.new(IO.read(info_erb_file), 0, '<>') info_template.result(binding) end |
.setup_directory_structure(folder) ⇒ Object
Sets up a new directory structure for a document project.
7 8 9 10 11 12 13 |
# File 'lib/docfu/skeleton.rb', line 7 def setup_directory_structure(folder) Dir.mkdir(folder) unless Dir.exists? folder %w( figures figures-dia figures-source en ).each do |fold| Dir.mkdir("#{folder}/#{fold}") unless Dir.exists? "#{folder}/#{fold}" end setup_readme(folder) end |
.setup_readme(project) ⇒ Object
Sets up the README for the project.
28 29 30 31 32 33 34 35 36 |
# File 'lib/docfu/skeleton.rb', line 28 def setup_readme(project) readme_erb_file = "#{templates_location}/README.md.erb" readme_template = ERB.new(IO.read(readme_erb_file), 0, '<>') unless File.exists? "#{project}/README.md" File.open("#{project}/README.md", 'w') { |f| f.write(readme_template.result(binding)) } end end |
.templates_location ⇒ Object
The location of the templates folder.
21 22 23 |
# File 'lib/docfu/skeleton.rb', line 21 def templates_location File.join(File.(File.dirname(__FILE__)), 'templates') end |
.write_config_yml(project) ⇒ Object
Writes the config.yml if it’s missing for the current project, otherwise it returns early.
40 41 42 43 44 45 46 47 |
# File 'lib/docfu/skeleton.rb', line 40 def write_config_yml(project) config_file = "#{project}/config.yml" unless File.exists? config_file puts "Creating config.yml..." cfg = File.open("#{files_location}/config.yml", 'r').read File.open(config_file, 'w') { |f| f.write(cfg) } end end |
.write_info_yml(project, info) ⇒ Object
Writes the info.yml if it’s missing for the current project, otherwise it returns early.
68 69 70 71 72 73 74 |
# File 'lib/docfu/skeleton.rb', line 68 def write_info_yml(project, info) unless File.exists? "#{project}/info.yml" puts "Creating info.yml..." inf = generate_info_yml(info) File.open("#{project}/info.yml", 'w') { |f| f.write(inf) } end end |