Permalink
Browse files

remove system template data

  • Loading branch information...
1 parent 12ae2e7 commit 06c545ce6478bdff11ddfc26cf75d5034eb1c71b @gutenye committed Dec 7, 2011
@@ -1,26 +0,0 @@
-
-file layout
-
- bin/
-
- lib/
- \__project__/
- ...
- \__project__.rb
-
- spec/
- spec_helper.rb
- \__project__
- ...
- \__project__.watchr
-
- Gemfile
- Ragfile
- \__project__.gemspec
- version.rb
-
- LICENSE
- README
-
-
-# vim: filetype=markdown
@@ -1 +0,0 @@
-*~
@@ -1 +0,0 @@
---color
@@ -1,9 +0,0 @@
-source "http://rubygems.org"
-
-group :development do
- gem 'rspec'
- gem 'watchr'
- gem 'rag'
-end
-
-gemspec
@@ -1,20 +0,0 @@
-Copyright (c) 2011 <%=author%>
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-'Software'), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,47 +0,0 @@
-Foo, a very good library
-========================
-
-**Homepage**: [https://github.com/<%=github.username%>/<%=project%>](https://github.com/<%=github.username%>/<%=project%>) <br/>
-**Author**: <%=author%> <br/>
-**License**: <%=license%> <br/>
-**Documentation**: [http://rubydoc.info/gems/<%=project%>/frames](http://rubydoc.info/gems/<%=project%>/frames) <br/>
-**Issue Tracker**: [https://github.com/<%=github.username%>/<%=project%>/issues](https://github.com/<%=github.username%>/<%=project%>/issues) <br/>
-
-Overview
---------
-
- descripe your prjoect here.
-
-Features
---------
-
- a clearly list of features.
-
-Usage
------
-
- how to use
-
-Contributing
--------------
-
-* Feel free to join the project and make contributions (by submitting a pull request)
-* Submit any bugs/features/ideas to github issue tracker
-* Coding Style Guide: https://gist.github.com/1105334
-
-* [a list of contributors](https://github.com/<%=github.username%>/<%=project%>/contributors)
-
-Install
-----------
-
- gem install <%=project%>
-
-Resources
----------
-
- some related resources to help each other.
-
-Copyright
----------
-
-Copyright &copy; 2011 by <%=author%>. this library released under <%=license%>, See {file:LICENSE} for futher details.
@@ -1,5 +0,0 @@
-# add your own task in Ragfile or in tasks/*.rag
-class Rag < Thor
-end
-
-# vim: filetype=ruby
@@ -1,21 +0,0 @@
-$: << "."
-require "lib/<%=project%>/version"
-
-Gem::Specification.new do |s|
- s.name = "<%=project%>"
- s.version = <%=project.capitalize%>::VERSION::IS
- s.summary = "a good lib"
- s.description = <<-EOF
-a good lib
- EOF
-
- s.author = "<%=author%>"
- s.email = "<%=email%>"
- s.homepage = "http://github.com/<%=github.username%>/<%=project%>"
- s.rubyforge_project = "xx"
-
- s.files = `git ls-files`.split("\n")
- #s.executables = ["x"]
-
- #s.add_dependency "x"
-end
@@ -1,22 +0,0 @@
-# lib/**/*.rb
-watch %r~lib/(.*)\.rb~ do |m|
- test "spec/#{m[1]}_spec.rb"
-end
-
-# spec/**/*_spec.rb
-watch %r~spec/.*_spec\.rb~ do |m|
- test m[0]
-end
-
-# Ctrl-\
-Signal.trap('QUIT') do
- puts "--- Running all tests ---\n\n"
- test "spec"
-end
-
-def test path
- cmd = "rspec #{path}"
- puts cmd
- system cmd
-end
-
@@ -1,6 +0,0 @@
-libdir = File.dirname(__FILE__)
-$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
-
-module <%=project.capitalize%>
- autoload :VERSION, "<%=project%>/version"
-end
@@ -1,9 +0,0 @@
-module <%=project.capitalize%>
- module VERSION
- MAJOR = 0
- MINOR = 1
- PATCH = 0
- PRE = '' # beta rc1
- IS = [MAJOR, MINOR, PATCH].join(".") + PRE
- end
-end
View
@@ -23,7 +23,7 @@ class << self
attr_accessor :ui
def ui
- @ui ||= UI.new
+ @ui ||= UI::Base.new
end
end
View
@@ -1,35 +1,28 @@
-require_relative "new/project"
+require_relative 'new/project'
class Rag < Thor
- desc "new <project_name> or new .", "create a new project or use current directory"
- method_option "author", :type => :string, :banner => "NAME", :desc => "the project's author name"
- method_option "email", :type => :string, :desc => "author's email address"
- method_option "template", :type => :string, :default => "default", :banner => "NAME", :desc => "which template to use"
- method_option "name", :type => :string, :banner => "NAME", :desc => "rag new . [--name hello] default from File.basename(cur_path)"
- method_option "list", :type => :boolean, :aliases => "-l", :desc => "list templates"
- def new name
- if options.list?
- Project.list_templates
- end
-
- check_first_time
+ desc 'new <name> [class_name]', 'create a new project'
+ method_option 'template', :aliases => '-t', :default => 'default', :type => :string, :banner => 'NAME', :desc => 'which template to use'
+ def new(name, class_name=nil)
+ check_first_time!
- Project.create name, options
+ class_name ||= name.capitalize
+ Project.create name, class_name, options
end
private
- def check_first_time
+ def check_first_time!
return unless first_time?
- puts "first time run rag"
- Rc.p.data.join("home_config").each do |src|
+ puts 'first time run rag'
+ Rc.p.data.join('home_config').each do |src|
dest = '~/' + src.b.sub(/^_/, '.')
puts "[create] #{dest.short}"
Pa.cp src, dest
end
- puts "exit."
- puts "please edit ~/.ragrc config file, then run rag again"
+ puts 'exit.'
+ puts 'please edit ~/.ragrc config file, then run rag again'
exit
end
@@ -16,35 +16,23 @@ class Rag
=end
class Project
class << self
- def create(name, o={})
- Project.new(name, o).create
- end
-
- # find templates
- def templates
- templates = []
- templates << Rc.p.data.join("template").ls - %w(test)
- home_template_pa = Rc.p.home.join("template")
- templates << home_template_pa.ls if home_tempate_pa.exists?
- end
-
- # call by `rag new -l'
- def list_templates
- puts self.templates.join('\n')
+ def create(*args)
+ Project.new(*args).create
end
end
- attr_reader :options, :name, :project
- def initialize(name, o={})
+ attr_reader :options, :template_name, :name, :class_name, :project
+ def initialize(template_name, name, class_name, o={})
+ @template_name = template_name
@name = name
@options = o
- @project = o["name"] ? o["name"] : (name=="." ? Rc.pwd.fname : name)
+ @project = o['name'] ? o['name'] : (name=='.' ? Rc.pwd.fname : name)
@dest = Pa(@name)
end
def create
create_project_directory
- if name=="."
+ if name=='.'
copy_files
else
copy_files :overwrite => true
@@ -53,7 +41,7 @@ def create
private
def create_project_directory
- if @name=="."
+ if @name=='.'
return
elsif @dest.exists?
puts "dest directory `#{@name}' already existing"
@@ -64,13 +52,10 @@ def create_project_directory
end
def template_path
- pa1 = Rc.p.home.join(options[:template])
+ pa1 = Rc.p.home.join(template_name)
return pa1.p if pa1.exists?
- pa2 = Rc.p.data.join("template", options[:template])
- return pa2.p if pa2.exists?
-
- raise Error, "can't find template -- #{options[:template]}"
+ raise Error, "can't find template -- #{template_name}"
end
def copy_files(o={})
@@ -88,14 +73,14 @@ def copy_files(o={})
if not o[:overwrite] and (dest.exists? or dest.sub(/\.erb$/, '').exists?)
print "Overwrite #{path_msg}? [yna] "
case $stdin.gets.rstrip
- when "y"
+ when 'y'
puts "[overwrite] #{path_msg}"
copy_file pa, dest, o
- when "a"
+ when 'a'
puts "[overwrite] #{path_msg}"
o[:overwrite] = true
copy_file pa, dest, o
- when "q"
+ when 'q'
exit
else
puts "[skip] #{path_msg}"
@@ -115,7 +100,7 @@ def copy_files(o={})
# not rescurive copy
def copy_file(src, dest, o)
- if src.e=='erb'
+ if src.e == 'erb'
copy_erb_file src, dest.sub(/\.erb$/,'')
else
Pa.cp src, dest, o.merge(special: true)
@@ -130,7 +115,9 @@ def copy_erb_file(src, dest)
def get_erb_config
config = Optimism.require(Rc.p.apprc.p, Rc.p.homerc.p) + Optimism[options]
- config["project"] = project
+ config['project'] = project
+ config['klass'] = class_name
+ config['template'] = template_name
config._data
end
@@ -1,6 +1,6 @@
-require "spec_helper"
-require "fileutils"
-require "tmpdir"
+require 'spec_helper'
+require 'fileutils'
+require 'tmpdir'
describe Rag::Project do
before :all do
@@ -14,14 +14,9 @@
Dir.chdir(@curdir)
end
- describe ".create" do
- before :all do
- Rag::Project.create "guten", template: 'default', author: 'Test', email: 'test@test.com'
+ describe '.create' do
+ it 'runs ok' do
+ Rag::Project.create 'default', 'guten', 'Guten', :author => 'Guten', :email => 'a@a.com'
end
-
- it "runs ok" do
- end
-
end
-
end

0 comments on commit 06c545c

Please sign in to comment.