Class: WpScaffold::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/wp_scaffold/generator.rb

Instance Method Summary collapse

Instance Method Details

#create_custom_post_type(cpt_name) ⇒ Object



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)
	# Grab out template, and use it to create our cpt object
	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)

	# Append the new custom post type "custom-post-types.php". Crate the file if it doesn't already exist.
	File.open(current_dir + "/functions/custom-post-type.php", 'a') {|f| f.write(new_cpt) }


	# Create the Page Template
	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) }


	# Create the Single 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

#create_theme(theme_name) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/wp_scaffold/generator.rb', line 3

def create_theme(theme_name)
	theme_name = 'New Theme' if theme_name.nil?

	if File.directory?(current_dir + "/" + theme_name.to_underscore)
		puts "There is already a theme called #{theme_name}."
	else

		# Copy the directory
		cp_r file_base + "/templates/theme_base", current_dir + "/"

		# Rename it
    File.rename current_dir + "/theme_base", current_dir + "/" + theme_name.to_underscore


    # Add the name of the theme to the files, where necessary
    file_names = ['style.css', 'styles/style.scss']

		file_names.each do |file_name|
			file_name = current_dir + "/" + theme_name.to_underscore + "/" + file_name
		  file_text = File.read(file_name).gsub("___THEME_NAME___", theme_name)
		  File.open(file_name, "w") {|file| file.puts file_text}
		end

		puts "Created the theme #{theme_name}. run 'cd #{theme_name.to_underscore}'."
	end
end

#usageObject



65
66
67
68
69
# File 'lib/wp_scaffold/generator.rb', line 65

def usage
file = File.open("#{File.expand_path(File.dirname(__FILE__))}/usage.txt", "rb")
puts file.read
file.close
end