agnostic 0.1.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/README ADDED
@@ -0,0 +1,41 @@
1
+ Agnostic
2
+ ========
3
+
4
+ For FW hackers
5
+ --------------
6
+
7
+ * configure plugin by application developer
8
+
9
+ Agnostic.plugin :plugin_name do
10
+ # do configure
11
+ config_entry value
12
+ end
13
+
14
+ * load helpers
15
+
16
+ include Agnostic::Helper
17
+
18
+
19
+ For Plugin providors
20
+ ------------------
21
+
22
+ * access to configuration entry
23
+
24
+ Agnostic.plugin(:plugin_name).config_entry
25
+
26
+ * register a view helper
27
+
28
+ Agnostic.helpers do
29
+ def your_view_helper
30
+ end
31
+ end
32
+
33
+ For Application Developers
34
+ --------------------------
35
+
36
+ If your FW support agnostic, you need to do nothing.
37
+ Otherwise, you should initialize angostic by
38
+
39
+ require "agnostic/polyglot"
40
+
41
+ at your FW's configuration script (such as config/environemnt.rb).
data/Rakefile ADDED
@@ -0,0 +1,63 @@
1
+ require "rake/gempackagetask"
2
+
3
+ GEM_NAME = "agnostic"
4
+ GEM_VERSION = "0.1.0"
5
+ AUTHOR = "Genki Takiuchi"
6
+ EMAIL = "genki@s21g.com"
7
+ HOMEPAGE = "http://blog.s21g.com/genki"
8
+ SUMMARY = "An abstract framework for framework agnostic plugins"
9
+ PROJECT = "asakusarb"
10
+
11
+ spec = Gem::Specification.new do |s|
12
+ s.rubyforge_project = PROJECT
13
+ s.name = GEM_NAME
14
+ s.version = GEM_VERSION
15
+ s.platform = Gem::Platform::RUBY
16
+ s.has_rdoc = true
17
+ s.extra_rdoc_files = %w(README)
18
+ s.summary = SUMMARY
19
+ s.description = s.summary
20
+ s.author = AUTHOR
21
+ s.email = EMAIL
22
+ s.homepage = HOMEPAGE
23
+ s.require_path = "lib"
24
+ s.files = %w(Rakefile README) + Dir.glob("{lib,spec}/**/*")
25
+ end
26
+
27
+ Rake::GemPackageTask.new(spec) do |pkg|
28
+ pkg.need_tar = true
29
+ pkg.gem_spec = spec
30
+ end
31
+
32
+ desc "Create gemspec file"
33
+ task :gemspec do
34
+ File.open("#{GEM_NAME}.gemspec", "w") do |file|
35
+ file.puts spec.to_ruby
36
+ end
37
+ end
38
+
39
+ desc "Run spec"
40
+ task :spec do
41
+ sh "spec spec --color"
42
+ end
43
+
44
+ desc 'Package and upload the release to rubyforge.'
45
+ task :release => :package do |t|
46
+ require 'rubyforge'
47
+ v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
48
+ abort "Versions don't match #{v} vs #{GEM_VERSION}" unless v == GEM_VERSION
49
+ pkg = "pkg/#{GEM_NAME}-#{GEM_VERSION}"
50
+
51
+ require 'rubyforge'
52
+ rf = RubyForge.new.configure
53
+ puts "Logging in"
54
+ rf.login
55
+
56
+ c = rf.userconfig
57
+ c["preformatted"] = true
58
+ files = [ "#{pkg}.tgz", "#{pkg}.gem" ].compact
59
+ puts "Releasing #{GEM_NAME} v. #{GEM_VERSION}"
60
+ rf.add_release PROJECT, GEM_NAME, GEM_VERSION, *files
61
+ end
62
+
63
+ task :default => :spec
@@ -0,0 +1,19 @@
1
+ module Agnostic
2
+ class Config
3
+ def initialize
4
+ @hash = {}
5
+ end
6
+
7
+ def method_missing(method, *args, &block)
8
+ if args.empty?
9
+ @hash[method] ||= Config.new
10
+ elsif block.nil?
11
+ @hash[method] = args.size == 1 ? args.first : args
12
+ else
13
+ class << self; self end.class_eval do
14
+ define_method(method){block.call(*args)}
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ module Agnostic
2
+ module Helper
3
+ module_function
4
+ @helpers = []
5
+
6
+ def included(klass)
7
+ @helpers.each do |block|
8
+ klass.class_eval(&block)
9
+ end
10
+ end
11
+
12
+ def register(&block)
13
+ @helpers.push(block)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module Agnostic
2
+ class Plugin
3
+ def initialize
4
+ @config = Config.new
5
+ end
6
+
7
+ def method_missing(method, *args, &block)
8
+ @config.send(method, *args, &block)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ if defined?(Sinatra)
2
+ module Sinatra
3
+ helpers Agnostic::Helper
4
+ end
5
+ Agnostic.modify
6
+ end
7
+ if defined?(Merb::Plugin)
8
+ Merb::BootLoader.before_app_loads do
9
+ module Merb
10
+ module GlobalHelpers
11
+ include Agnostic::Helper
12
+ end
13
+ end
14
+ Agnostic.modify
15
+ end
16
+ end
data/lib/agnostic.rb ADDED
@@ -0,0 +1,34 @@
1
+ require File.join(File.dirname(__FILE__), %w[agnostic config])
2
+ require File.join(File.dirname(__FILE__), %w[agnostic plugin])
3
+ require File.join(File.dirname(__FILE__), %w[agnostic helper])
4
+
5
+ module Agnostic
6
+ module_function
7
+ @plugins = {}
8
+ @modifiers = []
9
+
10
+ def plugin(name, &block)
11
+ if block.nil?
12
+ @plugins[name]
13
+ else
14
+ @plugins[name] ||= Plugin.new
15
+ plugin(name).instance_eval(&block)
16
+ end
17
+ end
18
+
19
+ def helper(&block)
20
+ Helper.register(&block)
21
+ end
22
+
23
+ def modify(&block)
24
+ if block.nil?
25
+ @modifiers.each{|modifier| modifier.call}
26
+ else
27
+ @modifiers.push(block)
28
+ end
29
+ end
30
+
31
+ def polyglot
32
+ load File.join(File.dirname(__FILE__), %w[agnostic polyglot.rb])
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: agnostic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Genki Takiuchi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-24 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: An abstract framework for framework agnostic plugins
17
+ email: genki@s21g.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - Rakefile
26
+ - README
27
+ - lib/agnostic/config.rb
28
+ - lib/agnostic/helper.rb
29
+ - lib/agnostic/plugin.rb
30
+ - lib/agnostic/polyglot.rb
31
+ - lib/agnostic.rb
32
+ has_rdoc: true
33
+ homepage: http://blog.s21g.com/genki
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ requirements: []
54
+
55
+ rubyforge_project: asakusarb
56
+ rubygems_version: 1.3.4
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: An abstract framework for framework agnostic plugins
60
+ test_files: []
61
+