Permalink
Browse files

public release

  • Loading branch information...
0 parents commit 4e9ee55f937abc7cbb6b59013e76175324217a59 @eudoxa eudoxa committed Dec 21, 2011
Showing with 4,177 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +4 −0 .rspec
  3. +3 −0 Gemfile
  4. +21 −0 License.txt
  5. +240 −0 README.rdoc
  6. +38 −0 Rakefile
  7. +1 −0 VERSION
  8. +41 −0 chanko.gemspec
  9. +5 −0 lib/chanko.rb
  10. +3 −0 lib/chanko/aborted.rb
  11. +94 −0 lib/chanko/active_if.rb
  12. +5 −0 lib/chanko/active_record.rb
  13. +80 −0 lib/chanko/active_record/expand.rb
  14. +15 −0 lib/chanko/aliases.rb
  15. +71 −0 lib/chanko/callback.rb
  16. +9 −0 lib/chanko/callbacks.rb
  17. +29 −0 lib/chanko/config.rb
  18. +23 −0 lib/chanko/controller.rb
  19. +33 −0 lib/chanko/directories.rb
  20. +6 −0 lib/chanko/exception.rb
  21. +27 −0 lib/chanko/exception_notifier.rb
  22. +107 −0 lib/chanko/expand.rb
  23. +76 −0 lib/chanko/helper.rb
  24. +175 −0 lib/chanko/invoker.rb
  25. +167 −0 lib/chanko/loader.rb
  26. +36 −0 lib/chanko/log.rb
  27. +74 −0 lib/chanko/method_proxy.rb
  28. +2 −0 lib/chanko/notification.rb
  29. +58 −0 lib/chanko/railtie.rb
  30. +8 −0 lib/chanko/test.rb
  31. +9 −0 lib/chanko/test/invoker.rb
  32. +27 −0 lib/chanko/test/macro.rb
  33. +92 −0 lib/chanko/test/mock.rb
  34. +12 −0 lib/chanko/tools.rb
  35. +318 −0 lib/chanko/unit.rb
  36. +12 −0 lib/chanko/unit/default.rb
  37. +85 −0 lib/chanko/updating_load.rb
  38. +25 −0 lib/generators/chanko/USAGE
  39. +74 −0 lib/generators/chanko/chanko_generator.rb
  40. +41 −0 lib/generators/chanko/install/install_generator.rb
  41. +12 −0 lib/generators/chanko/install/templates/active_if/active_if.rb
  42. +3 −0 lib/generators/chanko/install/templates/chanko_initializer.rb
  43. +1 −0 lib/generators/chanko/templates/chanko.coffee
  44. +1 −0 lib/generators/chanko/templates/chanko.haml
  45. +1 −0 lib/generators/chanko/templates/chanko.js
  46. +43 −0 lib/generators/chanko/templates/chanko.rb
  47. +6 −0 lib/generators/chanko/templates/chanko.scss
  48. BIN lib/generators/chanko/templates/chanko_blank.png
  49. +15 −0 lib/generators/chanko/templates/chanko_controller_spec.rb
  50. +8 −0 lib/generators/chanko/templates/chanko_helper.rb
  51. +11 −0 lib/generators/chanko/templates/chanko_helper_spec.rb
  52. +25 −0 lib/generators/chanko/templates/chanko_model.rb
  53. +10 −0 lib/generators/chanko/templates/chanko_model_spec.rb
  54. +9 −0 lib/hash_extension.rb
  55. +1 −0 lib/tasks/chanko.rake
  56. +35 −0 spec/app.rb
  57. +16 −0 spec/app/controller.rb
  58. +3 −0 spec/app/route.rb
  59. +7 −0 spec/fixtures/active_if/main.rb
  60. +7 −0 spec/fixtures/active_if/test.rb
  61. +2 −0 spec/fixtures/lib/chanko_dummy.rb
  62. +2 −0 spec/fixtures/load_path_file
  63. +4 −0 spec/fixtures/test_extensions/load_ext/helpers/load_ext_helper.rb
  64. +4 −0 spec/fixtures/test_extensions/load_ext/load_ext.rb
  65. +15 −0 spec/fixtures/test_extensions/sample2_ext/sample2_ext.rb
  66. +1 −0 spec/fixtures/test_extensions/sample2_ext/views/_same_partial.html.haml
  67. +7 −0 spec/fixtures/test_extensions/sample_ext/helpers/sample_ext_helper.rb
  68. 0 spec/fixtures/test_extensions/sample_ext/javascripts/sample1.js
  69. 0 spec/fixtures/test_extensions/sample_ext/javascripts/sample2.js
  70. +139 −0 spec/fixtures/test_extensions/sample_ext/sample_ext.rb
  71. +8 −0 spec/fixtures/test_extensions/sample_ext/specs/models/example_spec.rb
  72. +10 −0 spec/fixtures/test_extensions/sample_ext/stylesheets/sample_ext.scss
  73. +1 −0 spec/fixtures/test_extensions/sample_ext/views/_same_partial.html.haml
  74. +1 −0 ...t_extensions/sample_ext/views/example/extension/view_files_must_not_be_used_without_ext.html.haml
  75. +1 −0 spec/fixtures/test_extensions/sample_ext/views/extension/_partial.rhtml
  76. +1 −0 spec/fixtures/test_extensions/sample_ext/views/extension/_partial_async.html.haml
  77. +2 −0 spec/fixtures/test_extensions/sample_ext/views/extension/_partial_haml.html.haml
  78. +1 −0 spec/fixtures/test_extensions/sample_ext/views/extension/render_partial_haml.html.haml
  79. +13 −0 spec/fixtures/test_extensions/sample_ext/views/extension/rendering.rhtml
  80. +11 −0 spec/fixtures/test_extensions/sample_ext/views/extension/rendering_haml.html.haml
  81. +1 −0 ...ures/test_extensions/sample_ext/views/extension/view_files_must_not_be_used_without_ext.html.haml
  82. BIN spec/fixtures/test_extensions/testing_ext/images/logo.png
  83. +11 −0 spec/fixtures/test_extensions/testing_ext/specs/helpers/testing_ext_helper_spec.rb
  84. +10 −0 spec/fixtures/test_extensions/testing_ext/specs/models/testing_ext_spec.rb
  85. +12 −0 spec/fixtures/test_extensions/testing_ext/stylesheets/testing.scss
  86. +45 −0 spec/fixtures/test_extensions/testing_ext/testing_ext.rb
  87. +1 −0 spec/fixtures/test_extensions/testing_ext/views/_partial_hello.html.haml
  88. +2 −0 spec/fixtures/test_extensions/testing_ext/views/testing_hello.html.haml
  89. +18 −0 spec/integration/chanko_spec.rb
  90. +55 −0 spec/lib/active_if_spec.rb
  91. +124 −0 spec/lib/callback_spec.rb
  92. +34 −0 spec/lib/directories_spec.rb
  93. +72 −0 spec/lib/exception_spec.rb
  94. +155 −0 spec/lib/expand_spec.rb
  95. +58 −0 spec/lib/helper_spec.rb
  96. +208 −0 spec/lib/invoker_spec.rb
  97. +88 −0 spec/lib/loader_spec.rb
  98. +109 −0 spec/lib/method_proxy_spec.rb
  99. +39 −0 spec/lib/run_default_spec.rb
  100. +115 −0 spec/lib/shared_method_spec.rb
  101. +81 −0 spec/lib/test/test_tool_spec.rb
  102. +209 −0 spec/lib/unit_spec.rb
  103. +57 −0 spec/lib/updating_load_spec.rb
  104. 0 spec/log/development.log
  105. +56 −0 spec/spec_helper.rb
  106. +18 −0 spec/support/chanko.rb
  107. +13 −0 spec/support/database_cleaner.rb
@@ -0,0 +1,3 @@
+log/*
+tmp/*
+Gemfile.lock
4 .rspec
@@ -0,0 +1,4 @@
+--color
+--format=nested
+--backtrace
+--profile
@@ -0,0 +1,3 @@
+source "http://rubygems.org"
+gemspec
+
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2011 MORITA shingo
+
+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,240 @@
+= Chanko
+== What is Chanko
+"Chanko" is a library that attaches functional unit programming. Primarily, this is for prototyping and currently released as beta.
+
+== Supported versions
+Ruby 1.8.7, 1.9.2
+Rails 3.0.10 ~
+
+== Install
+Add your Gemfile.
+ gem 'chanko', :git => 'git@github.com:cookpad/Chanko.git'
+Run install.
+ rails generate chanko:install
+Add this code to ApplicationHelper.
+ include Chanko::Invoker
+
+== Files
+
+Generate chanko.
+ rails generate chanko sample
+ create app/chankos/sample/sample.rb
+ create app/chankos/sample/views/_show.html.haml
+ create app/chankos/sample/stylesheets/tutorial.scss
+ create app/chankos/sample/images/logo.png
+ create app/chankos/sample/specs/models/sample_spec.rb
+ create app/chankos/sample/specs/controllers/sample_controller_spec.rb
+ create app/chankos/sample/specs/helpers/sample_helper_spec.rb
+
+=== app/chankos/sample/sample.rb
+Main file. You write your functionality in this file.
+
+=== app/chankos/sample/views
+The view files for your chanko. Each chanko refers to its own views directory.
+
+=== app/chankos/sample/stylesheets/tutorial.scss
+Write styles for your chanko in this file. These files will be merged during startup or first access.
+
+=== app/chankos/sample/images/logo.png
+The image files for this chanko.
+if you manually created this directory, you should create a symbolic link from app/chankos/sample/images to (public or assets)/images/chankos/#{ext_name} with attention to use the relative path.
+If you used generator, the symbolic link is automaticlly generated.
+
+=== app/chankos/sample/specs/
+Write your tests code for the chanko here.
+
+== Syntax
+ module Sample
+ include Chanko::Unit
+
+ # active_if's block is used to decide if the chanko is active or not.
+ # context is the object which invoked the callback.
+ active_if :always_true do |context, options|
+ true
+ end
+
+ shared(:hello) do |name|
+ "hello #{name}"
+ end
+
+ scope(:controller) do
+ callback(:controller_show) do
+ # controller code here
+ end
+ end
+
+ scope(:view) do
+ callback(:view_show) do
+ render :partial => "/show"
+ end
+ end
+
+ models do
+ expand("ExpandedModel") do
+ #expanded_model.ext(:sample).has_many_associations
+ has_many :has_many_associations
+ has_one :has_one_association
+ named_scope :exists, :conditions => {:deleted_at => nil}
+
+ # expanded_model_instance.ext.new_method
+ def new_method
+ end
+
+ #expanded_mode.ext.new_method
+ class_methods do
+ def new_class_method
+ end
+ end
+ end
+ end
+
+ helpers do
+ # ext.helper_method
+ def helper_method
+ end
+ end
+ end
+
+== active_if
+"active_if()" decides if the chanko is enabled or not. active_if receives an arg of the invoked context, such as controller.
+The chanko is enabled when the block returns true.
+ # activeif's block is used to decide if the chanko is active or not.
+ # context is the object which invoked the callback.
+ which invoking callback object.
+ active_if do |context, options|
+ true
+ end
+
+Also, "active_if()" accept pre defined symbols. "active_if()" get AND result for all symbols and block.
+ # This definition means "user is staff and environment is not production"
+ active_if :staff, :not_production do |context, options|
+ # some additional conditions
+ end
+
+You can define symbol in lib/active_if_files/main.rb.
+ Chanko::ActiveIf.define(:not_production?) do |context, options|
+ !Rails.env.production?
+ end
+
+ Chanko::ActiveIf.define(:staff) do |context, options|
+ user = options[:user] || context.instance_variable_get('@login_user')
+ next false unless user
+ next false unless user.staff?
+ next true
+ end
+
+When you want to set OR defines, use "any()".
+ # This means "current user is staff or paid user. And environment is not production"
+ active_if any(:staff, :paid), :not_production
+
+== shared method
+A "shared()" is syntax for shared method definitions. you can use defined method through callbacks of either :controller or :view or etc. a block of shared method behave as instance method.
+ shared(:hello) do |name|
+ "hello #{name}"
+ end
+
+ scope(:view) do
+ callback(:hello) do
+ hello("alice")
+ end
+ end
+
+== callback
+A "callback()" is an expanding block for the current code. This block's context behaves as an invoked context, so you can access original context instance variables. if you need to access local variables, callback provides a :locals option that is similar to :locals of render.
+A callback is scoped, and its scope is a restriction for the callback. The callback is only called from scoped context.
+ #scope can receive specified context such as "scope('UsersController')".
+ scope(:controller) do
+ callback(:controller_show) do
+ # controller code here
+ end
+ end
+
+"invoke()" runs a callback block if the active_if block returns true.
+ class UsersController
+ def show
+ invoke(:sample, :controller_show)
+ end
+ end
+
+"invoke()" can receive a block as a default process. The block is executed if active_if block return false or the callback raises an error.
+ callback(:controller_show) do
+ default_behaviour
+ end
+
+"run_default()" method runs default block and return a result as string.
+it is used by callback block
+ callback(:hello) do
+ result = run_default
+ "#{result} + hello"
+ end
+
+"invoke()" can receive multiple callbacks. "invoke" tries to run the callbacks in turn. Only the first enabled callback is executed.
+ #invoke doesn't run next_ext callback if first_ext is enabled.
+ invoke([:first_ext, :show], [:next_ext, :show])
+
+"invoke"() doesn't run if the specified chanko in the :if is disabled
+ invoke(:sample, :show, :if => :depend_on_ext)
+
+== expand
+"expand()" expands existing model methods and adds chanko helper methods. The expanded method is only used by the expanding chanko.
+All expanded method must be used via ext proxy as below.
+ user_instance.ext.expanded_method
+
+You can write expanding methods for current models. The "models()" block provides association and named_scope and class method syntax.
+ models do
+ expand("ExpandedModel") do
+ #expanded_model.ext.has_many_associations
+ has_many :has_many_associations
+ has_one :has_one_association
+ has_many :through_associations, :through => label(:has_many_associations)
+ named_scope :exists, :conditions => {:deleted_at => nil}
+ # expanded_model_instance.ext.new_method
+ def new_method
+ end
+
+ #expanded_mode.ext.new_method
+ class_methods do
+ def cmethod
+ end
+ end
+ end
+ end
+
+when used as symbol as :include option for ActiveRecord, you must wrap label with "ext.label()" syntax.
+ User.find(:first, :include => [ext.label(:recipes)])
+
+== Helpers
+You can write chanko helpers.
+ helpers do
+ def helper_method
+ end
+ end
+
+And can use helpers in views and controllers via ext proxy.
+ callback(:sample) { ext.hello }
+ helpers { def hello; 'hello'; end }
+
+== Tips
+return from inside of invoke block.
+Use following code.
+ invoke(:hoge, :aaa) do
+ redirect_to xxx
+ end
+ return if performed?
+
+
+always activate or inactive chanko.
+Use :always_true/:always_false on active_if.
+ active_if :always_true # or :always_false
+
+
+invoke with before_filter.
+Use block and invoke.
+ before_filter :only => :index do |controller|
+ controller.invoke(:contest_noseru_ext, :store_contest_id)
+ end
+
+check status of chanko.
+you can check the status of an chanko. In almost all situations, context is controller.(deprecated ?)
+ ext(:sample).active? #=> return boolean
+
@@ -0,0 +1,38 @@
+#!/usr/bin/env rake
+
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require 'bundler'
+Bundler.setup
+Bundler::GemHelper.install_tasks
+
+Dir['lib/tasks/*.rake'].each { |rake| load rake }
+
+require 'rspec/core'
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new(:spec)
+
+task :default => :spec
+
+desc "Run all specs with rcov"
+RSpec::Core::RakeTask.new(:rcov) do |t|
+ t.rcov = true
+ t.rcov_opts = %w{--rails --exclude osx\/objc,gems\/,spec\/,features\/}
+end
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gemspec|
+ gemspec.name = "chanko"
+ gemspec.summary = "Extend rails application"
+ gemspec.email = "morita.shingo@gmail.com"
+ gemspec.homepage = ""
+ gemspec.description = "Extend rails application "
+ gemspec.authors = ["MORITA shingo"]
+ end
+rescue LoadError
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
+end
+
@@ -0,0 +1 @@
+1.0.0
@@ -0,0 +1,41 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{chanko}
+ s.version = "1.0.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["MORITA shingo"]
+ s.date = %q{2011-12-16}
+ s.description = %q{Extend rails application}
+ s.email = %q{morita.shingo@gmail.com}
+ s.homepage = %q{}
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.6.2}
+ s.summary = %q{extension framework}
+
+ s.add_dependency 'rails', ['>= 3.0.0']
+ s.add_development_dependency 'sqlite3', ['>= 0']
+ s.add_development_dependency 'rspec', ['>= 0']
+ s.add_development_dependency 'rspec-rails', ['>= 0']
+ if RUBY_VERSION =~ /\A1.9.*/
+ s.add_development_dependency 'ruby-debug19', ['>= 0']
+ else
+ s.add_development_dependency 'ruby-debug', ['>= 0']
+ end
+
+ s.add_development_dependency 'rcov'
+ s.add_development_dependency 'capybara'
+ s.add_development_dependency 'factory_girl', ['>2.0.0']
+ s.add_development_dependency 'database_cleaner', ['>= 0']
+ s.add_development_dependency 'simplecov', ['>= 0.4.0']
+
+ if s.respond_to? :specification_version then
+ s.specification_version = 3
+ else
+ end
+end
+
@@ -0,0 +1,5 @@
+require 'hash_extension'
+
+module Chanko
+ require 'chanko/railtie'
+end
@@ -0,0 +1,3 @@
+module Chanko
+ class Aborted < StandardError; end
+end
Oops, something went wrong.

0 comments on commit 4e9ee55

Please sign in to comment.