Class: LaTeXProjectTemplate::Directory
- Inherits:
-
Object
- Object
- LaTeXProjectTemplate::Directory
- Defined in:
- lib/latex_project_template.rb
Constant Summary collapse
- IGNORE_FILE_REGEXP =
/(\/__IMPORT__$|\/__IGNORE__|~$)/
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #copy_to_directory(target_dir, erb_binding_obj, files = nil) ⇒ Object
- #files_to_import ⇒ Object
-
#initialize(path) ⇒ Directory
constructor
A new instance of Directory.
Constructor Details
#initialize(path) ⇒ Directory
Returns a new instance of Directory.
107 108 109 110 |
# File 'lib/latex_project_template.rb', line 107 def initialize(path) @path = File.(path) @name = File.basename(@path) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
105 106 107 |
# File 'lib/latex_project_template.rb', line 105 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
105 106 107 |
# File 'lib/latex_project_template.rb', line 105 def path @path end |
Instance Method Details
#copy_to_directory(target_dir, erb_binding_obj, files = nil) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/latex_project_template.rb', line 145 def copy_to_directory(target_dir, erb_binding_obj, files = nil) create_directory_if_needed(target_dir) if files file_list = files.map do |file_path| fullpath = File.join(@path, file_path) if File.exist?(fullpath) fullpath else nil end end.compact else file_list = Dir.glob(File.join(@path, '**', '*')).sort end created_files = [] file_list.each do |file| next if IGNORE_FILE_REGEXP =~ file create_directory_if_needed(File.dirname(file)) unless File.directory?(file) case file when /\.erb$/ created = create_erb_template(file, erb_binding_obj, erb_binding_obj.project_name, target_dir) else created = target_path(erb_binding_obj.project_name, target_dir, file) FileUtils.cp(file, created) end created_files << created end end created_files end |
#files_to_import ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/latex_project_template.rb', line 177 def files_to_import import = Hash.new { |h, k| h[k] = [] } import_list_path = File.join(@path, '__IMPORT__') if File.exist?(import_list_path) File.read(import_list_path).each_line do |l| l.strip! if n = l.index('/') k = l.slice!(0...n) import[k] << l[1..-1] end end end import end |