Permalink
Browse files

SimpleTemplater, RubyExts and CLI divided into separate projects

  • Loading branch information...
1 parent 27c529e commit 3dd6088e5e87c1e937e68df809e4924d67b2af23 Jakub Stastny committed Oct 27, 2009
Showing with 32 additions and 2,202 deletions.
  1. +9 −0 .gitmodules
  2. +2 −1 CHANGELOG
  3. +2 −2 README.textile
  4. +2 −1 deps.rip
  5. +0 −1 lib/rango/boot.rb
  6. +0 −126 lib/rango/cli/generator.rb
  7. +0 −89 lib/rango/cli/templater.rb
  8. +0 −90 lib/rango/ext.rb
  9. +0 −20 lib/rango/ext/array.rb
  10. +0 −152 lib/rango/ext/attribute.rb
  11. +0 −59 lib/rango/ext/cli.rb
  12. +0 −104 lib/rango/ext/colored_string.rb
  13. +0 −30 lib/rango/ext/enumerable.rb
  14. +0 −84 lib/rango/ext/file.rb
  15. +0 −147 lib/rango/ext/hash.rb
  16. +0 −91 lib/rango/ext/kernel.rb
  17. +0 −6 lib/rango/ext/module.rb
  18. +0 −56 lib/rango/ext/object.rb
  19. +0 −16 lib/rango/ext/object_space.rb
  20. +0 −89 lib/rango/ext/os.rb
  21. +0 −27 lib/rango/ext/platform.rb
  22. +0 −25 lib/rango/ext/random.rb
  23. +0 −38 lib/rango/ext/string.rb
  24. +0 −1 lib/rango/ext/thor.rb
  25. +0 −15 lib/rango/ext/time.rb
  26. +0 −62 lib/rango/ext/time_dsl.rb
  27. +0 −16 lib/rango/ext/unique_array.rb
  28. +2 −2 rango.gemspec
  29. +0 −1 script/autospec
  30. +0 −1 script/spec
  31. +12 −0 script/spec
  32. 0 spec/rango/cli/generator_spec.rb
  33. 0 spec/rango/cli/templater_spec.rb
  34. +0 −19 spec/rango/ext/array_spec.rb
  35. +0 −37 spec/rango/ext/attribute_spec.rb
  36. 0 spec/rango/ext/cli_spec.rb
  37. +0 −9 spec/rango/ext/colored_string_spec.rb
  38. +0 −52 spec/rango/ext/enumerable_spec.rb
  39. +0 −78 spec/rango/ext/file_spec.rb
  40. +0 −91 spec/rango/ext/hash_spec.rb
  41. +0 −9 spec/rango/ext/kernel_spec.rb
  42. 0 spec/rango/ext/module_spec.rb
  43. +0 −17 spec/rango/ext/object_space_spec.rb
  44. +0 −57 spec/rango/ext/object_spec.rb
  45. +0 −121 spec/rango/ext/os_spec.rb
  46. 0 spec/rango/ext/platform_spec.rb
  47. +0 −31 spec/rango/ext/random_spec.rb
  48. +0 −23 spec/rango/ext/string_spec.rb
  49. +0 −25 spec/rango/ext/thor_spec.rb
  50. +0 −88 spec/rango/ext/time_dsl_spec.rb
  51. +0 −11 spec/rango/ext/time_spec.rb
  52. 0 spec/rango/ext/unique_array_spec.rb
  53. +0 −182 spec/rango/ext_spec.rb
  54. +1 −0 vendor/cli
  55. +1 −0 vendor/rubyexts
  56. +1 −0 vendor/simple-templater
View
@@ -16,3 +16,12 @@
[submodule "vendor/erubis"]
path = vendor/erubis
url = git://github.com/genki/erubis.git
+[submodule "vendor/cli"]
+ path = vendor/cli
+ url = git://github.com/botanicus/cli.git
+[submodule "vendor/rubyexts"]
+ path = vendor/rubyexts
+ url = git://github.com/botanicus/rubyexts.git
+[submodule "vendor/simple-templater"]
+ path = vendor/simple-templater
+ url = git://github.com/botanicus/simple-templater.git
View
@@ -11,11 +11,12 @@
= Version 0.0.4
-= Version 0.0.5
+= Version 0.1
* [FEATURE] environments support
* [FEATURE] installation without RubyGems
* [FEATURE] Rip support
* [FEATURE] HTTP caching
* [FEATURE] Hooks for Rendering
* [SPECS] Integration with RunCodeRun.com
* [SPECS] All specs passing
+ * SimpleTemplater, RubyExts & CLI
View
@@ -1,7 +1,7 @@
h1. Installation
-* From RubyForge: @sudo gem install rango@
-* From GitHub: @sudo gem install botanicus-rango -s http://gems.github.com@
+* From RubyForge: @sudo gem install rango --development@
+* From Gemcutter: @sudo gem install rango -s http://gemcutter.org --development@
h1. Documentation
View
@@ -2,6 +2,7 @@
# Syntax:
# repository [tag or commit to install]
-git://github.com/datamapper/extlib.git
git://github.com/botanicus/path.git
+git://github.com/botanicus/rubyexts.git
+git://github.com/botanicus/simple-templater.git
git://github.com/rack/rack.git 1.0.1
View
@@ -2,7 +2,6 @@
# dependencies
require "rack"
-require "extlib"
# imports
Rango.import("project")
View
@@ -1,126 +0,0 @@
-# encoding: utf-8
-
-require "rango" # logger
-
-require "yaml"
-require "ostruct"
-require "fileutils"
-
-require_relative "templater"
-
-# yes? etc
-require "rango/ext/cli"
-include Rango::CLI
-
-# TODO
-# metadata :file option for rendering just one file
-# gem installation (for plugin)
-# usage on rango -h
-# !!! @models.each |model| => create models/%model%.rb
-
-# - Find possible location and take first one
-# - If type of the location is full, then copy it's content directory to the desired name
-# - If type of the location is diff, then take another location, copy it and then copy files from the first one
-# - Run init.rb
-
-# === Hooks ===
-
-# == preprocessing.rb ==
-# @foo = "bar"
-# <%= %> a <%% %%>
-
-# models/%model%.rb
-# model.rb.rbt, posts.html.erb.rbt
-
-# content/foo
-# xxx/bar
-# => rango generate bigproject blog --models=post,tag --controllers=posts,tags
-
-module Rango
- module CLI
- class Generator
- def self.rango_root
- File.expand_path(File.join(File.dirname(__FILE__), "..", "..", ".."))
- end
-
- def self.stubs_dirs
- ["#{os.home}/.rango/stubs", "#{self.rango_root}/stubs"]
- end
-
- def self.list
- output = Hash.new
- self.stubs_dirs.each do |directory|
- files = map { |directory| Dir["#{directory}/*"] }.flatten
- directories = files.select { |file| Dir.exist?(file) }
- output[directory] = directories
- end
- return output
- end
-
- def initialize(type, name, *args)
- @type, @name, @args = type, name, args
- if File.exist?(name)
- abort "#{name} already exist, aborting."
- end
- end
-
- def stubs_dirs
- dirs = self.class.stubs_dirs.dup
- dirs.map! { |dir| "#{dir}/#{@type}" }
- dirs.find { |dir| Dir.exist?(dir) }
- end
-
- def content_dir
- "#{@stubs_dir}/content"
- end
-
- def create
- self.stubs_dirs.each do |stubs_dir|
- @stubs_dir = stubs_dir
- self.proceed
- end
- end
-
- def proceed
- Rango.logger.info("Creating #{@type} #{@name} from stubs in #{@stubs_dir}")
- FileUtils.mkdir_p(@name)
- Dir.chdir(@name) do
- ARGV.clear.push(*[self.content_dir, @args].flatten.compact)
- if File.exist?(hook = File.join(@stubs_dir, "preprocess.rb"))
- load hook
- else
- Rango::CLI::Templater.create(self.content_dir)
- end
- end
- self.run_init_hook
- end
-
- def run_init_hook
- Dir.chdir(@name) do
- if File.exist?(hook = File.join(@stubs_dir, "postprocess.rb"))
- load(hook) && Rango.logger.inspect("Running postprocess.rb hook")
- end
- end
- end
-
- def validations
- ["diff", "full"].include?(self.config.type)
- end
-
- # Metadata options
- # :type: full|diff
- # :file: flat.ru
- def metadata
- metadata_file = File.join(@stubs_dir, "metadata.yml")
- YAML::load_file(metadata_file)
- rescue Errno::ENOENT
- Rango.logger.fatal("Rango expected '#{metadata_file}'")
- end
-
- def config
- defaults = {processing: true, type: "full"}
- OpenStruct.new(defaults.merge(self.metadata))
- end
- end
- end
-end
View
@@ -1,89 +0,0 @@
-# encoding: utf-8
-
-# I know, I know, we have Rubigen, Templater and others,
-# but Rango needs something really simple, so user can
-# start work immediately and can't study bloated docs
-
-require_gem_or_exit "erubis"
-
-require "fileutils"
-require "tempfile"
-require "find"
-
-# @since 0.0.3
-# @example
-# Rango::CLI::Templater.create("my_generator_dir", user: "botanicus", constant: -> { |argv| argv.first.camel_case })
-module Rango
- module CLI
- class Templater
- def self.create(*args)
- templater = self.new(*args)
- Rango.logger.debug("Context: #{templater.context.inspect}")
- templater.create
- end
-
- attr_accessor :context
- def initialize(content_dir, context = Hash.new)
- @content_dir, @context = content_dir, context.reverse_merge(name: File.basename(Dir.pwd))
- end
-
- def create
- Find.find(@content_dir) do |template|
- file = self.expand_path(template)
- next if template == @content_dir
- if File.file?(template)
- proceed_file(template, file)
- else
- unless Dir.exist?(file)
- Rango.logger.debug("[MKDIR] #{file}")
- FileUtils.mkdir_p(file)
- end
- end
- end
- end
-
- protected
- # replace %variable% in file path
- # %name%_controller.rb => application_controller.rb
- def expand_path(file)
- file = self.location(file).sub(/\.rbt$/, "")
- @context.each do |key, value|
- file.gsub!(/%#{Regexp::quote(key)}%/, value.to_s)
- end
- return file
- end
-
- def location(file)
- file.sub(%r[^#{Regexp::quote(@content_dir)}/?], "")
- end
-
- def proceed_file(template, file)
- FileUtils.mkdir_p(File.dirname(file))
- if template.end_with?(".rbt")
- if File.exist?(file)
- Rango.logger.debug("[RETEMPLATE] #{file} (from #{template})")
- else
- Rango.logger.debug("[TEMPLATE] #{file} (from #{template})")
- end
- File.open(file, "w") do |file|
- eruby = Erubis::Eruby.new(File.read(template))
- begin
- output = eruby.evaluate(@context)
- rescue Exception => exception
- Rango.logger.error("Exception occured in template #{template}: #{exception.message}")
- end
- file.print(output)
- end
- else # just copy
- if File.exist?(file)
- Rango.logger.debug("[RECOPY] #{file} (from #{template})")
- FileUtils.cp_f(template, file)
- else
- Rango.logger.debug("[COPY] #{file} (from #{template})")
- FileUtils.cp(template, file)
- end
- end
- end
- end
- end
-end
View
@@ -1,90 +0,0 @@
-# encoding: utf-8
-
-module Kernel
- # Require all files matching given glob relative to $:
- #
- # @author Botanicus
- # @since 0.0.3
- # @param [String] library Glob of files to require
- # @param [Hash] params Optional parameters.
- # @option params [String, Array<String>] :exclude File or list of files or globs relative to base directory
- # @raise [LoadError] If base directory doesn't exist
- # @raise [ArgumentError] If first argument isn't a glob
- # @return [Array<String>] List of successfully loaded files
- # @example
- # acquire "lib/*"
- # acquire "lib/**/*", exclude: "**/*_spec.rb"
- # acquire "lib/**/*", exclude: ["**/*_spec.rb", "lib/init.rb"]
- def acquire(glob, params = Hash.new)
- base, glob = get_base_and_glob(glob)
- $:.compact.find do |path|
- fullpath = File.expand_path(File.join(path, base))
- if File.directory?(fullpath)
- return __acquire__(fullpath, glob, params.merge(soft: true))
- end
- end
- raise LoadError, "Directory #{base} doesn't exist in $:"
- end
-
- def acquire!(glob, params = Hash.new)
- self.acquire(glob, params.merge(soft: false))
- end
-
- # Require all files matching given glob relative to current file
- #
- # @author Botanicus
- # @since 0.0.3
- # @param [String] library Glob of files to require
- # @param [Hash] params Optional parameters.
- # @option params [String, Array<String>] :exclude File or list of files or globs relative to base directory
- # @raise [LoadError] If base directory doesn't exist
- # @raise [ArgumentError] If first argument isn't a glob
- # @return [Array<String>] List of successfully loaded files
- # @example
- # acquire "lib/*"
- # acquire "lib/**/*", exclude: "**/*_spec.rb"
- # acquire "lib/**/*", exclude: ["**/*_spec.rb", "lib/init.rb"]
- def acquire_relative(glob, params = Hash.new)
- base, glob = get_base_and_glob(glob)
- path = File.dirname(caller[0].split(":").first)
- full = File.expand_path(File.join(path, base))
- raise LoadError, "Directory #{base} doesn't exist in #{path}" unless File.directory?(full)
- return __acquire__(full, glob, params.merge(soft: true))
- end
-
- def acquire_relative!(glob, params = Hash.new)
- self.acquire_relative(glob, params.merge(soft: false))
- end
-
- def load_relative(file)
- path = File.dirname(caller[0].split(":").first)
- load File.expand_path(File.join(path, file))
- end
-
- private
- def __acquire__(path, glob, params)
- glob.replace("#{glob}.rb") if glob.eql?("*") || glob.end_with?("/*")
- files = Dir[File.join(path, glob)]
- excludes = [params[:exclude]].flatten.compact
- excludes.map! do |glob|
- fullpath = File.join(path, glob)
- File.file?(fullpath) ? fullpath : Dir[fullpath]
- end
- excludes = excludes.flatten.compact
- files.select do |path|
- if File.file?(path) && !excludes.include?(path)
- soft_not_loaded = params[:soft] && ! $LOADED_FEATURES.include?(path)
- load(path) if soft_not_loaded || ! params[:soft]
- $LOADED_FEATURES.push(path) if soft_not_loaded
- end
- end
- end
-
- def get_base_and_glob(glob)
- base, glob = glob.match(/^([^*]+)(.*)$/)[1..2]
- raise ArgumentError, "You have to provide glob" if glob.empty?
- return [base, glob]
- end
-end
-
-acquire_relative "ext/*", exclude: "thor.rb"
View
@@ -1,20 +0,0 @@
-# encoding: utf-8
-
-class Array
- # Returns the _only_ element in the array or raise
- # +IndexError+ if array hasn't exactly one element.
- #
- # @author Botanicus
- # @from Extensions
- # @since 0.0.3
- # @raise [IndexError] If array hasn't exactly one element
- # @return [Object] First (and only) item of the array
- # @example
- # [5].only # => 5
- # [1, 2, 3].only # => IndexError
- # [].only # => IndexError
- def only
- raise IndexError, "Array#only called on non-single-element array" unless self.size == 1
- self.first
- end
-end
Oops, something went wrong.

0 comments on commit 3dd6088

Please sign in to comment.