majic 0.2 → 0.3
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.
- data/executables/majic +15 -0
- data/library/majic/generator.rb +21 -0
- data/library/majic/stubs/project.rb +69 -0
- data/library/majic/templates/project/Gemfile +3 -0
- data/library/majic/templates/project/Gemspec +26 -0
- data/library/majic/templates/project/License +13 -0
- data/library/majic/templates/project/README.md +3 -0
- data/library/majic/templates/project/executables/_name_.rb +7 -0
- data/library/majic/templates/project/library/_name_.rb +10 -0
- data/library/majic.rb +8 -3
- metadata +37 -6
- data/library/majic/class.rb +0 -11
data/executables/majic
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'thor'
|
5
|
+
require 'majic'
|
6
|
+
|
7
|
+
class Majic::CLI < Thor
|
8
|
+
desc "project [name]", "Generate a new project skeleton."
|
9
|
+
def project name
|
10
|
+
@generator = Majic::Generator.new :project, name: name
|
11
|
+
@generator.generate
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Majic::CLI.start
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Majic
|
4
|
+
class Generator
|
5
|
+
def self.template_root template
|
6
|
+
absolute = File.expand_path File.dirname(__FILE__) + '/templates'
|
7
|
+
Pathname.new File.join absolute, template
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize type = :project, options = {}
|
11
|
+
@klass = (type == :project ? Project : NilClass)
|
12
|
+
@options = options
|
13
|
+
|
14
|
+
@stub = @klass.new @options
|
15
|
+
end
|
16
|
+
|
17
|
+
def generate
|
18
|
+
@stub.commence
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Majic
|
4
|
+
class Generator
|
5
|
+
class Project
|
6
|
+
attr_accessor :root, :path
|
7
|
+
|
8
|
+
MessageLevels = [:exists, :create, :executable]
|
9
|
+
MessageColors = { exists: :red, create: :green, executable: :yellow }
|
10
|
+
|
11
|
+
def self.source_root *args
|
12
|
+
Generator.template_root File.join "project", *args
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize options = {}
|
16
|
+
unless options[:name]
|
17
|
+
raise "You can't generate a project stub without a project name."
|
18
|
+
end
|
19
|
+
|
20
|
+
@name = options[:name]
|
21
|
+
@root = Pathname.new Dir.pwd
|
22
|
+
@path = @root + @name
|
23
|
+
end
|
24
|
+
|
25
|
+
def commence
|
26
|
+
@path.mkpath unless @path.exist?
|
27
|
+
|
28
|
+
Pathname.glob(Project.source_root("**/*")).each do |path|
|
29
|
+
post_relative = path.relative_path_from Project.source_root
|
30
|
+
output_path = (@path + post_relative).sub '_name_', @name
|
31
|
+
relative_path = output_path.relative_path_from(@root).to_s
|
32
|
+
|
33
|
+
if path.file?
|
34
|
+
unless output_path.exist?
|
35
|
+
template = Erubis::Eruby.new path.read
|
36
|
+
|
37
|
+
output_path.open "w+" do |file|
|
38
|
+
file.write template.result _name_: @name
|
39
|
+
end
|
40
|
+
|
41
|
+
notify :create, relative_path
|
42
|
+
else
|
43
|
+
notify :exists, relative_path
|
44
|
+
end
|
45
|
+
else
|
46
|
+
unless output_path.exist?
|
47
|
+
notify :create, relative_path
|
48
|
+
|
49
|
+
output_path.mkpath
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def notify level = :exists, path
|
58
|
+
@@max_width ||= MessageLevels.map(&:length).max
|
59
|
+
|
60
|
+
puts format level, path
|
61
|
+
end
|
62
|
+
|
63
|
+
def format level, message
|
64
|
+
level = level.to_s.rjust(@@max_width) ^ MessageColors[level]
|
65
|
+
[level, message].join " "
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/gem build
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
$:.unshift File.dirname(__FILE__) + '/library'
|
5
|
+
require '<%= _name_ %>'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "<%= _name_ %>"
|
9
|
+
spec.version = <%= _name_.capitalize %>::Version
|
10
|
+
spec.summary = %{No summary.}
|
11
|
+
spec.description = <<-eos
|
12
|
+
No description.
|
13
|
+
eos
|
14
|
+
|
15
|
+
spec.license = "ISC"
|
16
|
+
|
17
|
+
spec.author = "John Doe"
|
18
|
+
spec.email = "john.doe@gmail.com"
|
19
|
+
|
20
|
+
spec.files = Dir["library/**/*.rb"]
|
21
|
+
spec.require_path = "library"
|
22
|
+
|
23
|
+
spec.add_dependency "majic"
|
24
|
+
end
|
25
|
+
|
26
|
+
# vim: set syntax=ruby:
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) <%= Date.today.year %>, John Doe <john.doe@gmail.com>
|
2
|
+
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
4
|
+
purpose with or without fee is hereby granted, provided that the above
|
5
|
+
copyright notice and this permission notice appear in all copies.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
data/library/majic.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'set'
|
4
|
+
require 'date'
|
5
|
+
require 'erubis'
|
6
|
+
require 'pathname'
|
4
7
|
|
5
|
-
require 'majic/
|
8
|
+
require 'majic/object'
|
6
9
|
require 'majic/logging'
|
10
|
+
require 'majic/generator'
|
7
11
|
require 'majic/ansi_escape'
|
12
|
+
require 'majic/stubs/project'
|
8
13
|
|
9
14
|
module Majic
|
10
|
-
Version = "0.
|
15
|
+
Version = "0.3"
|
11
16
|
end
|
12
17
|
|
13
|
-
::Logging = Majic::Logging unless defined? ::Logging
|
18
|
+
::Logging = Majic::Logging unless defined? ::Logging
|
metadata
CHANGED
@@ -1,27 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: majic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.3'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Mikkel Kroman
|
9
9
|
autorequire:
|
10
|
-
bindir:
|
10
|
+
bindir: executables
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10-
|
13
|
-
dependencies:
|
12
|
+
date: 2011-10-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: thor
|
16
|
+
requirement: &14633640 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *14633640
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: erubis
|
27
|
+
requirement: &14633200 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *14633200
|
14
36
|
description:
|
15
37
|
email: mk@maero.dk
|
16
|
-
executables:
|
38
|
+
executables:
|
39
|
+
- majic
|
17
40
|
extensions: []
|
18
41
|
extra_rdoc_files: []
|
19
42
|
files:
|
20
43
|
- library/majic.rb
|
21
44
|
- library/majic/ansi_escape.rb
|
22
45
|
- library/majic/logging.rb
|
23
|
-
- library/majic/
|
46
|
+
- library/majic/stubs/project.rb
|
24
47
|
- library/majic/object.rb
|
48
|
+
- library/majic/generator.rb
|
49
|
+
- library/majic/templates/project/Gemfile
|
50
|
+
- library/majic/templates/project/library/_name_.rb
|
51
|
+
- library/majic/templates/project/executables/_name_.rb
|
52
|
+
- library/majic/templates/project/Gemspec
|
53
|
+
- library/majic/templates/project/License
|
54
|
+
- library/majic/templates/project/README.md
|
55
|
+
- executables/majic
|
25
56
|
homepage:
|
26
57
|
licenses: []
|
27
58
|
post_install_message:
|