majic 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 91dbcd5678033aa8520dd14a353171e43b91c88f
4
+ data.tar.gz: 29f5d817dfda0e0e1a207804a77e08dd449b3487
5
+ SHA512:
6
+ metadata.gz: fcce50e6caa841d25c52e699bd019bdba90688197ef04c031a169745bd9451e4f11fe9265463936c2dbeb2f64a1fae6f0a5bf6046b40fa4da8e12b91a64777e1
7
+ data.tar.gz: 663d221b0418612c2f88d0c96d1cd5aa37ed56d1ecc74ef985fd9b4a8d6dd8362f81686529cebaada23bfab7e896ff182603b81aa81ec83bfedef53cbedcf57f
data/executables/majic CHANGED
@@ -1,15 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
 
4
- require 'thor'
4
+ $:.unshift File.dirname(__FILE__) + '/../library'
5
5
  require 'majic'
6
+ require 'majic/generator'
6
7
 
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
8
+ Thor.register Majic::Generator, 'generate', 'generate [command]', 'Generate a new entity.'
9
+ Thor.start ARGV
14
10
 
15
- Majic::CLI.start
11
+ # vim: syntax=ruby
@@ -0,0 +1,16 @@
1
+ class String
2
+ def truncate! length, position = :middle
3
+ case position
4
+ when :middle
5
+ replace ellipsize length
6
+ end
7
+ end
8
+
9
+ def ellipsize length = 9
10
+ return self if self.size <= length
11
+
12
+ remainder = length - 3
13
+ offset = remainder / 2
14
+ (self[0, offset + (remainder.odd? ? 1 : 0)].to_s + '…' + self[-offset, offset].to_s)[0, length].to_s
15
+ end unless defined? ellipsize
16
+ end
@@ -1,21 +1,31 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require 'thor'
4
+
3
5
  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
6
+ class Generator < Thor
7
+ include Thor::Actions
8
+ namespace :generate
9
9
 
10
- def initialize type = :project, options = {}
11
- @klass = (type == :project ? Project : NilClass)
12
- @options = options
10
+ desc "project <name>", "Generate a new project."
11
+ def project name
12
+ @name = name
13
13
 
14
- @stub = @klass.new @options
14
+ directory 'templates/project', name
15
15
  end
16
16
 
17
- def generate
18
- @stub.commence
17
+ no_commands do
18
+ # Return the lowercase name.
19
+ def downcase_name
20
+ @name.downcase
21
+ end
22
+
23
+ # Return the name
24
+ def name
25
+ @name
26
+ end
19
27
  end
20
28
  end
21
29
  end
30
+
31
+ Majic::Generator.source_root File.dirname(__FILE__)
@@ -5,7 +5,7 @@ module Majic
5
5
  Levels = [:debug, :info, :warn, :error, :fatal]
6
6
  LevelColors = { debug: :white, info: :blue, warn: :yellow, error: :red, fatal: :orange }
7
7
 
8
- DefaultNameCutoff = 10
8
+ DefaultNameCutoff = 18
9
9
  UnknownLevelError = Class.new RuntimeError
10
10
 
11
11
  @level = Levels.first
@@ -133,4 +133,4 @@ module Majic
133
133
  end
134
134
  end
135
135
  end
136
- end
136
+ end
data/library/majic.rb CHANGED
@@ -1,18 +1,15 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'set'
4
- require 'date'
5
- require 'erubis'
6
- require 'pathname'
7
4
 
8
- require 'majic/object'
5
+ require 'majic/core_extensions/object'
6
+ require 'majic/core_extensions/string'
7
+
9
8
  require 'majic/logging'
10
- require 'majic/generator'
11
9
  require 'majic/ansi_escape'
12
- require 'majic/stubs/project'
13
10
 
14
11
  module Majic
15
- Version = "0.3"
12
+ Version = "0.4"
16
13
  end
17
14
 
18
15
  ::Logging = Majic::Logging unless defined? ::Logging
metadata CHANGED
@@ -1,80 +1,52 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: majic
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
5
- prerelease:
4
+ version: '0.4'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mikkel Kroman
9
8
  autorequire:
10
9
  bindir: executables
11
10
  cert_chain: []
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
36
- description:
37
- email: mk@maero.dk
11
+ date: 2013-10-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Toolkit for Ruby
14
+ email: mk@uplink.io
38
15
  executables:
39
16
  - majic
40
17
  extensions: []
41
18
  extra_rdoc_files: []
42
19
  files:
43
20
  - library/majic.rb
44
- - library/majic/ansi_escape.rb
45
- - library/majic/logging.rb
46
- - library/majic/stubs/project.rb
47
- - library/majic/object.rb
48
21
  - 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
22
+ - library/majic/logging.rb
23
+ - library/majic/core_extensions/string.rb
24
+ - library/majic/core_extensions/object.rb
25
+ - library/majic/ansi_escape.rb
55
26
  - executables/majic
56
- homepage:
57
- licenses: []
27
+ homepage: http://uplink.io
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
58
31
  post_install_message:
59
32
  rdoc_options: []
60
33
  require_paths:
61
34
  - library
62
35
  required_ruby_version: !ruby/object:Gem::Requirement
63
- none: false
64
36
  requirements:
65
- - - ! '>='
37
+ - - ">="
66
38
  - !ruby/object:Gem::Version
67
39
  version: '0'
68
40
  required_rubygems_version: !ruby/object:Gem::Requirement
69
- none: false
70
41
  requirements:
71
- - - ! '>='
42
+ - - ">="
72
43
  - !ruby/object:Gem::Version
73
44
  version: '0'
74
- requirements: []
45
+ requirements:
46
+ - 'Thor, for generating stubs '
75
47
  rubyforge_project:
76
- rubygems_version: 1.8.10
48
+ rubygems_version: 2.1.3
77
49
  signing_key:
78
- specification_version: 3
50
+ specification_version: 4
79
51
  summary: A set of utillities for Ruby
80
52
  test_files: []
@@ -1,69 +0,0 @@
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
@@ -1,3 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- gem "majic"
@@ -1,26 +0,0 @@
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:
@@ -1,13 +0,0 @@
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.
@@ -1,3 +0,0 @@
1
- <%= _name_.capitalize %>
2
- <%= '=' * _name_.length %>
3
- To be written.
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
-
4
- $:.unshift File.dirname(__FILE__) + '/../library'
5
- require '<%= _name_ %>'
6
-
7
- puts "=> #{'<%= _name_.capitalize %>' ^ :bold} v#{<%= _name_.capitalize %>::Version}"
@@ -1,10 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'majic'
4
- require 'bundler'
5
-
6
- Bundler.setup :default
7
-
8
- module <%= _name_.capitalize %>
9
- Version = "0.1"
10
- end