cocoanova 1.0.0
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/bin/nova +47 -0
- data/lib/cocoanova.rb +75 -0
- data/lib/cocoanova/engine.rb +35 -0
- data/lib/cocoanova/engines/erb.rb +29 -0
- data/lib/cocoanova/helper.rb +7 -0
- data/lib/cocoanova/loader.rb +49 -0
- data/lib/cocoanova/loaders/json.rb +9 -0
- data/lib/cocoanova/loaders/txt.rb +9 -0
- data/lib/cocoanova/loaders/yaml.rb +9 -0
- data/lib/cocoanova/task.rb +43 -0
- data/lib/cocoanova/tasks/compile.rb +46 -0
- data/lib/cocoanova/version.rb +3 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ef877707e1fa3f1767538fe0be75402b1a0bb5c6
|
4
|
+
data.tar.gz: f53b61f64882706078c163df7652e6c6480f210b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d7c00f30602d090d4effc49eb0768b50d57c6751374cbf0f8e6e04e2e619aefa352fc9d7f0150fca0640083c3f12f95d8ccb72b7b565aad150fb9426d13851cc
|
7
|
+
data.tar.gz: a200bf920fbdb498e1ec35bb873f05cdcec965b86668e9c30017340d25d2988517062ce26e4d85ef950f78a2444b72fc36f8ac8b1a7739076069b67b56f15ca2
|
data/bin/nova
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'cocoanova'
|
5
|
+
|
6
|
+
config = { 'src_root'=> Dir.pwd }
|
7
|
+
|
8
|
+
# Load novarc
|
9
|
+
if File.exists? './.novarc'
|
10
|
+
config.merge! YAML.load_file './.novarc'
|
11
|
+
end
|
12
|
+
|
13
|
+
# Generate config
|
14
|
+
# Resolve src_root from relative
|
15
|
+
config['src_root'] = File.expand_path(config['src_root'], Dir.pwd)
|
16
|
+
# Set local_root if not exists
|
17
|
+
config['local_root'] ||= File.expand_path('./nova', config['src_root'])
|
18
|
+
# Resolve local_root from relative
|
19
|
+
config['local_root'] = File.expand_path(config['local_root'], Dir.pwd)
|
20
|
+
|
21
|
+
# Require plugins
|
22
|
+
Array.wrap(config['plugins']).each do |plugin|
|
23
|
+
require plugin
|
24
|
+
end
|
25
|
+
|
26
|
+
# Set project root to ./
|
27
|
+
Nova.src_root = config['src_root']
|
28
|
+
# Set local nova root to ./nova
|
29
|
+
Nova.local_root= config['local_root']
|
30
|
+
|
31
|
+
# Load Tasks
|
32
|
+
Nova::Task.require_all
|
33
|
+
|
34
|
+
# Execute task or print tasks
|
35
|
+
if ARGV.first.nil?
|
36
|
+
puts "CocoaNova Avaliable Tasks"
|
37
|
+
Nova::Task::Tasks.each_pair do |key, value|
|
38
|
+
puts "Task: #{key}"
|
39
|
+
Array.wrap(value).each do |task|
|
40
|
+
puts " -#{task}"
|
41
|
+
end
|
42
|
+
puts ""
|
43
|
+
end
|
44
|
+
else
|
45
|
+
puts "======== Task: #{ARGV.first} =========="
|
46
|
+
Nova::Task.invoke(ARGV.first)
|
47
|
+
end
|
data/lib/cocoanova.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_support/all'
|
3
|
+
|
4
|
+
module Nova
|
5
|
+
Plugins = []
|
6
|
+
|
7
|
+
@@local_root= nil
|
8
|
+
@@src_root = nil
|
9
|
+
@@data = {}
|
10
|
+
|
11
|
+
autoload :VERSION, 'cocoanova/version'
|
12
|
+
autoload :Loader, 'cocoanova/loader'
|
13
|
+
autoload :Engine, 'cocoanova/engine'
|
14
|
+
autoload :Helper, 'cocoanova/helper'
|
15
|
+
autoload :Task, 'cocoanova/task'
|
16
|
+
|
17
|
+
# Register Plugin
|
18
|
+
def self.register_plugin(path)
|
19
|
+
Plugins << path
|
20
|
+
end
|
21
|
+
|
22
|
+
# Global data
|
23
|
+
def self.data
|
24
|
+
@@data
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.data=(value)
|
28
|
+
@@data = value
|
29
|
+
end
|
30
|
+
|
31
|
+
# Get preset_path, i.e. lib/cocoanova
|
32
|
+
def self.preset_path
|
33
|
+
File.expand_path('../cocoanova', __FILE__)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Get project root
|
37
|
+
def self.src_root
|
38
|
+
@@src_root
|
39
|
+
end
|
40
|
+
|
41
|
+
# Set project root
|
42
|
+
def self.src_root=(value)
|
43
|
+
@@src_root= value
|
44
|
+
end
|
45
|
+
|
46
|
+
# Get local nova root
|
47
|
+
def self.local_root
|
48
|
+
@@local_root
|
49
|
+
end
|
50
|
+
|
51
|
+
# Set local nova root
|
52
|
+
def self.local_root=(value)
|
53
|
+
@@local_root = value
|
54
|
+
end
|
55
|
+
|
56
|
+
# Require a folder in both preset path and local path
|
57
|
+
def self.require_folder(folder)
|
58
|
+
# Require folder from preset path, i.e. lib/cocoanova/
|
59
|
+
Dir["#{self.preset_path}/#{folder}/**/*.rb"].each do |file|
|
60
|
+
require file
|
61
|
+
end
|
62
|
+
# Load Plugins
|
63
|
+
Plugins.each do |path|
|
64
|
+
Dir["#{path}/#{folder}/**/*.rb"].each do |file|
|
65
|
+
require file
|
66
|
+
end
|
67
|
+
end
|
68
|
+
# Require folder from local nova path, i.e. ./nova/
|
69
|
+
if self.local_root
|
70
|
+
Dir["#{self.local_root}/#{folder}/**/*.rb"].each do |file|
|
71
|
+
require file
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Nova
|
2
|
+
class Engine
|
3
|
+
Registry = {}
|
4
|
+
|
5
|
+
# Load all engines
|
6
|
+
def self.require_all
|
7
|
+
Nova.require_folder :engines
|
8
|
+
end
|
9
|
+
|
10
|
+
# Supported extensions, all symbol
|
11
|
+
def self.supported_extensions
|
12
|
+
Registry.keys
|
13
|
+
end
|
14
|
+
|
15
|
+
# Get subclass
|
16
|
+
def self.[](ext)
|
17
|
+
Registry[ext.to_sym]
|
18
|
+
end
|
19
|
+
|
20
|
+
# For subclass
|
21
|
+
|
22
|
+
# Register a subclass for file extension
|
23
|
+
def self.extension(*exts)
|
24
|
+
exts.flatten.each do |ext|
|
25
|
+
Registry[ext.to_sym] = self
|
26
|
+
puts "Engine Loaded: '#{self}' registered to extension '#{ext}'"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Execute render
|
31
|
+
def render(template, data, filename)
|
32
|
+
raise "#{self}#render not implemented."
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'digest'
|
4
|
+
|
5
|
+
class Nova::Engine::ERB < Nova::Engine
|
6
|
+
extension :erb
|
7
|
+
|
8
|
+
def render(_template, _data, _filename)
|
9
|
+
clazz = ::ERB.new(_template).def_class
|
10
|
+
clazz.class_eval do
|
11
|
+
include Nova::Helper
|
12
|
+
|
13
|
+
def initialize(data, filename)
|
14
|
+
@data = data
|
15
|
+
@filename = filename
|
16
|
+
end
|
17
|
+
|
18
|
+
def filename
|
19
|
+
@filename
|
20
|
+
end
|
21
|
+
|
22
|
+
def data
|
23
|
+
@data
|
24
|
+
end
|
25
|
+
end
|
26
|
+
clazz.new(OpenStruct.new(_data), _filename).result
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Nova
|
2
|
+
class Loader
|
3
|
+
# Regular file loaders
|
4
|
+
Registry = {}
|
5
|
+
# Phony loaders
|
6
|
+
Phony = {}
|
7
|
+
|
8
|
+
# Load all from default folder
|
9
|
+
def self.require_all
|
10
|
+
Nova.require_folder :loaders
|
11
|
+
end
|
12
|
+
|
13
|
+
# Supported extensions
|
14
|
+
def self.supported_extensions
|
15
|
+
Registry.keys
|
16
|
+
end
|
17
|
+
|
18
|
+
# Get implement
|
19
|
+
def self.[](ext)
|
20
|
+
Registry[ext.to_sym]
|
21
|
+
end
|
22
|
+
|
23
|
+
# For subclass calling
|
24
|
+
|
25
|
+
# Register Engines
|
26
|
+
def self.extension(*exts)
|
27
|
+
exts.flatten.each do |ext|
|
28
|
+
Registry[ext.to_sym] = self
|
29
|
+
puts "Loader Loaded: '#{self}' registered to extension '#{ext}'"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Phony loader
|
34
|
+
def self.phony(*keys)
|
35
|
+
keys.flatten.each do |key|
|
36
|
+
Phony[key.to_sym] = self
|
37
|
+
puts "Phony Loader: '#{self}' registered to key '#{key}'"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# For subclassing
|
42
|
+
|
43
|
+
# Load data from a file or phony
|
44
|
+
def load(content)
|
45
|
+
raise "#{self}.load not implemented"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Task System
|
2
|
+
|
3
|
+
module Nova
|
4
|
+
class Task
|
5
|
+
Tasks = {}
|
6
|
+
|
7
|
+
def self.require_all
|
8
|
+
Nova.require_folder :tasks
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.[](key)
|
12
|
+
Tasks[key.to_sym] || []
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.[]=(key, value)
|
16
|
+
Tasks[key.to_sym] ||= []
|
17
|
+
Tasks[key.to_sym] << value
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.invoke(name, params = {})
|
21
|
+
total = self[name].count
|
22
|
+
raise "Task #{name} not found" if total == 0
|
23
|
+
self[name].each_with_index do |task, idx|
|
24
|
+
puts "===> #{idx + 1}/#{total} #{task}"
|
25
|
+
task.new.invoke(params)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# For Register
|
30
|
+
|
31
|
+
def self.task(*names)
|
32
|
+
names.flatten.each do |name|
|
33
|
+
Nova::Task[name] = self
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# For subclassing
|
38
|
+
|
39
|
+
def invoke(params = {})
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class Nova::Task::Compile < Nova::Task
|
2
|
+
task :compile
|
3
|
+
|
4
|
+
def load_data
|
5
|
+
# Load regular data
|
6
|
+
Dir["#{Nova.local_root}/data/*"].each do |file|
|
7
|
+
key = File.basename(file).split('.').first.downcase.to_sym
|
8
|
+
extname = file.split('.').last.to_sym
|
9
|
+
if Nova::Loader.supported_extensions.include?(extname)
|
10
|
+
content = File.open(file).read
|
11
|
+
Nova.data[key] = Nova::Loader[extname].new.load(content)
|
12
|
+
else
|
13
|
+
raise "Data file extension '#{extname}' not supported"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
# Load phony data
|
17
|
+
Nova::Loader::Phony.each_pair do |key, clazz|
|
18
|
+
Nova.data[key] = clazz.new.load(key)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def invoke(params = {})
|
23
|
+
raise "Nova.local_root not set" unless Nova.local_root
|
24
|
+
raise "Nova.src_root not set" unless Nova.src_root
|
25
|
+
|
26
|
+
Nova::Helper.require_all
|
27
|
+
Nova::Loader.require_all
|
28
|
+
Nova::Engine.require_all
|
29
|
+
|
30
|
+
self.load_data
|
31
|
+
|
32
|
+
# Find all *.erb and render from yml file
|
33
|
+
Dir["#{Nova.src_root}/**/*"].each do |file|
|
34
|
+
extname = file.split('.').last.to_sym
|
35
|
+
if Nova::Engine.supported_extensions.include? extname
|
36
|
+
template= File.open(file).read
|
37
|
+
target = File.join File.dirname(file), File.basename(file, ".*")
|
38
|
+
puts "File Rendering: #{target}"
|
39
|
+
result = Nova::Engine[extname].new.render(template, Nova.data, target)
|
40
|
+
File.open(target, 'w') { |tf| tf.write(result) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
puts "Done !"
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cocoanova
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yanke Guo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
description: CocoaNova is a iOS project management toolkit, providing code generator
|
28
|
+
and assets checking.
|
29
|
+
email: me@yanke.io
|
30
|
+
executables:
|
31
|
+
- nova
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- lib/cocoanova/engine.rb
|
36
|
+
- lib/cocoanova/engines/erb.rb
|
37
|
+
- lib/cocoanova/helper.rb
|
38
|
+
- lib/cocoanova/loader.rb
|
39
|
+
- lib/cocoanova/loaders/json.rb
|
40
|
+
- lib/cocoanova/loaders/txt.rb
|
41
|
+
- lib/cocoanova/loaders/yaml.rb
|
42
|
+
- lib/cocoanova/task.rb
|
43
|
+
- lib/cocoanova/tasks/compile.rb
|
44
|
+
- lib/cocoanova/version.rb
|
45
|
+
- lib/cocoanova.rb
|
46
|
+
- bin/nova
|
47
|
+
homepage: http://rubygems.org/gems/cocoanova
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 2.0.14
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: CocoaNova is a iOS project management toolkit
|
71
|
+
test_files: []
|