wp_scaffold 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -0
  3. data/.rspec +2 -0
  4. data/Guardfile +8 -0
  5. data/README.md +9 -1
  6. data/bin/wp +19 -8
  7. data/lib/.DS_Store +0 -0
  8. data/lib/wp_scaffold.rb +27 -8
  9. data/lib/wp_scaffold/helpers/text_helpers.rb +19 -0
  10. data/lib/wp_scaffold/models/generator.rb +43 -0
  11. data/lib/wp_scaffold/models/generators/custom_post_type.rb +26 -0
  12. data/lib/wp_scaffold/models/generators/setting.rb +14 -0
  13. data/lib/wp_scaffold/models/generators/theme.rb +21 -0
  14. data/lib/wp_scaffold/templates/custom_post_type/custom-post-types/custom.php +30 -0
  15. data/lib/wp_scaffold/templates/custom_post_type/page-custom.php.erb +38 -0
  16. data/lib/wp_scaffold/templates/custom_post_type/single-custom.php.erb +25 -0
  17. data/lib/wp_scaffold/templates/setting/wp_scaffold_settings.txt.erb +1 -0
  18. data/lib/wp_scaffold/templates/{theme_base → theme/custom_theme}/README.md +1 -1
  19. data/lib/wp_scaffold/templates/{theme_base → theme/custom_theme}/category.php +0 -0
  20. data/lib/wp_scaffold/templates/{theme_base → theme/custom_theme}/footer.php +0 -0
  21. data/lib/wp_scaffold/templates/{theme_base → theme/custom_theme}/front-page.php +0 -0
  22. data/lib/wp_scaffold/templates/{theme_base → theme/custom_theme}/functions.php +8 -4
  23. data/lib/wp_scaffold/templates/{theme_base → theme/custom_theme}/functions/breadcrumbs.php +0 -0
  24. data/lib/wp_scaffold/templates/{theme_base → theme/custom_theme}/header.php +6 -5
  25. data/lib/wp_scaffold/templates/{theme_base → theme/custom_theme}/home.php +0 -0
  26. data/lib/wp_scaffold/templates/{theme_base → theme/custom_theme}/index.php +0 -0
  27. data/lib/wp_scaffold/templates/theme/custom_theme/js/main.js +7 -0
  28. data/lib/wp_scaffold/templates/{theme_base → theme/custom_theme}/js/vendor/fastclick.js +0 -0
  29. data/lib/wp_scaffold/templates/{theme_base → theme/custom_theme}/js/vendor/html5shiv.js +0 -0
  30. data/lib/wp_scaffold/templates/{theme_base → theme/custom_theme}/js/vendor/jquery.easydropdown.min.js +0 -0
  31. data/lib/wp_scaffold/templates/{theme_base → theme/custom_theme}/js/vendor/retina-1.1.0.min.js +0 -0
  32. data/lib/wp_scaffold/templates/{theme_base → theme/custom_theme}/page.php +0 -0
  33. data/lib/wp_scaffold/templates/{theme_base → theme/custom_theme}/partials/content-post.php +0 -0
  34. data/lib/wp_scaffold/templates/{theme_base → theme/custom_theme}/screenshot.png +0 -0
  35. data/lib/wp_scaffold/templates/{theme_base → theme/custom_theme}/single.php +0 -0
  36. data/lib/wp_scaffold/templates/theme/custom_theme/style.css +7 -0
  37. data/lib/wp_scaffold/usage.txt +2 -1
  38. data/lib/wp_scaffold/version.rb +1 -1
  39. data/spec/models/cpt_spec.rb +38 -0
  40. data/spec/models/generator_spec.rb +38 -0
  41. data/spec/models/setting_spec.rb +33 -0
  42. data/spec/models/theme_spec.rb +35 -0
  43. data/spec/spec_helper.rb +31 -0
  44. data/spec/templates/files/php/test_file_3.php.erb +5 -0
  45. data/spec/templates/files/test_file_1.txt +1 -0
  46. data/spec/templates/files/test_file_2.txt.erb +1 -0
  47. data/spec/wp_scaffold_spec.rb +34 -0
  48. data/wp_scaffold.gemspec +4 -1
  49. metadata +95 -36
  50. data/lib/wp_scaffold/generator.rb +0 -81
  51. data/lib/wp_scaffold/helper.rb +0 -11
  52. data/lib/wp_scaffold/templates/.DS_Store +0 -0
  53. data/lib/wp_scaffold/templates/custom_post_type/page-custom.php +0 -50
  54. data/lib/wp_scaffold/templates/custom_post_type/register-cpt.php +0 -31
  55. data/lib/wp_scaffold/templates/custom_post_type/single-custom.php +0 -18
  56. data/lib/wp_scaffold/templates/theme_base/.gitignore +0 -2
  57. data/lib/wp_scaffold/templates/theme_base/coffee/main.coffee +0 -2
  58. data/lib/wp_scaffold/templates/theme_base/functions/theme-settings.php +0 -60
  59. data/lib/wp_scaffold/templates/theme_base/js/main.js +0 -2
  60. data/lib/wp_scaffold/templates/theme_base/style.css +0 -211
  61. data/lib/wp_scaffold/templates/theme_base/styles/_base.scss +0 -36
  62. data/lib/wp_scaffold/templates/theme_base/styles/_grid.scss +0 -327
  63. data/lib/wp_scaffold/templates/theme_base/styles/_normalize.scss +0 -410
  64. data/lib/wp_scaffold/templates/theme_base/styles/style.scss +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06fe1a92e4d783512c5bf8286ed739f76096a240
4
- data.tar.gz: 90292acf0118bd3ac7059b9f66575f1ae39ca3dd
3
+ metadata.gz: f3259ed6d80ad20ca9cd01fd10fd0990dc3a1d3a
4
+ data.tar.gz: 055a0a68033f19d322b13f8762c6a9241f30942c
5
5
  SHA512:
6
- metadata.gz: 93c1b62872f453ee357f7b93e7996ad49850a6ef785ea7076954a50b0ff4438f6f4c26fd64e23edb8236e9cf5978ddd5af0f16e8b7de2be03007561565509b9e
7
- data.tar.gz: cadec653f0c8b076efacc21303c44c523e87b9acf942dafefd80e38d4c939cf7a6972e11b197e2637d9ea46d82b1101a060642db077349670c45f9c8c9e72c78
6
+ metadata.gz: b741424ac3512def6466410ddc01d416bc2b46b326b708babe65fe0941cf3d1b5416975fa4e8ae8efe3f84b8ddf4c47b146f7fa50baf434c62e04fe0546cf050
7
+ data.tar.gz: be945ac5ed5f5916e29107aba3ed4c52b5a25a84bbaefe9417f1dc44d79d3d6e307a0f0783535f6b1aa99d49a365756409f19aec02b6c011c8b256d6d5fe50b2
data/.gitignore CHANGED
@@ -15,3 +15,9 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .DS_Store
19
+ spec/tmp
20
+
21
+ single-custom.php
22
+ page-custom.php
23
+ /custom-post-types
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
data/README.md CHANGED
@@ -2,13 +2,15 @@
2
2
 
3
3
  Scaffold commands for Wordpress theme development.
4
4
 
5
+ #### THIS IS A WORK IN PROGRESS AND IS NOT READY FOR ACTIVE THEME DEVELOPMENT.
6
+
5
7
  ## Installation
6
8
 
7
9
  ```$ gem install wp_scaffold```
8
10
 
9
11
  ## Usage
10
12
 
11
- To create a new theme:
13
+ To create a new theme, navigate to your wp-content/themes directory and type:
12
14
 
13
15
  ```wp new "theme name"```
14
16
 
@@ -20,6 +22,12 @@ To create a custom post type:
20
22
 
21
23
  Make sure that your custom post type name is singular; wp_scaffold with take care of pluralizing it for you.
22
24
 
25
+ ## Customization
26
+
27
+ Every developer seems to have their own way of setting up a WP project. If you would like to use your own template files, copy down the `lib/wp_scaffold/templates` directory to use as a guide. You can insert the Theme (or custom post type) name using Ruby's ERB templating.
28
+
29
+ Once you have your templates ready to go, open terminal and type `wp set_template_path path/to/your/templates` (the path should be relative to your User's home folder). wp_scaffold will now use your custom templates, rather than the defaults.
30
+
23
31
  ## Contributing
24
32
 
25
33
  1. Fork it
data/bin/wp CHANGED
@@ -1,18 +1,29 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'wp_scaffold'
4
+ require 'colorize'
4
5
 
5
6
  case ARGV[0]
6
7
 
7
8
  when "new"
8
- gen = WpScaffold::Generator.new
9
- # Pass the theme name as ARGV[1]
10
- gen.create_theme(ARGV[1])
9
+ theme = Theme.new(ARGV[1])
10
+ theme.generate
11
+ puts "Created #{theme.name.titleize}.".green
12
+ puts "Type 'cd #{theme.name.to_underscore}'"
13
+
11
14
  when "cpt"
12
- gen = WpScaffold::Generator.new
13
- # Pass the theme name as ARGV[1]
14
- gen.create_custom_post_type(ARGV[1])
15
+ cpt = CustomPostType.new(ARGV[1])
16
+ cpt.generate
17
+ puts "Added post type: #{cpt.name.titleize}.".green
18
+
19
+ when "set_template_path"
20
+ setting = Setting.new(ARGV[1])
21
+ setting.generate
22
+ puts "Set template source directory to '#{setting.user_path_setting}'".green
23
+
15
24
  else
16
- message = WpScaffold::Generator.new
17
- message.usage
25
+ # Output usage instructinos
26
+ file = File.open("#{File.expand_path(File.dirname(__FILE__))}/../lib/wp_scaffold/usage.txt", "rb")
27
+ puts file.read
28
+ file.close
18
29
  end
Binary file
@@ -1,12 +1,31 @@
1
+ # Version Info
1
2
  require "wp_scaffold/version"
2
- require 'fileutils'
3
- include FileUtils
3
+
4
+ # Ruby Dependancies
5
+ require 'fileutils'
6
+ require 'erb'
7
+ require 'active_support/inflector'
8
+
9
+ # Include custom helpers
10
+ Dir[File.dirname(__FILE__) + "/wp_scaffold/helpers/**/*.rb"].each {|file| require file }
4
11
 
5
12
  module WpScaffold
6
- # Require our Generator class
7
- require 'wp_scaffold/generator'
8
- # Require Active Support Inflector to help with semantics
9
- require 'active_support/inflector'
10
- # Require out custom helpers
11
- require 'wp_scaffold/helper'
13
+ class Base
14
+
15
+ # set the path to our root template folder
16
+ if File.exists?(File.expand_path('~')+"/wp_scaffold_settings.txt")
17
+ # user the user's settings file
18
+ TEMPLATE_BASE = ENV['HOME'] + "/" + File.read(ENV['HOME']+"/wp_scaffold_settings.txt") + "/"
19
+ else
20
+ # user the gem's default templates
21
+ TEMPLATE_BASE = File.expand_path(File.dirname(__FILE__)) + "/wp_scaffold/templates/"
22
+ end
23
+
24
+ # The User's current directory
25
+ USER_DIRECTORY = Dir.pwd + "/"
26
+
27
+ # Include all generator classes
28
+ Dir[File.dirname(__FILE__) + "/wp_scaffold/models/**/*.rb"].each {|file| require file }
29
+
30
+ end
12
31
  end
@@ -0,0 +1,19 @@
1
+ class String
2
+
3
+ def to_underscore
4
+ self.gsub(/::/, '/').
5
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
6
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
7
+ tr("- ", "_").
8
+ downcase
9
+ end
10
+
11
+ def to_dash
12
+ self.gsub(/::/, '/').
13
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
14
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
15
+ tr("_ ", "-").
16
+ downcase
17
+ end
18
+
19
+ end
@@ -0,0 +1,43 @@
1
+ class Generator < WpScaffold::Base
2
+
3
+ attr_accessor :template_path, :destination, :name, :relative_to_cwd
4
+
5
+ def generate
6
+ # Path to our template folder
7
+ source = TEMPLATE_BASE + self.template_path
8
+
9
+ # For each file in the template source directory
10
+ Dir.glob("#{source}/**/*").each do |file|
11
+ unless File.directory?(file)
12
+
13
+ @generator = self
14
+
15
+ # template file, plus template directories
16
+ file_name = file.split(source)[1]
17
+
18
+ # full path to where the file will be written, including file name
19
+ # Should this be relative to the current working directory?
20
+ if @generator.relative_to_cwd == true
21
+ full_destination = USER_DIRECTORY + self.destination + "/" + file_name
22
+ else
23
+ full_destination = self.destination + "/" + file_name
24
+ end
25
+
26
+ # full path to where the file will be written, without file name
27
+ file_directory = File.dirname(full_destination)
28
+
29
+ # Create the directory, if needed
30
+ unless File.directory?(file_directory)
31
+ FileUtils.mkdir_p(file_directory)
32
+ end
33
+
34
+ # complile the erb template, remove the .erb extention, and write to a new file
35
+ File.open(full_destination.gsub('.erb', ''), 'w') do |f|
36
+ f.write ERB.new(open(file).read).result(binding)
37
+ end
38
+
39
+ end
40
+ end # each
41
+ end # generate
42
+
43
+ end
@@ -0,0 +1,26 @@
1
+ class CustomPostType < Generator
2
+
3
+ DEFAULT_NAME = "custom-post"
4
+
5
+ def generate
6
+ super
7
+ base_path = USER_DIRECTORY + self.destination
8
+
9
+ # Rename the register CPT file
10
+ File.rename(base_path + "/custom-post-types/custom.php", base_path + "/custom-post-types/" + self.name.to_dash + ".php")
11
+
12
+ # Rename the CPT's template files
13
+ File.rename(base_path + "/page-custom.php", base_path + "/page-" + self.name.to_dash + ".php")
14
+ File.rename(base_path + "/single-custom.php", base_path + "/single-" + self.name.to_dash + ".php")
15
+ end
16
+
17
+ private
18
+
19
+ def initialize(cpt_name = nil)
20
+ self.name = cpt_name.nil? ? DEFAULT_NAME : cpt_name.downcase
21
+ self.destination = ""
22
+ self.template_path = "custom_post_type"
23
+ self.relative_to_cwd = true
24
+ end
25
+
26
+ end
@@ -0,0 +1,14 @@
1
+ class Setting < Generator
2
+
3
+ attr_accessor :user_path_setting
4
+
5
+ private
6
+
7
+ def initialize(user_path = nil)
8
+ self.user_path_setting = user_path
9
+ self.destination = File.expand_path('~')
10
+ self.template_path = "setting"
11
+ self.relative_to_cwd == false
12
+ end
13
+
14
+ end
@@ -0,0 +1,21 @@
1
+ class Theme < Generator
2
+
3
+ DEFAULT_NAME = "my new theme"
4
+
5
+ def generate
6
+ super
7
+ # rename the theme's root folder
8
+ base_path = USER_DIRECTORY + self.destination
9
+ File.rename(base_path + "/custom_theme", base_path + "/" + self.name.to_underscore)
10
+ end
11
+
12
+ private
13
+
14
+ def initialize(theme_name = nil)
15
+ self.name = theme_name.nil? ? DEFAULT_NAME : theme_name.downcase
16
+ self.destination = ""
17
+ self.template_path = "theme"
18
+ self.relative_to_cwd = true
19
+ end
20
+
21
+ end
@@ -0,0 +1,30 @@
1
+ <?php
2
+
3
+ // Register <%= @generator.name.titleize %>
4
+ add_action('init', 'create_<%= @generator.name.to_underscore %>_post_type');
5
+ function create_<%= @generator.name.to_underscore %>_post_type() {
6
+ register_post_type( '<%= @generator.name.to_dash %>',
7
+ array(
8
+ 'labels' => array(
9
+ 'name' => __( '<%= @generator.name.pluralize.titleize %>' ),
10
+ 'singular_name' => __( '<%= @generator.name.titleize %>' ),
11
+ 'add_new' => __( 'Add New <%= @generator.name.titleize %>' ),
12
+ 'add_new_item' => __( 'Add New <%= @generator.name.titleize %>' ),
13
+ 'edit_item' => __( 'Edit <%= @generator.name.titleize %>' ),
14
+ 'new_item' => __( 'Add New <%= @generator.name.titleize %>' ),
15
+ 'view_item' => __( 'View <%= @generator.name.titleize %>' ),
16
+ 'search_items' => __( 'Search <%= @generator.name.pluralize.titleize %>' ),
17
+ 'not_found' => __( 'No <%= @generator.name.pluralize.downcase %> found' ),
18
+ 'not_found_in_trash' => __( 'No <%= @generator.name.pluralize.downcase %> found in trash'),
19
+ 'menu_name' => __( '<%= @generator.name.pluralize.titleize %>' ),
20
+ ),
21
+ 'public' => true,
22
+ 'rewrite' => array('slug' => '<%= @generator.name.to_dash %>'),
23
+ //'taxonomies' => array('category'),
24
+ 'publicly_queryable' => true,
25
+ 'supports' => array('title', 'editor', 'page-attributes')
26
+ )
27
+ );
28
+ }
29
+
30
+ ?>
@@ -0,0 +1,38 @@
1
+ <?php
2
+ /*
3
+ Template Name: <%= @generator.name.titleize %> Page
4
+ */
5
+ ?>
6
+
7
+ <?php get_header(); ?>
8
+
9
+
10
+ <!-- This is the page-<%= @generator.name.to_dash %>.php file, a page tempalte for listing <%= @generator.name.titleize %> posts -->
11
+
12
+
13
+ <?php
14
+ // List all posts with type "<%= @generator.name.to_dash %>"
15
+ $args = array(
16
+ 'post_type' => '<%= @generator.name.to_dash %>'
17
+ );
18
+
19
+ $custom_query = new WP_Query( $args );
20
+ ?>
21
+
22
+ <!-- Start Loop -->
23
+ <?php if ( have_posts() ) : while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
24
+
25
+ <!--List the posts -->
26
+ <?php the_title(); ?>
27
+ <a href="<?php the_permalink(); ?>"><?php the_permalink(); ?></a>
28
+ <hr>
29
+
30
+ <?php endwhile; else: ?>
31
+
32
+ <p>No Posts to display!</p>
33
+
34
+ <?php endif; ?>
35
+ <!-- End Loop -->
36
+
37
+
38
+ <?php get_footer(); ?>
@@ -0,0 +1,25 @@
1
+ <?php get_header(); ?>
2
+
3
+ <!-- This is the single-<%= @generator.name.to_dash %>.php file, which acts as a template for a single "<%= @generator.name.titleize %>" post type -->
4
+
5
+ <!-- Start Loop -->
6
+ <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
7
+
8
+ <!-- Content for this post -->
9
+ <?php the_title(); ?>
10
+
11
+ <hr>
12
+
13
+ <?php the_post_thumbnail(); ?>
14
+
15
+ <?php the_content(); ?>
16
+
17
+ <?php endwhile; else: ?>
18
+
19
+ <p>No Posts to display!</p>
20
+
21
+ <?php endif; ?>
22
+ <!-- End Loop -->
23
+
24
+
25
+ <?php get_footer(); ?>
@@ -0,0 +1 @@
1
+ <%= @generator.user_path_setting %>
@@ -1,4 +1,4 @@
1
- Wordpress-Boilerplate
1
+ <%= @generator.name.titleize %>
2
2
  =====================
3
3
 
4
4
  Blank theme with basic Wordpress functions included.
@@ -1,7 +1,6 @@
1
1
  <?php
2
2
 
3
3
  # Enable custom menus
4
- add_theme_support( 'menus' );
5
4
  register_nav_menus( array(
6
5
  'header_menu' => 'Header Menu',
7
6
  'footer_menu' => 'Footer Menu'
@@ -14,7 +13,7 @@
14
13
 
15
14
  # Stylesheets
16
15
  function theme_styles() {
17
- wp_enqueue_style( 'main', get_template_directory_uri() . '/style.css' );
16
+ wp_enqueue_style( 'main', get_template_directory_uri() . '/style.css' );
18
17
  }
19
18
  add_action( 'wp_enqueue_scripts', 'theme_styles' );
20
19
 
@@ -37,8 +36,13 @@
37
36
 
38
37
 
39
38
  # Include all PHP files from "functions" directory
40
- foreach ( glob("functions/*.php") as $filename ) {
41
- include $filename;
39
+ foreach ( glob(dirname(__FILE__)."/functions/*.php") as $filename ) {
40
+ include_once $filename;
41
+ }
42
+
43
+ # Include all PHP files from "custom-post-types" directory
44
+ foreach ( glob(dirname(__FILE__)."/custom-post-types/*.php") as $filename ) {
45
+ include_once $filename;
42
46
  }
43
47
 
44
48
  ?>
@@ -1,27 +1,28 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" >
4
5
  <meta charset="utf-8">
5
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
6
7
 
7
8
  <title><?php bloginfo( 'name' ); ?><?php wp_title( '|' ); ?></title>
8
9
 
9
10
  <!-- Favicon -->
10
- <link rel="shortcut icon" href="<?php echo get_stylesheet_directory_uri(); ?>/favicon.ico" />
11
+ <link rel="shortcut icon" href="<?php echo get_stylesheet_directory_uri(); ?>/favicon.ico" />
11
12
 
12
13
  <?php wp_head(); ?>
13
14
 
14
15
  <!-- HTML5 Shiv -->
15
- <!--[if lt IE 9]>
16
- <script src="<?php bloginfo('template_directory'); ?>/js/vendor/html5shiv.js"></script>
17
- <![endif]-->
16
+ <!--[if lt IE 9]>
17
+ <script src="<?php bloginfo('template_directory'); ?>/js/vendor/html5shiv.js"></script>
18
+ <![endif]-->
18
19
  </head>
19
20
  <body>
20
21
 
21
22
  <header>
22
23
  <nav>
23
24
  <?php
24
- // Display Header Menu
25
+ // Display Header Menu
25
26
  $defaults = array('theme_location' => 'header_menu');
26
27
  wp_nav_menu( $defaults );
27
28
  ?>