Class: Wpgen::FileWriter
- Inherits:
-
Object
- Object
- Wpgen::FileWriter
- Defined in:
- lib/wpgen/file_writer.rb
Constant Summary collapse
- @@initial_folder_list =
["css", "inc", "js"]
- @@initial_file_list =
[ "css/reset.css", "css/ie.css", "inc/meta.php", "inc/nav.php", "inc/paging.php", "js/functions.js", "404.php", "archive.php", "comments.php", "footer.php", "functions.php", "header.php", "index.php", "page.php", "screenshot.png", "search.php", "searchform.php", "sidebar.php", "style.css" ]
- @@write_css_ignore =
["functions.php"]
- @@templates_dir =
File.("../../templates", File.dirname(__FILE__))
Class Method Summary collapse
- .new_theme(folder_name) ⇒ Object
- .write_css(file) ⇒ Object
- .write_custom_post_type(type) ⇒ Object
- .write_dynamic_sidebar(sidebar_name) ⇒ Object
- .write_page_template(template_name) ⇒ Object
- .write_stylesheet ⇒ Object
Class Method Details
.new_theme(folder_name) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/wpgen/file_writer.rb', line 30 def self.new_theme folder_name mkdir "#{folder_name}" @@initial_folder_list.each do |folder| mkdir "#{folder_name}/#{folder}" end @@initial_file_list.each do |file| mkfile file, @@templates_dir, folder_name end end |
.write_css(file) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/wpgen/file_writer.rb', line 98 def self.write_css file stylesheet = File.open("style.css", "a") ids = get_ids_from_file file c = get_classes_from_file file stylesheet.puts CssGen.generate_id_css(ids) stylesheet.puts CssGen.generate_class_css(c) puts "Write selectors from #{file} to style.css" end |
.write_custom_post_type(type) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/wpgen/file_writer.rb', line 42 def self.write_custom_post_type type php_code = Generator.custom_post_type type File.open("post-type-#{type}.php", "w") do |f| f.puts php_code end File.open("functions.php", "r+") do |f| php_code = f.read php_code.gsub!(/\/\/ WPGEN custom post types/, "// WPGEN custom post types\nrequire_once 'post-type-#{type}.php'") f.close FileUtils.remove_file "functions.php" File.open("functions.php", "w") do |f| f.puts php_code end end puts "Create file post-type-#{type}.php" puts "Change functions.php" end |
.write_dynamic_sidebar(sidebar_name) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/wpgen/file_writer.rb', line 73 def self. = Generator. File.open("functions.php", "r+") do |f| functions_code = f.read functions_code.gsub!(/\/\/ WPGEN register sidebars/, "// WPGEN register sidebars\n#{}") f.close FileUtils.remove_file "functions.php" File.open("functions.php", "w") do |f| f.puts functions_code end end puts "Change file functions.php" end |
.write_page_template(template_name) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/wpgen/file_writer.rb', line 63 def self.write_page_template template_name php_code = Generator.page_template template_name File.open("page-template-#{template_name}.php", "w") do |f| f.puts php_code end puts "Create file page-template-#{template_name}.php" end |
.write_stylesheet ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/wpgen/file_writer.rb', line 89 def self.write_stylesheet File.open("style.css", "a") do |stylesheet| ids, c = get_all_css_selectors stylesheet.puts CssGen.generate_id_css(ids) stylesheet.puts CssGen.generate_class_css(c) puts "Write selectors to style.css" end end |