aina 0.2.0.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.rdoc +6 -0
- data/aina.rdoc +5 -0
- data/bin/aina +143 -0
- data/lib/aina.rb +53 -0
- data/lib/aina/addable.rb +106 -0
- data/lib/aina/generable.rb +62 -0
- data/lib/aina/generable/base.rb +72 -0
- data/lib/aina/generable/types/post_type.rb +49 -0
- data/lib/aina/globals.rb +3 -0
- data/lib/aina/support.rb +46 -0
- data/lib/aina/version.rb +3 -0
- data/templates/add.php +29 -0
- data/templates/aina_framework.php +138 -0
- data/templates/post_type.php +101 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9bf384084ac4dcc6deb23c59231c73d92fc8676e
|
4
|
+
data.tar.gz: e1a802445afe753a40e06b6f70d558b92e015a52
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 759048bad7a66d82e8435a7daa4bd74d4a47ce78fa28166ec11c893d228d1c50ff527464f4896ba292da46ac5c7736b8b4edab6bf7a902ab35e358f42d1cc755
|
7
|
+
data.tar.gz: 804cb8f919f337a57743ecffd388391ac07cbf32ba542be302586d4505f07955524e09e2bb34f75109886679fe363027b4f38a3a443f12fed19f4c34b0a6b861
|
data/README.rdoc
ADDED
data/aina.rdoc
ADDED
data/bin/aina
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'gli'
|
3
|
+
|
4
|
+
require 'aina'
|
5
|
+
|
6
|
+
include GLI::App
|
7
|
+
|
8
|
+
program_desc 'Code generator for WordPress themes'
|
9
|
+
|
10
|
+
version Aina::VERSION
|
11
|
+
|
12
|
+
# desc 'Describe some switch here'
|
13
|
+
# switch [:s,:switch]
|
14
|
+
|
15
|
+
# desc 'Describe some flag here'
|
16
|
+
# default_value 'the default'
|
17
|
+
# arg_name 'The name of the argument'
|
18
|
+
# flag [:f,:flagname]
|
19
|
+
|
20
|
+
desc 'Generates a piece of code from a template'
|
21
|
+
arg_name 'element_type element_name'
|
22
|
+
command [:generate, :g] do |c|
|
23
|
+
# c.desc 'Describe a switch to generate'
|
24
|
+
# c.switch :s
|
25
|
+
|
26
|
+
c.desc '[post_type] Content fields that a post_type supports, comma separated'
|
27
|
+
c.default_value PostType::DEFAULT_SUPPORT
|
28
|
+
c.arg_name 'supports'
|
29
|
+
c.flag [:s, :supports]
|
30
|
+
|
31
|
+
c.desc '[post_type] Capability type'
|
32
|
+
c.default_value PostType::DEFAULT_CAPABILITY
|
33
|
+
c.arg_name 'capability'
|
34
|
+
c.flag [:c, :capability]
|
35
|
+
|
36
|
+
c.desc 'Install Aina framework to easily create custom post_type fields'
|
37
|
+
c.switch [:i, :install]
|
38
|
+
|
39
|
+
c.action do |global_options,options,args|
|
40
|
+
@type = args.shift
|
41
|
+
@name = args.shift
|
42
|
+
|
43
|
+
if @type.nil?
|
44
|
+
raise NoMethodError, 'You need to generate something'
|
45
|
+
elsif @name.nil?
|
46
|
+
raise NoMethodError, 'You need to put a name to what you want tot generate'
|
47
|
+
end
|
48
|
+
|
49
|
+
if Generable.accepts?(@type)
|
50
|
+
element = Object.const_get(Generable.class_name_for @type).new(@name, options)
|
51
|
+
unless File.exists?(element.file)
|
52
|
+
element.generate
|
53
|
+
else
|
54
|
+
raise Exception, "A #{@type} named #{element.name} already exists. Action aborted."
|
55
|
+
end
|
56
|
+
|
57
|
+
output = "A #{@type} with name #{element.name} has been succesfully generated"
|
58
|
+
if options[:i]
|
59
|
+
output += ". Also, Aina's framework has been added.\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
puts output
|
63
|
+
else
|
64
|
+
raise Exception, "#{@type} is not a generable piece of code. Options are: #{Generable.generable_types.join(', ')}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
desc 'Destroys a generated piece of code'
|
70
|
+
arg_name 'element_type element_name'
|
71
|
+
command [:destroy] do |c|
|
72
|
+
c.action do |global_options,options,args|
|
73
|
+
@type = args.shift
|
74
|
+
@name = args.shift
|
75
|
+
|
76
|
+
if @type.nil?
|
77
|
+
raise NoMethodError, 'You must specify what kind of file you want to destroy (i.e. post_type)'
|
78
|
+
elsif @name.nil?
|
79
|
+
raise NoMethodError, 'You must specify the name of what you want to destroy'
|
80
|
+
end
|
81
|
+
|
82
|
+
if Generable.accepts?(@type)
|
83
|
+
element = Object.const_get(Generable.class_name_for @type).new(@name)
|
84
|
+
if element.destroy
|
85
|
+
puts "The #{@type} #{element.name} has been succesfully destroyed"
|
86
|
+
end
|
87
|
+
else
|
88
|
+
raise Exception, "#{@type} is not a destroyable piece of code. Options are: #{Generable.generable_types.join(', ')}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
desc 'Add custom fields to post_types'
|
94
|
+
arg_name 'element_name field:type'
|
95
|
+
command [:add] do |c|
|
96
|
+
c.action do |global_options,options,args|
|
97
|
+
@name = args.shift
|
98
|
+
|
99
|
+
if @name.nil?
|
100
|
+
raise Exception, "Please, write the name of the post_type"
|
101
|
+
end
|
102
|
+
|
103
|
+
unless Aina.is_installed?
|
104
|
+
Aina.install
|
105
|
+
puts "We have installed Aina's framework for you. Next time, you can run `aina install` yourself ;-)"
|
106
|
+
end
|
107
|
+
|
108
|
+
add = Addable.new(@name, args)
|
109
|
+
add.add_custom_fields
|
110
|
+
|
111
|
+
puts "#{add.fields.map{|f| f[:key]}} fields have been added to #{@name}"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
desc 'Installs Aina framework, that allows you to easily create custom fields for post_types'
|
116
|
+
arg_name 'field:type'
|
117
|
+
command [:install] do |c|
|
118
|
+
c.action do |global_options, options, args|
|
119
|
+
Aina.install(true)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
pre do |global,command,options,args|
|
124
|
+
unless is_wordpress_theme? or tests_being_runned?
|
125
|
+
puts "This does not look like a WordPress theme"
|
126
|
+
return false
|
127
|
+
end
|
128
|
+
true
|
129
|
+
end
|
130
|
+
|
131
|
+
post do |global,command,options,args|
|
132
|
+
# Post logic here
|
133
|
+
# Use skips_post before a command to skip this
|
134
|
+
# block on that command only
|
135
|
+
end
|
136
|
+
|
137
|
+
on_error do |exception|
|
138
|
+
# Error logic here
|
139
|
+
# return false to skip default error handling
|
140
|
+
true
|
141
|
+
end
|
142
|
+
|
143
|
+
exit run(ARGV)
|
data/lib/aina.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Lib
|
2
|
+
Dir.glob(File.dirname(__FILE__) + "/aina/*.rb") { |file| require file }
|
3
|
+
Dir.glob(File.dirname(__FILE__) + "/aina/generable/*.rb") { |file| require file }
|
4
|
+
Dir.glob(File.dirname(__FILE__) + "/aina/generable/types/*.rb") { |file| require file }
|
5
|
+
|
6
|
+
# Templates
|
7
|
+
Dir.glob(File.expand_path('..') + "/templates/*") { |file| require file }
|
8
|
+
|
9
|
+
module Aina
|
10
|
+
def self.aina_version
|
11
|
+
Aina::VERSION
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.install(output = false)
|
15
|
+
unless Dir.exists?(Dir.pwd + '/inc')
|
16
|
+
Dir.mkdir(Dir.pwd + '/inc')
|
17
|
+
end
|
18
|
+
|
19
|
+
# Install Aina
|
20
|
+
unless self.is_installed?
|
21
|
+
text = File.read(Aina::TEMPLATES_DIR + '/aina_framework.php')
|
22
|
+
|
23
|
+
['{{aina_version}}'].each do |replace|
|
24
|
+
attribute = replace.gsub(/[{}]/, '')
|
25
|
+
@output = text.gsub!(/#{replace}/, self.send(attribute))
|
26
|
+
end
|
27
|
+
|
28
|
+
File.open(Dir.pwd + "/inc/aina.php", "w") {|file| file.puts @output}
|
29
|
+
|
30
|
+
message = "Aina has been installed in your WordPress theme.\n"
|
31
|
+
message += "\n\nIf you want your post type to be automatically included, put this is functions.php:\n"
|
32
|
+
message += "function aina_post_types() {\n"
|
33
|
+
message += " return array('your_post_type', 'another_post_type', 'etc');\n"
|
34
|
+
message += "}\n"
|
35
|
+
else
|
36
|
+
message = "Aina was already installed in your WordPress theme ;-)\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
# Include Aina
|
40
|
+
unless functions_php_exists?
|
41
|
+
create_empty_functions_php
|
42
|
+
end
|
43
|
+
File.open(functions_php, "a+") {|file| file.puts aina_inclusion}
|
44
|
+
|
45
|
+
if output
|
46
|
+
puts message
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.is_installed?
|
51
|
+
File.exists?(Dir.pwd + "/inc/aina.php")
|
52
|
+
end
|
53
|
+
end
|
data/lib/aina/addable.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
class Addable
|
2
|
+
attr_accessor :name, :aina_version, :fields
|
3
|
+
|
4
|
+
def initialize(name, fields = nil)
|
5
|
+
@type = 'post_type'
|
6
|
+
@name = validate_name(name)
|
7
|
+
@aina_version = Aina::VERSION
|
8
|
+
|
9
|
+
parse_fields(fields)
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse_fields(fields)
|
13
|
+
@fields = Array.new
|
14
|
+
fields.each do |f|
|
15
|
+
a = f.split(':')
|
16
|
+
# TODO: Validate type against a whitelist
|
17
|
+
@fields << {key: a[0], type: a[1]}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def fields_php_array
|
22
|
+
a = ''
|
23
|
+
@fields.each do |f|
|
24
|
+
a += "'#{f[:key]}' => array(\n"
|
25
|
+
a += " 'label' => '#{f[:key].capitalize}',\n"
|
26
|
+
a += " 'type' => '#{f[:type]}',\n"
|
27
|
+
a += " 'options' => array('option_1', 'option_2', 'etc'),\n" if %w(radio checkbox select).include?(f[:type])
|
28
|
+
a += "),\n"
|
29
|
+
end
|
30
|
+
a
|
31
|
+
end
|
32
|
+
|
33
|
+
def custom_fields
|
34
|
+
c = Array.new
|
35
|
+
c << "/**"
|
36
|
+
c << " * Custom data fields"
|
37
|
+
c << " * Add these custom fields to the #{@name} post type"
|
38
|
+
c << " * IMPORTANT: Thou shalt not rename this function, or bad things may happen"
|
39
|
+
c << " */"
|
40
|
+
c << "if ( ! function_exists( '#{@name}_custom_fields' ) ) {"
|
41
|
+
c << " function #{@name}_custom_fields() {"
|
42
|
+
c << " return array("
|
43
|
+
c << " #{fields_php_array}"
|
44
|
+
c << " );"
|
45
|
+
c << " }"
|
46
|
+
c << "}"
|
47
|
+
c.join("\n")
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_custom_fields
|
51
|
+
@file = Dir.pwd + "/post-types/#{@name}.php"
|
52
|
+
|
53
|
+
# The post type wasn't using custom fields yet,
|
54
|
+
# so wrap them with the custom_fields function
|
55
|
+
unless File.read(@file).include? "function #{@name}_custom_fields"
|
56
|
+
File.open(@file, 'a+') {|file| file.puts custom_fields}
|
57
|
+
else
|
58
|
+
output = Array.new
|
59
|
+
counter = 0 # This will help us keep track of lines
|
60
|
+
|
61
|
+
File.open(@file).each do |line|
|
62
|
+
output << line
|
63
|
+
|
64
|
+
# When we reach a line that includes "function #{@name}_custom_fields"
|
65
|
+
# it means that we have to add the items two lines later
|
66
|
+
if line.include?("function #{@name}_custom_fields")
|
67
|
+
# Negative number, so we know that this + 1 will we the line
|
68
|
+
# after which we want to add text
|
69
|
+
counter = -2
|
70
|
+
end
|
71
|
+
|
72
|
+
# Ok! It's ok to add the new items here, after 'return array('
|
73
|
+
if counter === -1 and line.include?('return array(')
|
74
|
+
output << fields_php_array
|
75
|
+
end
|
76
|
+
|
77
|
+
counter = counter + 1
|
78
|
+
end
|
79
|
+
|
80
|
+
File.open(@file, 'w') {|file| file.puts output}
|
81
|
+
end
|
82
|
+
|
83
|
+
# Make sure they can be saved
|
84
|
+
text = File.read(@file)
|
85
|
+
unless text.include? "function #{@name}_meta_box"
|
86
|
+
template = File.read("#{Aina::TEMPLATES_DIR}/add.php")
|
87
|
+
['{{name}}'].each do |replace|
|
88
|
+
attribute = replace.gsub(/[{}]/, '')
|
89
|
+
@output = template.gsub!(/#{replace}/, self.send(attribute))
|
90
|
+
end
|
91
|
+
File.open(@file, "a+") {|file| file.puts @output}
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.accepts?(type)
|
96
|
+
Generable.accepts?(type)
|
97
|
+
end
|
98
|
+
|
99
|
+
protected
|
100
|
+
def validate_name(name)
|
101
|
+
unless File.exists?(Dir.pwd + "/post-types/#{name}.php")
|
102
|
+
raise Exception, "There's no file named /post-types/#{name}.php"
|
103
|
+
end
|
104
|
+
name
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Generable
|
2
|
+
# List of generable types
|
3
|
+
def self.generable_types
|
4
|
+
g = Array.new
|
5
|
+
Dir.glob(File.dirname(__FILE__) + "/generable/types/*.rb").each do |f|
|
6
|
+
g << f.split('/').last.split('.rb').join()
|
7
|
+
end
|
8
|
+
g
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.class_name_for(type)
|
12
|
+
"Generable::#{type.camelcase}"
|
13
|
+
end
|
14
|
+
|
15
|
+
# Is generable?
|
16
|
+
def self.accepts?(type)
|
17
|
+
generable_types.include?(type)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Does type need to be created in a directory?
|
21
|
+
# Then, in type use:
|
22
|
+
# dir 'my-directory'
|
23
|
+
def dir(directory)
|
24
|
+
@dir = directory
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_dir
|
28
|
+
@dir
|
29
|
+
end
|
30
|
+
|
31
|
+
# Does type use a template?
|
32
|
+
# Then, in type use:
|
33
|
+
# template 'my-template.php'
|
34
|
+
def template(template)
|
35
|
+
@template = "#{Aina::TEMPLATES_DIR}/#{template}" if template
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_template
|
39
|
+
@template
|
40
|
+
end
|
41
|
+
|
42
|
+
# Does type template need custom replacements?
|
43
|
+
# Then, in type use:
|
44
|
+
# replacements %w({{replace_this}} {{and_this_too}})
|
45
|
+
def replacements(*replacements)
|
46
|
+
@replacements = %w(name aina_version)
|
47
|
+
@replacements += replacements.flatten if replacements
|
48
|
+
@replacements = @replacements.map { |r| "{{#{r}}}" }
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_replacements
|
52
|
+
@replacements
|
53
|
+
end
|
54
|
+
|
55
|
+
def after_generate(*callbacks)
|
56
|
+
@after_generate = callbacks
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_after_generate
|
60
|
+
@after_generate
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Generable class
|
2
|
+
class Generable::Base
|
3
|
+
extend Generable
|
4
|
+
attr_reader :name, :template, :file, :aina_version, :supports
|
5
|
+
|
6
|
+
def initialize(name, options=nil)
|
7
|
+
@name = name
|
8
|
+
@options = options
|
9
|
+
@aina_version = Aina::VERSION
|
10
|
+
@template = self.template
|
11
|
+
@dir = self.dir
|
12
|
+
@file = generate_file_name
|
13
|
+
|
14
|
+
set_custom_vars
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_custom_vars
|
18
|
+
# Nothing here
|
19
|
+
# This can be used in types to parse required instance variables
|
20
|
+
end
|
21
|
+
|
22
|
+
def dir
|
23
|
+
self.class.get_dir
|
24
|
+
end
|
25
|
+
|
26
|
+
def template
|
27
|
+
self.class.get_template
|
28
|
+
end
|
29
|
+
|
30
|
+
def replacements
|
31
|
+
self.class.get_replacements
|
32
|
+
end
|
33
|
+
|
34
|
+
def generate
|
35
|
+
text = File.read(@template)
|
36
|
+
replacements.each do |replace|
|
37
|
+
attribute = replace.gsub(/[{}]/, '')
|
38
|
+
@output = text.gsub!(/#{replace}/, self.send(attribute))
|
39
|
+
end
|
40
|
+
File.open(@file, "w") {|file| file.puts @output}
|
41
|
+
|
42
|
+
after_generate
|
43
|
+
end
|
44
|
+
|
45
|
+
def after_generate
|
46
|
+
if self.class.get_after_generate
|
47
|
+
self.class.get_after_generate.each do |callback|
|
48
|
+
self.send(callback)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def destroy
|
54
|
+
if File.exists?(@file)
|
55
|
+
File.delete(@file)
|
56
|
+
else
|
57
|
+
raise "No #{self.class} with name #{@name}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
def generate_file_name
|
63
|
+
unless @dir.nil?
|
64
|
+
unless Dir.exists?(Dir.pwd + '/' + @dir)
|
65
|
+
Dir.mkdir(Dir.pwd + '/' + @dir)
|
66
|
+
end
|
67
|
+
Dir.pwd + "/#{@dir}/#{@name}.php"
|
68
|
+
else
|
69
|
+
Dir.pwd + "/#{@name}.php"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class PostType < Generable::Base
|
2
|
+
attr_reader :name_capitalize, :capability, :supports
|
3
|
+
|
4
|
+
DEFAULT_SUPPORT = 'title,editor,excerpt,thumbnail'
|
5
|
+
DEFAULT_CAPABILITY = 'post'
|
6
|
+
|
7
|
+
template 'post_type.php'
|
8
|
+
dir 'post-types'
|
9
|
+
replacements %w(name_capitalize capability supports)
|
10
|
+
|
11
|
+
after_generate :install_aina_framework?, :include_post_type
|
12
|
+
|
13
|
+
def set_custom_vars
|
14
|
+
@name_capitalize = self.name.capitalize
|
15
|
+
if @options
|
16
|
+
@supports = get_supports
|
17
|
+
@capability = get_capability
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_supports
|
22
|
+
s = @options[:s] ? @options[:s] : DEFAULT_SUPPORT
|
23
|
+
s = s.split(',')
|
24
|
+
|
25
|
+
supports = Array.new
|
26
|
+
s.each do |item|
|
27
|
+
supports << "'#{item}'"
|
28
|
+
end
|
29
|
+
supports.join(',')
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_capability
|
33
|
+
@options[:c] ? @options[:c] : DEFAULT_CAPABILITY
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
def install_aina_framework?
|
38
|
+
if @options and @options[:i]
|
39
|
+
Aina.install
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def include_post_type
|
44
|
+
unless functions_php_exists?
|
45
|
+
create_empty_functions_php
|
46
|
+
end
|
47
|
+
File.open(functions_php, "a+") {|file| file.puts "\n/* Include #{self.name} */\nrequire_once '#{dir}/#{self.name}.php';\n"}
|
48
|
+
end
|
49
|
+
end
|
data/lib/aina/globals.rb
ADDED
data/lib/aina/support.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
def is_wordpress_theme?
|
2
|
+
theme_path = Dir.pwd.split('/')
|
3
|
+
theme_path.pop
|
4
|
+
theme_path.last(2).join('/') == 'wp-content/themes'
|
5
|
+
end
|
6
|
+
|
7
|
+
def tests_being_runned?
|
8
|
+
ENV['HOME'] == 'tmp/aruba'
|
9
|
+
end
|
10
|
+
|
11
|
+
def functions_php
|
12
|
+
Dir.pwd + "/functions.php"
|
13
|
+
end
|
14
|
+
|
15
|
+
def functions_php_exists?
|
16
|
+
File.exists?(Dir.pwd + "/functions.php")
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_empty_functions_php
|
20
|
+
unless functions_php_exists?
|
21
|
+
File.open(functions_php, "w") {|file| file.puts "<?php\n"}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def aina_inclusion
|
26
|
+
output = "\n/**\n"
|
27
|
+
output += " * Include Aina's framework\n"
|
28
|
+
output += " */\n"
|
29
|
+
output += "if ( file_exists( dirname(__FILE__) . '/inc/aina.php' ) ) {\n"
|
30
|
+
output += " require_once 'inc/aina.php';\n"
|
31
|
+
output += "}\n"
|
32
|
+
end
|
33
|
+
|
34
|
+
class String
|
35
|
+
def camelcase
|
36
|
+
r = Array.new
|
37
|
+
|
38
|
+
pieces = self.split(' ')
|
39
|
+
pieces = self.split('_') unless pieces.length > 1
|
40
|
+
|
41
|
+
pieces.each do |p|
|
42
|
+
r << p.capitalize
|
43
|
+
end
|
44
|
+
r.join()
|
45
|
+
end
|
46
|
+
end
|
data/lib/aina/version.rb
ADDED
data/templates/add.php
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
/**
|
2
|
+
* Add meta box
|
3
|
+
* add_meta_box( $id, $title, $callback, $post_type, $context, $priority );
|
4
|
+
*/
|
5
|
+
if ( ! function_exists('{{name}}_meta_box') ) {
|
6
|
+
function {{name}}_meta_box(){
|
7
|
+
add_meta_box("{{name}}_meta", "Extra", "add_{{name}}_custom_fields", "{{name}}", "normal", "low");
|
8
|
+
}
|
9
|
+
add_action("admin_init", "{{name}}_meta_box");
|
10
|
+
}
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Add Custom Fields
|
14
|
+
*/
|
15
|
+
if ( ! function_exists('add_{{name}}_custom_fields') ) {
|
16
|
+
function add_{{name}}_custom_fields() {
|
17
|
+
aina_add_custom_fields('{{name}}');
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Make sure we can save it
|
23
|
+
*/
|
24
|
+
if ( ! function_exists('save_{{name}}_custom') ) {
|
25
|
+
function save_{{name}}_custom() {
|
26
|
+
aina_save_custom('{{name}}');
|
27
|
+
}
|
28
|
+
add_action('save_post', 'save_{{name}}_custom');
|
29
|
+
}
|
@@ -0,0 +1,138 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Aina
|
5
|
+
* Generated with Aina. Version {{aina_version}}
|
6
|
+
*/
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Include Custom Post-Types
|
10
|
+
*/
|
11
|
+
if ( function_exists( 'aina_post_types' ) ) {
|
12
|
+
foreach ( aina_post_types() as $pt ) {
|
13
|
+
require dirname(dirname(__FILE__)) . '/post-types/' . $pt . '.php';
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Add Post-Type Custom Fields
|
19
|
+
*/
|
20
|
+
function aina_add_custom_fields($post_type) {
|
21
|
+
global $post;
|
22
|
+
$custom = get_post_custom($post->ID);
|
23
|
+
|
24
|
+
$add_custom_function = $post_type . '_custom_fields';
|
25
|
+
|
26
|
+
$custom_fields = $add_custom_function();
|
27
|
+
|
28
|
+
foreach ( $custom_fields as $field => $args ) {
|
29
|
+
$value = isset($custom[$field][0]) ? $custom[$field][0] : null;
|
30
|
+
echo aina_custom_field_for($field, $value, $args);
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Make sure we can save it
|
36
|
+
*/
|
37
|
+
function aina_save_custom($post_type) {
|
38
|
+
global $post;
|
39
|
+
|
40
|
+
// Is this a new post being created?
|
41
|
+
if ( ! isset($post->ID) ) return;
|
42
|
+
|
43
|
+
$add_custom_function = $post_type . '_custom_fields';
|
44
|
+
|
45
|
+
$save_fields = $add_custom_function();
|
46
|
+
|
47
|
+
foreach ( $save_fields as $field => $args ) {
|
48
|
+
$value = null;
|
49
|
+
if ( isset($_POST[$field]) ) {
|
50
|
+
if ( is_array($_POST[$field]) ) {
|
51
|
+
$value = $_POST[$field][0];
|
52
|
+
} else {
|
53
|
+
$value = $_POST[$field];
|
54
|
+
}
|
55
|
+
}
|
56
|
+
update_post_meta($post->ID, $field, $value);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Get single custom fields
|
62
|
+
*/
|
63
|
+
function aina_get_field($post_type, $field = '') {
|
64
|
+
global $post;
|
65
|
+
$custom_fields = get_post_custom($post->ID);
|
66
|
+
return isset($custom_fields[$field][0]) ? $custom_fields[$field][0] : false;
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Echo single custom fields
|
71
|
+
* This is a wrapper for aina_get_field()
|
72
|
+
*/
|
73
|
+
function aina_field($post_type, $field = '') {
|
74
|
+
echo aina_get_field($post_type, $field);
|
75
|
+
}
|
76
|
+
|
77
|
+
/**
|
78
|
+
* Custom Field For
|
79
|
+
*/
|
80
|
+
function aina_custom_field_for($field, $value, $args = array()) {
|
81
|
+
|
82
|
+
$return = '';
|
83
|
+
|
84
|
+
if ( isset($args) && is_array($args) ) {
|
85
|
+
|
86
|
+
// Is label set?
|
87
|
+
if ( isset($args['label']) ) {
|
88
|
+
$return .= '<label>' . ucfirst($args['label']) . '</label><br />';
|
89
|
+
} else {
|
90
|
+
$return .= '<label>' . ucfirst($field) . '</label><br />';
|
91
|
+
}
|
92
|
+
|
93
|
+
// Options
|
94
|
+
$placeholder = isset($args['placeholder']) ? $args['placeholder'] : '';
|
95
|
+
|
96
|
+
// Is type set?
|
97
|
+
if ( isset($args['type']) ) {
|
98
|
+
switch ($args['type']) {
|
99
|
+
// Simple inputs
|
100
|
+
case 'text':
|
101
|
+
$return .= '<input type="text" name="' . $field . '" value="' . $value . '" placeholder="' . $placeholder . '" />';
|
102
|
+
break;
|
103
|
+
case 'url':
|
104
|
+
$return .= '<input type="url" name="' . $field . '" value="' . $value . '" placeholder="' . $placeholder . '" />';
|
105
|
+
break;
|
106
|
+
case 'email':
|
107
|
+
$return .= '<input type="email" name="' . $field . '" value="' . $value . '" placeholder="' . $placeholder . '" />';
|
108
|
+
break;
|
109
|
+
case 'datetime-local':
|
110
|
+
case 'datetime':
|
111
|
+
$return .= '<input type="datetime-local" name="' . $field . '" value="' . $value . '" />';
|
112
|
+
break;
|
113
|
+
case 'textarea':
|
114
|
+
$return .= '<textarea name="' . $field . '">' . $value . '</textarea>';
|
115
|
+
break;
|
116
|
+
|
117
|
+
// With options
|
118
|
+
case 'radio':
|
119
|
+
if ( isset($args['options']) && is_array($args['options']) ) {
|
120
|
+
foreach ($args['options'] as $option) {
|
121
|
+
$checked = $option == $value ? true : false;
|
122
|
+
$is_checked = $checked == true ? 'checked' : '';
|
123
|
+
$return .= '<input type="radio" name=" ' . $field . '[]" value="' . $option . '" ' . $is_checked . '/>' . $option;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
break;
|
127
|
+
default:
|
128
|
+
# code...
|
129
|
+
break;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
} else {
|
133
|
+
$return .= '<label>' . ucfirst($field) . '</label><br />';
|
134
|
+
$return .= '<input type="text" name=" ' . $field . '" value="' . $value . '" />';
|
135
|
+
}
|
136
|
+
|
137
|
+
return '<p>' . $return . '</p>';
|
138
|
+
}
|
@@ -0,0 +1,101 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Custom Post Type: {{name_capitalize}}
|
5
|
+
* Generated with Aina. Version {{aina_version}}
|
6
|
+
*/
|
7
|
+
|
8
|
+
/* {{name_capitalize}} Properties */
|
9
|
+
function {{name}}_register() {
|
10
|
+
$labels = array(
|
11
|
+
'name' => _x("{{name_capitalize}}", '{{name}}'),
|
12
|
+
'singular_name' => _x("{{name_capitalize}} Item", '{{name}}'),
|
13
|
+
'add_new' => _x('New {{name_capitalize}} Item', '{{name}}'),
|
14
|
+
'add_new_item' => __('Add New {{name_capitalize}} Item'),
|
15
|
+
'edit_item' => __('Edit {{name_capitalize}} Item'),
|
16
|
+
'new_item' => __('New {{name_capitalize}} Item'),
|
17
|
+
'view_item' => __('View {{name_capitalize}} Item'),
|
18
|
+
'search_items' => __('Search {{name_capitalize}} Items'),
|
19
|
+
'not_found' => __('Nothing found'),
|
20
|
+
'not_found_in_trash' => __('Nothing found in Trash'),
|
21
|
+
'parent_item_colon' => '',
|
22
|
+
);
|
23
|
+
$args = array(
|
24
|
+
'labels' => $labels,
|
25
|
+
'public' => true,
|
26
|
+
'publicly_queryable' => true,
|
27
|
+
'show_ui' => true,
|
28
|
+
'query_var' => true,
|
29
|
+
'menu_icon' => false, // get_stylesheet_directory_uri() . '/your_pt_icon_here.png'
|
30
|
+
'rewrite' => true,
|
31
|
+
'capability_type' => '{{capability}}',
|
32
|
+
'hierarchical' => true,
|
33
|
+
'has_archive' => true,
|
34
|
+
'menu_position' => null,
|
35
|
+
'supports' => array({{supports}}),
|
36
|
+
);
|
37
|
+
register_post_type( '{{name}}' , $args );
|
38
|
+
}
|
39
|
+
|
40
|
+
add_action('init', '{{name}}_register');
|
41
|
+
|
42
|
+
|
43
|
+
/* {{name_capitalize}} Taxonomy */
|
44
|
+
add_action( 'init', 'register_taxonomy_{{name}}categories' );
|
45
|
+
|
46
|
+
function register_taxonomy_{{name}}categories() {
|
47
|
+
// Taxonomy slug
|
48
|
+
${{name}}_taxonomy = '{{name}}categories';
|
49
|
+
|
50
|
+
$labels = array(
|
51
|
+
'name' => _x( '{{name_capitalize}} Categories', ${{name}}_taxonomy ),
|
52
|
+
'singular_name' => _x( '{{name_capitalize}} Category', ${{name}}_taxonomy ),
|
53
|
+
'search_items' => _x( 'Search {{name_capitalize}} Category', ${{name}}_taxonomy ),
|
54
|
+
'popular_items' => _x( 'Popular {{name_capitalize}} Category', ${{name}}_taxonomy ),
|
55
|
+
'all_items' => _x( 'All {{name_capitalize}} Category', ${{name}}_taxonomy ),
|
56
|
+
'parent_item' => _x( 'Parent {{name_capitalize}} Category', ${{name}}_taxonomy ),
|
57
|
+
'parent_item_colon' => _x( 'Parent {{name_capitalize}} Category:', ${{name}}_taxonomy ),
|
58
|
+
'edit_item' => _x( 'Edit {{name_capitalize}} Category', ${{name}}_taxonomy ),
|
59
|
+
'update_item' => _x( 'Update {{name_capitalize}} Category', ${{name}}_taxonomy ),
|
60
|
+
'add_new_item' => _x( 'Add New {{name_capitalize}} Category', ${{name}}_taxonomy ),
|
61
|
+
'new_item_name' => _x( 'New {{name_capitalize}} Category', ${{name}}_taxonomy ),
|
62
|
+
'separate_items_with_commas' => _x( 'Separate {{name_capitalize}} Categories with commas', ${{name}}_taxonomy ),
|
63
|
+
'add_or_remove_items' => _x( 'Add or remove {{name_capitalize}} Categories', ${{name}}_taxonomy ),
|
64
|
+
'choose_from_most_used' => _x( 'Choose from the most used {{name_capitalize}} Categories', ${{name}}_taxonomy ),
|
65
|
+
'menu_name' => _x( '{{name_capitalize}} Category', ${{name}}_taxonomy ),
|
66
|
+
);
|
67
|
+
|
68
|
+
$args = array(
|
69
|
+
'labels' => $labels,
|
70
|
+
'public' => true,
|
71
|
+
'show_in_nav_menus' => true,
|
72
|
+
'show_ui' => true,
|
73
|
+
'show_tagcloud' => true,
|
74
|
+
'show_admin_column' => true,
|
75
|
+
'hierarchical' => true,
|
76
|
+
//'update_count_callback' => '',
|
77
|
+
'rewrite' => array( 'hierarchical' => true ), // Use taxonomy as categories
|
78
|
+
'query_var' => true
|
79
|
+
);
|
80
|
+
|
81
|
+
register_taxonomy( ${{name}}_taxonomy, array('{{name}}'), $args );
|
82
|
+
}
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Displays the {{name_capitalize}} post type icon in the dashboard
|
86
|
+
*/
|
87
|
+
//add_action( 'admin_head', '{{name}}_icon' );
|
88
|
+
function {{name}}_icon() {
|
89
|
+
echo '<style type="text/css" media="screen">
|
90
|
+
#menu-posts-projecte .wp-menu-image {
|
91
|
+
background: url(<?php echo get_stylesheet_directory_uri(); ?>/img/{{name}}-icon.png) no-repeat 6px 6px !important;
|
92
|
+
}
|
93
|
+
#menu-posts-projecte:hover .wp-menu-image, #menu-posts-projecte.wp-has-current-submenu .wp-menu-image {
|
94
|
+
background-position:6px -16px !important;
|
95
|
+
}
|
96
|
+
#icon-edit.icon32-posts-projecte {
|
97
|
+
background: url(<?php echo get_stylesheet_directory_uri(); ?>/img/{{name}}-32x32.png) no-repeat;
|
98
|
+
}
|
99
|
+
</style>';
|
100
|
+
}
|
101
|
+
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aina
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0.beta
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carles Jove i Buxeda
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: aruba
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: gli
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.8.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.8.1
|
69
|
+
description:
|
70
|
+
email: info@joanielena.cat
|
71
|
+
executables:
|
72
|
+
- aina
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files:
|
75
|
+
- README.rdoc
|
76
|
+
- aina.rdoc
|
77
|
+
files:
|
78
|
+
- bin/aina
|
79
|
+
- lib/aina/addable.rb
|
80
|
+
- lib/aina/generable.rb
|
81
|
+
- lib/aina/globals.rb
|
82
|
+
- lib/aina/support.rb
|
83
|
+
- lib/aina/version.rb
|
84
|
+
- lib/aina/generable/base.rb
|
85
|
+
- lib/aina/generable/types/post_type.rb
|
86
|
+
- templates/add.php
|
87
|
+
- templates/aina_framework.php
|
88
|
+
- templates/post_type.php
|
89
|
+
- lib/aina.rb
|
90
|
+
- README.rdoc
|
91
|
+
- aina.rdoc
|
92
|
+
homepage: http://joanielena.cat
|
93
|
+
licenses: []
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options:
|
97
|
+
- --title
|
98
|
+
- aina
|
99
|
+
- --main
|
100
|
+
- README.rdoc
|
101
|
+
- -ri
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
- lib
|
105
|
+
- templates
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - '>'
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: 1.3.1
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.0.3
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: Code generation for WordPress
|
122
|
+
test_files: []
|