dionysus 1.0.2 → 2.0.0

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/Gemfile CHANGED
@@ -1,13 +1,20 @@
1
- source :gemcutter
1
+ source "http://rubygems.org"
2
2
 
3
- gem 'bundler', '~> 1.0'
4
- gem 'activesupport', '~> 3.0.0'
3
+ group :development, :test do
4
+ gem "rake", "~> 0.9.2"
5
+ gem "rspec", "~> 2.10.0"
6
+ end
5
7
 
6
8
  group :development do
7
- gem 'rspec', '~> 2.0.0'
8
- gem 'jeweler', '~> 1.5.0'
9
- gem 'rake', '~> 0.8.0'
10
- gem 'rcov', '~> 0.9.0'
11
- gem 'sdoc', '~> 0.2.0'
12
- gem 'rdiscount', '~> 1.6.0'
9
+ gem "yard", "~> 0.8.2"
10
+ gem "redcarpet", "~> 2.1.1"
11
+ end
12
+
13
+ group :test do
14
+ gem "shoulda-matchers", "~> 1.2.0"
15
+ gem "mocha", "~> 0.11.4"
16
+ gem "simplecov", "~> 0.6.4", :require => false
13
17
  end
18
+
19
+ # Specify core dependencies in core.gemspec
20
+ gemspec
data/README.md CHANGED
@@ -1,58 +1,55 @@
1
- Dionysus
2
- ========
1
+ # Dionysus
3
2
 
4
- A helpful set of utility classes, generators, and command-line tools.
3
+ <<< description.md
5
4
 
6
5
  > Dionysus or Dionysos (pronounced /ˌdaɪ.ɵˈnaɪsəs/; Greek: Διόνυσος or
7
6
  > Διώνυσος) is the ancient Greek god of wine, the inspirer of ritual madness
8
7
  > and ecstasy, and a major figure of Greek mythology.
9
8
  > [Wikipedia: Dionysus (2010/03/15)](http://en.wikipedia.org/wiki/Dionysus)
10
9
 
11
- Requirements
12
- ------------
10
+ **GitHub** http://github.com/tekwiz/dionysus
13
11
 
14
- * Rails 3
12
+ **Issues** http://github.com/tekwiz/dionysus/issues
15
13
 
16
- Installation
17
- ------------
14
+ **Travis-CI** http://travis-ci.org/tekwiz/dionysus
15
+ [![Build Status](https://secure.travis-ci.org/tekwiz/dionysus.png?branch=master)](http://travis-ci.org/tekwiz/dionysus)
18
16
 
19
- gem install dionysus
17
+ **Docs** http://rubydoc.info/gems/dionysus
20
18
 
21
- Usage
22
- -----
19
+ **RubyGems** http://rubygems.org/gems/dionysus
23
20
 
24
- First, add "dionysus" to your Gemfile or whatever other dependency system you're using. Then, you'll need to require each file/module as you need them. Dionysus is setup *à la carte* since parts are bound to conflict with something you're using at some point.
21
+ ## Requirements
25
22
 
26
- Resources
27
- ---------
23
+ * ActiveSupport 3.1 or 3.2
28
24
 
29
- * [Github Project](http://github.com/tekwiz/dionysus)
30
- * [SDocs](http://tekwiz.github.com/dionysus)
31
- * [Wiki on Github](http://wiki.github.com/tekwiz/dionysus/)
32
- * [Issues Tracker on Github](http://github.com/tekwiz/dionysus/issues)
25
+ ##Installation
33
26
 
34
- Features & Issues
35
- -----------------
27
+ $ gem install dionysus
36
28
 
37
- This is a brand new project, so if you find bugs or use cases that would helpful to satisfy, post an [Issue](http://github.com/tekwiz/dionysus/issues) on Github.
29
+ or add to your Gemfile:
38
30
 
39
- This project is intended to be a **very** eclectic mix of helpful tools, so please feel free to send pull requests. That said, make **absolutely sure** your modifications are well tested. The hodge-podge nature of this project may make it prone to issues, so no code will be pulled-in that is not __fully_tested__.
31
+ gem "dionysus"
40
32
 
41
- Note on Patches/Pull Requests
42
- -----------------------------
33
+ and
34
+
35
+ $ bundle install
36
+
37
+ ## Usage
38
+
39
+ Add dionysus to your Gemfile:
43
40
 
44
- * Fork the project.
45
- * Make your feature addition or bug fix.
46
- * Add tests for it. This is important so I don't break it in a
47
- future version unintentionally.
48
- * Commit, do not mess with rakefile, version, or history.
49
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
50
- * Send me a pull request. Bonus points for topic branches.
41
+ gem "dionysus"
51
42
 
52
- Copyright
53
- ---------
43
+ Then, you'll need to require each file/module as you need them. Dionysus is setup *à la carte*
44
+ since parts are bound to conflict with something you're using at some point.
45
+
46
+ ## Contributing
47
+
48
+ This project is intended to be a **very** eclectic mix of helpful tools, so please feel free to send pull requests. That said, make **absolutely sure** your modifications are well tested. The hodge-podge nature of this project may make it prone to issues, so no code will be pulled-in that is not __fully_tested__.
49
+
50
+ -----------------------------
54
51
 
55
- Copyright 2010 Travis D. Warlick, Jr.
52
+ Copyright 2012 Travis D. Warlick, Jr.
56
53
 
57
54
  Licensed under the Apache License, Version 2.0 (the "License");
58
55
  you may not use this file except in compliance with the License.
data/Rakefile CHANGED
@@ -1,90 +1,27 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'rake'
11
-
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- gem.name = "dionysus"
15
- gem.summary = %Q{A helpful set of utility classes, generators, and command-line tools.}
16
- gem.email = "warlickt@operissystems.com"
17
- gem.homepage = "http://github.com/tekwiz/dionysus"
18
- gem.authors = ["Travis D. Warlick, Jr."]
19
- gem.add_bundler_dependencies(:default, :development)
20
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
21
- end
22
- Jeweler::RubygemsDotOrgTasks.new
1
+ require "bundler/gem_tasks"
2
+ require "pathname"
23
3
 
24
- require 'rspec/core'
25
- require 'rspec/core/rake_task'
26
- RSpec::Core::RakeTask.new(:spec) do |spec|
27
- spec.pattern = FileList['spec/**/*_spec.rb']
28
- end
29
- RSpec::Core::RakeTask.new(:rcov) do |spec|
30
- spec.pattern = 'spec/**/*_spec.rb'
31
- spec.rcov = true
32
- spec.rcov_opts = '--exclude \/Library\/ --exclude /\.gem\/ --exclude /\.rvm\/ --exclude /\.bundle\/'
33
- end
34
- task :default => :spec
4
+ $rake_root = Pathname(__FILE__).expand_path.dirname
35
5
 
36
- task :clobber_rcov do
37
- FileUtils.rm_r 'coverage', :secure => true, :force => true, :verbose => true
6
+ Dir.glob($rake_root.join("**/*.rake").to_s).each do |fn|
7
+ load fn
38
8
  end
39
9
 
40
- require 'rake/rdoctask'
41
- require 'sdoc'
42
- require 'dionysus/rdoc/markdown'
43
- require 'dionysus/rdoc/no_markup'
44
- RDoc::NoMarkup.files.include('LICENSE', 'VERSION')
10
+ task :default => [:spec]
45
11
 
46
- Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
- rdoc.options << '--fmt' << 'shtml'
49
- rdoc.template = 'direct'
50
- rdoc.title = "Dionysus #{version}"
51
- rdoc.main = "README.md"
52
- rdoc.rdoc_files.include('README.md', 'LICENSE', 'VERSION')
53
- rdoc.rdoc_files.include('lib/**/*.rb')
54
- rdoc.rdoc_dir = 'docs'
55
- end
56
-
57
- task :clobber => [:clobber_rcov, :clobber_rdoc]
58
-
59
- # Github pages tasks taken from the sdoc-helpers gem.
60
- # http://github.com/defunkt/sdoc-helpers
61
- # Author: Chris Wanstrath chris@ozmm.org
62
- namespace :pages do
63
- task :publish => [ :check_dirty, :rerdoc ] do
64
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
65
- `git checkout gh-pages`
66
- `ls -1 | grep -v docs | xargs rm -rf; mv docs/* .; rm -rf docs`
67
- `git add .; git commit -m "update docs for version #{version}"; git push origin gh-pages`
68
- `git checkout master`
69
- puts :done
12
+ namespace :clobber do
13
+ desc "Clobber Gem Package (pkg/)"
14
+ task :pkg do
15
+ $rake_root.join("pkg").rmtree rescue nil
70
16
  end
71
17
 
72
- desc "Initialize GitHub Pages with documentation"
73
- task :init => [ :check_dirty, :rerdoc ] do
74
- `git symbolic-ref HEAD refs/heads/gh-pages`
75
- `rm .git/index`
76
- `ls -1 | grep -v docs | xargs rm -rf; mv docs/* .; rm -rf docs`
77
- `git add .;git commit -m "create docs"; git push origin gh-pages`
78
- `git checkout master`
79
- puts :done
18
+ desc "Clobber Coverage (coverage/)"
19
+ task :coverage do
20
+ $rake_root.join("coverage").rmtree rescue nil
80
21
  end
81
22
 
82
- task :check_dirty do
83
- if !`git status`.include?('nothing to commit')
84
- abort "dirty index - not publishing!"
85
- end
86
- end
23
+ task :doc => ["doc:clobber"]
87
24
  end
88
25
 
89
- desc "Build and publish documentation using GitHub Pages."
90
- task :pages => "pages:publish"
26
+ desc "Clobber All"
27
+ task :clobber => ["doc:clobber", "clobber:pkg", "clobber:coverage"]
@@ -0,0 +1 @@
1
+ A helpful set of utility classes, generators, and command-line tools.
@@ -1,31 +1,12 @@
1
- # Copyright 2010 Travis D. Warlick, Jr.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require 'rubygems'
16
- require 'bundler'
17
- Bundler.setup
18
- %w(hash class module).each { |v| require 'active_support/core_ext/'+v }
1
+ require 'dionysus/version'
19
2
 
20
3
  ##
21
- # The top-level for Dionysus.
4
+ # <<< description.md
22
5
  #
23
6
  # Dionysus is setup *à la carte* since parts are bound to conflict with
24
7
  # something you're using at some point. This means that if you need something,
25
8
  # you *must* require it. See the documentation for instructions on what you
26
9
  # should require (this is always within the first few lines).
27
10
  module Dionysus
28
- # The current version
29
- VERSION = File.read(File.join(File.dirname(__FILE__), '..', 'VERSION')).strip
11
+
30
12
  end
31
-
@@ -0,0 +1,93 @@
1
+ require 'set'
2
+ require 'forwardable'
3
+ require 'active_support/concern'
4
+ require 'active_support/callbacks'
5
+ require 'active_support/core_ext/module/aliasing'
6
+ require 'active_support/core_ext/array/extract_options'
7
+
8
+ module Dionysus
9
+ module ConfigurationCallbacks
10
+ extend ActiveSupport::Concern
11
+
12
+ included do
13
+ # TODO validate self.config inherits from AS::Configurable::Configuration and is an anonymous class
14
+ self.config.class.send(:include, Configuration)
15
+ end
16
+
17
+ module Configuration
18
+ extend ActiveSupport::Concern
19
+ include ActiveSupport::Callbacks
20
+
21
+ included do
22
+ alias_method :_set, :[]= # preserve the original #[] method
23
+ protected :_set # make it protected
24
+ extend Forwardable
25
+ end
26
+
27
+ def respond_to?(name, include_private=false)
28
+ if name.to_s =~ /^_/
29
+ include_private ? method_defined?(name) : public_method_defined?(name)
30
+ else
31
+ true
32
+ end
33
+ end
34
+
35
+ def before(get_set, key, *args, &block)
36
+ name = _setup_for_callback(get_set, key)
37
+ self.class.set_callback(name, :before, *args, &block)
38
+ end
39
+
40
+ def after(get_set, key, *args, &block)
41
+ name = _setup_for_callback(get_set, key)
42
+ self.class.set_callback(name, :after, *args, &block)
43
+ end
44
+
45
+ def around(get_set, key, *args, &block)
46
+ name = _setup_for_callback(get_set, key)
47
+ self.class.set_callback(name, :around, *args, &block)
48
+ end
49
+
50
+ def forward(get_set, key, to_accessor, to_method)
51
+ case get_set.to_sym
52
+ when :get
53
+ self.class.def_delegator(to_accessor, to_method, key)
54
+ when :set
55
+ self.class.def_delegator(to_accessor, to_method, "#{key}=")
56
+ else
57
+ raise ArgumentError, "Invalid get_set parameter %p"%[get_set]
58
+ end
59
+ end
60
+
61
+ private
62
+
63
+ def _setup_for_callback(get_set, key)
64
+ key = key.to_sym
65
+ name = "#{get_set}_#{key}"
66
+
67
+ case get_set.to_sym
68
+ when :get
69
+ if method_defined?(key)
70
+ warn "Cannot setup callbacks for #{self}##{key}. Method already defined."
71
+ else
72
+ class_eval <<-EOS, __FILE__, __LINE__ + 1
73
+ def #{key}() run_callbacks(#{name.inspect}) { _get(#{key.inspect}) }; end
74
+ EOS
75
+ end
76
+ when :set
77
+ if method_defined?(:"#{key}=")
78
+ warn "Cannot setup callbacks for #{self}##{key}. Method already defined."
79
+ else
80
+ class_eval <<-EOS, __FILE__, __LINE__ + 1
81
+ def #{key}=(val) run_callbacks(#{name.inspect}) { _set(#{key.inspect}, val) }; end
82
+ EOS
83
+ end
84
+ else
85
+ raise ArgumentError, "Invalid get_set parameter %p"%[get_set]
86
+ end
87
+
88
+ self.class.define_callbacks(name)
89
+ return name
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,41 @@
1
+ require 'pathname'
2
+ require 'redcarpet'
3
+ require 'active_support/concern'
4
+ require 'active_support/core_ext/object/blank'
5
+
6
+ module Dionysus
7
+ module Redcarpet
8
+ module Includes
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ if method_defined?(:preprocess)
13
+ alias_method_chain :preprocess, :includes
14
+ else
15
+ alias_method :preprocess, :preprocess_with_includes
16
+ end
17
+ end
18
+
19
+ def preprocess_with_includes(full_document)
20
+ lines = full_document.split($/)
21
+ lines.each_with_index do |ln, i|
22
+ if m = ln.match(/\A\s*<<<\s*(\S+)\s*\Z/)
23
+ path = Pathname.new(m[1])
24
+ if path.file?
25
+ newlines = path.readlines
26
+ newlines.collect! {|ln| ln.chomp}
27
+ newlines.shift while(newlines.first.blank?)
28
+ newlines.pop while(newlines.last.blank?)
29
+ lines[i] = newlines
30
+ else
31
+ warn "[WARNING] Cannot find path %s to include"%[path.to_s]
32
+ end
33
+ end
34
+ end
35
+ lines.flatten.join("\n")
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ Redcarpet::Render::HTML.send(:include, Dionysus::Redcarpet::Includes)
@@ -0,0 +1,8 @@
1
+ class String
2
+ # @param (String) req Gem version requirement
3
+ # @return (Boolean) true if the given requirement is satisfied by the current
4
+ # String
5
+ def version_match?(req)
6
+ Gem::Requirement.new(req) =~ Gem::Version.new(self)
7
+ end
8
+ end
@@ -0,0 +1,67 @@
1
+ require 'bundler'
2
+
3
+ module Dionysus
4
+ module TravisCI
5
+ class GemfileGenerator
6
+ def initialize(gemfile)
7
+ @definition = Bundler::Dsl.new
8
+ @definition.instance_eval(Bundler.read_file(gemfile), "Gemfile", 1)
9
+ end
10
+
11
+ def generate(filename, options={})
12
+ File.open(filename, "w") do |f|
13
+ f.puts %(source "http://rubygems.org")
14
+
15
+ @definition.dependencies.each do |dep|
16
+ next if exclude_by_group?(dep, :default, options[:without])
17
+ f.puts dependency_line(dep)
18
+ end
19
+
20
+ case options[:add]
21
+ when String
22
+ f.puts options[:add]
23
+ when Array
24
+ options[:add].each {|ln| f.puts ln}
25
+ else
26
+ raise "Invalid :add option: %p"%[options[:add]] if options[:add]
27
+ end
28
+
29
+ f.puts %(gemspec :path => "../")
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def dependency_line(dep)
36
+ ln = [ %(gem "%s")%[dep.name] ]
37
+
38
+ ln << %("%s")%[dep.requirement]
39
+
40
+ groups = dep.groups.collect {|v| %(:#{v})}.join(", ")
41
+ ln << %(:group => [%s])%[groups]
42
+
43
+ if dep.autorequire == []
44
+ ln << %(:require => false)
45
+ elsif dep.autorequire
46
+ requires = dep.autorequire.collect {|s| %("#{s}")}.join(",")
47
+ ln << %(:require => [%s])%[requires]
48
+ end
49
+
50
+ if dep.source and dep.source.is_a?(Bundler::Source::Git)
51
+ ln << %(:git => "%s")%[dep.source.options["git"]]
52
+ ln << %(:branch => "%s")%[dep.source.options["branch"]]
53
+ elsif dep.source
54
+ raise "Unknown source type: %s"%[dep.source.class]
55
+ end
56
+
57
+ ln.join(", ")
58
+ end
59
+
60
+ def exclude_by_group?(dep, *without)
61
+ return false if without.nil? or without.empty?
62
+ without = without.compact.flatten
63
+ !(dep.groups & without).empty?
64
+ end
65
+ end
66
+ end
67
+ end