Permalink
Browse files

Initial commit

  • Loading branch information...
Paul Engel
Paul Engel committed Oct 15, 2011
0 parents commit a768589760fb855a6a75753e3897f895fce014ec
@@ -0,0 +1,4 @@
+.DS_Store
+.bundle
+Gemfile.lock
+pkg/*
@@ -0,0 +1,5 @@
+= JazzLibs CHANGELOG
+
+== Version 0.1.0 (October 15, 2011)
+
+* Initial release
@@ -0,0 +1,3 @@
+source "http://rubygems.org"
+
+gemspec
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Paul Engel
+
+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.
@@ -0,0 +1,54 @@
+h1. JazzLibs
+
+A small gem for generating a Javascript library repository
+
+h2. Introduction
+
+*WARNING: THIS GEM IS NOT AVAILABLE YET*
+
+Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+
+h2. Installation
+
+Run the following command in your console:
+
+<pre>
+ gem install jazz_libs
+</pre>
+
+h2. Usage
+
+Run the following command to create a Javascript library repository:
+
+<pre>
+ jazz new your_library_name
+</pre>
+
+*Note*: You will be asked a couple questions concerning the library (e.g. a small description, your Twitter name).
+
+h2. Contact me
+
+For support, remarks and requests please mail me at "paul.engel@holder.nl":mailto:paul.engel@holder.nl.
+
+h2. Credit
+
+The generated Javascript library structure is based on Eric Miraglia's ("@miraglia":http://twitter.com/miraglia) JavaScript Module Pattern:
+
+"http://www.yuiblog.com":http://www.yuiblog.com / "the-blog-post":http://www.yuiblog.com/blog/2007/06/12/module-pattern/
+
+h2. ToDo's
+
+* Add "SASS":http://sass-lang.com facilities like in "RaccoonTip":https://github.com/archan937/raccoon_tip/blob/master/Rakefile
+* Add "Jzip":https://github.com/archan937/jzip/tree/edge facilities like in "Rich-CMS":https://github.com/archan937/rich_cms/blob/edge/Rakefile
+
+h2. License
+
+Copyright (c) 2011 Paul Engel, released under the MIT license
+
+"http://holder.nl":http://holder.nl – "http://github.com/archan937":http://github.com/archan937 – "http://codehero.es":http://codehero.es – "http://gettopup.com":http://gettopup.com – "http://twitter.com/archan937":http://twitter.com/archan937 – "paul.engel@holder.nl":mailto:paul.engel@holder.nl
+
+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.
@@ -0,0 +1,2 @@
+require "bundler"
+Bundler::GemHelper.install_tasks
@@ -0,0 +1 @@
+0.1.0
@@ -0,0 +1,10 @@
+#!/usr/bin/env ruby
+
+require "rubygems"
+require "jazz_libs/cli"
+
+begin
+ JazzLibs::CLI.start
+rescue JazzLibs::CLI::Error => e
+ puts e.message.red
+end
@@ -0,0 +1,23 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "jazz_libs/version"
+
+Gem::Specification.new do |s|
+ s.name = "jazz_libs"
+ s.version = JazzLibs::VERSION::STRING
+ s.authors = ["Paul Engel"]
+ s.email = ["paul.engel@holder.nl"]
+ s.homepage = "https://github.com/archan937/jazz_libs"
+ s.summary = %q{A small gem for rolling out JS libraries (includes repository, demo page and version release rake task)}
+ s.description = %q{A small gem for rolling out JS libraries (includes repository, demo page and version release rake task)}
+
+ s.rubyforge_project = "jazz_libs"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ s.add_dependency "rich_support", "~> 0.1.2"
+ s.add_dependency "thor" , "~> 0.14.6"
+end
@@ -0,0 +1 @@
+require "jazz_libs/version"
@@ -0,0 +1,26 @@
+require "thor"
+require "rich/support/core/string/colorize"
+
+require "jazz_libs/cli/core_ext"
+require "jazz_libs/cli/generator"
+require "jazz_libs/version"
+
+module JazzLibs
+ class CLI < Thor
+
+ class Error < StandardError; end
+
+ desc "new REPO", "Generate a Javascript library (specify the repository name)"
+ method_options [:verbose, "-v"] => false
+ def new(repository)
+ Generator.new.run repository
+ end
+
+ private
+
+ def method_missing(method, *args)
+ raise Error, "Unrecognized command \"#{method}\". Please consult `jazz help`."
+ end
+
+ end
+end
@@ -0,0 +1,3 @@
+Dir["#{File.dirname(__FILE__)}/core_ext/*.rb"].sort.each do |file|
+ require file
+end
@@ -0,0 +1,5 @@
+class NilClass
+ def blank?
+ true
+ end
+end
@@ -0,0 +1,5 @@
+class String
+ def blank?
+ nil? || empty?
+ end
+end
@@ -0,0 +1,127 @@
+require "thor/shell/basic"
+require "fileutils"
+
+module JazzLibs
+ class CLI < Thor
+ class Generator < Thor
+ include Thor::Actions
+
+ def self.source_root
+ File.expand_path "../../../../templates", __FILE__
+ end
+
+ no_tasks do
+ def run(repository)
+ ask_for_locals :repository => repository, :now => Time.now
+ create_lib_directory
+ install_default_files
+ end
+ end
+
+ private
+
+ def ask_for_locals(defaults)
+ @locals = defaults.dup
+
+ @locals[:name] = ask "What is the (non-underscored) name of the Javascript library?"
+ raise Error, "Invalid library name" if name.empty?
+
+ @locals[:file_name] = repository.gsub(/\.js$/, "") + ".js"
+ @locals[:class_name] = camelize repository.gsub(/\.js$/, "")
+
+ @locals[:small_description] = ask "Describe the Javascript library in one sentence:"
+ @locals[:jquery] = agree? "Do you want to include jQuery to your library?", :no
+ @locals[:author] = ask "What is your full name?"
+ @locals[:email] = ask "What is your email address?"
+ @locals[:github] = ask "What is your Github name?"
+ @locals[:twitter] = ask "What is your Twitter name? (press Enter to skip)"
+ @locals[:company] = ask "What is your company name? (press Enter to skip)"
+
+ @locals[:company_url] = begin
+ company.empty? ? "" : ask("What is your company URL? (press Enter to skip)")
+ end
+
+ unless company_url.blank? || company_url.match(/^https?:\/\/\w+/)
+ @locals[:company_url] = "http://#{company_url}"
+ end
+ end
+
+ def create_lib_directory
+ self.destination_root = File.expand_path "./#{repository}"
+
+ if File.exists? self.destination_root
+ if agree? "The directory '#{name}' already exists. Do you want to replace it?", :no
+ FileUtils.rm_r self.destination_root, :force => true
+ else
+ raise Error, "Aborting..."
+ end
+ end
+
+ FileUtils.mkdir self.destination_root
+ end
+
+ def install_default_files
+ template "CHANGELOG.rdoc"
+ template "MIT-LICENSE"
+ template "Rakefile"
+ template "README.textile"
+ template "VERSION"
+ directory "demo"
+ directory "lib"
+ template "demo/index.html", :force => true
+ directory "src/jquery" if jquery
+ template "src/lib.js", File.expand_path("src/#{file_name}", self.destination_root)
+
+ execute "git init"
+ template "gitignore", ".gitignore"
+ execute "git add -A"
+ end
+
+ def thor_shell
+ @thor_shell ||= Thor::Shell::Basic.new
+ end
+
+ def is?(*args)
+ thor_shell.send :is?, *args
+ end
+
+ def ask(question, opts = nil, default = nil)
+ in_brackets = [opts, default].compact.first
+ statement = [question, ("[#{in_brackets}]" unless in_brackets.nil?)].compact.join " "
+ answer = thor_shell.ask statement.yellow
+ answer.nil? || answer.empty? ? default.to_s : answer
+ rescue Interrupt
+ puts ""
+ exit
+ end
+
+ def agree?(question, default = nil)
+ opts = %w(y n).collect{|x| !default.nil? && x =~ is?(default) ? x.upcase : x}
+ answer = ask question, opts, default
+ !!(answer =~ is?(:yes))
+ end
+
+ def execute(command)
+ `cd #{self.destination_root} && #{command}`
+ end
+
+ def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
+ if first_letter_in_uppercase
+ lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
+ else
+ lower_case_and_underscored_word.to_s[0].chr.downcase + camelize(lower_case_and_underscored_word)[1..-1]
+ end
+ end
+
+ def method_missing(method, *args)
+ if @locals && @locals.include?(method.to_sym)
+ @locals[method.to_sym]
+ else
+ puts caller
+ super
+ end
+ end
+
+ end
+ end
+end
@@ -0,0 +1,9 @@
+module JazzLibs
+ module VERSION
+ MAJOR = 0
+ MINOR = 1
+ TINY = 0
+
+ STRING = [MAJOR, MINOR, TINY].join(".")
+ end
+end
@@ -0,0 +1,5 @@
+= <%= name %> CHANGELOG
+
+== Version 0.0.1 (<%= now.strftime "%B xxx, %Y" %>)
+
+* Initial release
@@ -0,0 +1,20 @@
+Copyright (c) <%= now.strftime "%Y" %> <%= 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.
Oops, something went wrong.

0 comments on commit a768589

Please sign in to comment.