32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/wp_scaffold/generator.rb', line 32
def create_custom_post_type(cpt_name)
new_cpt = File.read(file_base + "/templates/custom_post_type/register-cpt.php")
new_cpt = new_cpt.gsub("___CPT_CAPITALIZED___", cpt_name.titleize)
new_cpt = new_cpt.gsub("___CPT_UNDERSCORED___", cpt_name.to_underscore)
new_cpt = new_cpt.gsub("___CPT_CAPITALIZED_PLURAL___", cpt_name.titleize.pluralize)
new_cpt = new_cpt.gsub("___CPT_DOWNCASE_PLURAL___", cpt_name.pluralize.downcase)
File.open(current_dir + "/functions/custom-post-type.php", 'a') {|f| f.write(new_cpt) }
page_template = File.read(file_base + "/templates/custom_post_type/page-custom.php")
page_template = page_template.gsub("___CPT_NAME_DASHED_PLURAL___", cpt_name.pluralize.to_underscore.dasherize)
page_template = page_template.gsub("___CPT_NAME___", cpt_name.titleize)
page_template = page_template.gsub("___CPT_NAME_PLURAL___", cpt_name.pluralize.titleize)
page_template = page_template.gsub("___CPT_NAME_UNDERSCORED___", cpt_name.to_underscore)
File.open(current_dir + "/page-" + cpt_name.pluralize.to_underscore.dasherize + ".php", 'w') {|f| f.write(page_template) }
single_template = File.read(file_base + "/templates/custom_post_type/single-custom.php")
single_template = single_template.gsub("___CPT_NAME_DASHED___", cpt_name.to_underscore.dasherize)
single_template = single_template.gsub("___CPT_NAME___", cpt_name.titleize)
File.open(current_dir + "/single-" + cpt_name.to_underscore.dasherize + ".php", 'w') {|f| f.write(single_template) }
puts "Created new post type '#{cpt_name.pluralize}'."
end
|