auser-dslify 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -7,26 +7,17 @@ config/hoe.rb
7
7
  config/requirements.rb
8
8
  dslify.gemspec
9
9
  lib/dslify.rb
10
- lib/dslify/core.rb
11
- lib/dslify/core/object.rb
12
- lib/dslify/core/string.rb
13
- lib/dslify/modules.rb
14
- lib/dslify/modules/configurable.rb
15
- lib/dslify/modules/method_missing_sugar.rb
10
+ lib/dslify/dslify.rb
16
11
  lib/dslify/version.rb
17
12
  script/console
18
13
  script/destroy
19
14
  script/generate
20
15
  script/txt2html
21
16
  setup.rb
22
- spec/configureable_spec.rb
23
- spec/method_missing_spec.rb
24
- spec/spec_helper.rb
25
17
  tasks/deployment.rake
26
18
  tasks/environment.rake
27
19
  tasks/website.rake
28
20
  test/test_dslify.rb
29
- test/test_helper.rb
30
21
  website/index.html
31
22
  website/index.txt
32
23
  website/javascripts/rounded_corners_lite.inc.js
data/dslify.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{dslify}
5
- s.version = "0.0.3"
5
+ s.version = "0.0.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ari Lerner"]
9
- s.date = %q{2009-02-16}
9
+ s.date = %q{2009-03-16}
10
10
  s.description = %q{Easily add DSL-like calls to any class}
11
11
  s.email = ["arilerner@mac.com"]
12
12
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.txt", "website/index.txt"]
13
- s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.txt", "Rakefile", "config/hoe.rb", "config/requirements.rb", "dslify.gemspec", "lib/dslify.rb", "lib/dslify/core.rb", "lib/dslify/core/object.rb", "lib/dslify/core/string.rb", "lib/dslify/modules.rb", "lib/dslify/modules/configurable.rb", "lib/dslify/modules/method_missing_sugar.rb", "lib/dslify/version.rb", "script/console", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "spec/configureable_spec.rb", "spec/method_missing_spec.rb", "spec/spec_helper.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "test/test_dslify.rb", "test/test_helper.rb", "website/index.html", "website/index.txt", "website/javascripts/rounded_corners_lite.inc.js", "website/stylesheets/screen.css", "website/template.html.erb"]
13
+ s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.txt", "Rakefile", "config/hoe.rb", "config/requirements.rb", "dslify.gemspec", "lib/dslify.rb", "lib/dslify/dslify.rb", "lib/dslify/version.rb", "script/console", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "tasks/deployment.rake", "tasks/environment.rake", "tasks/website.rake", "test/test_dslify.rb", "website/index.html", "website/index.txt", "website/javascripts/rounded_corners_lite.inc.js", "website/stylesheets/screen.css", "website/template.html.erb"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://dslify.rubyforge.org}
16
16
  s.post_install_message = %q{Thanks for installing dslify!
@@ -23,7 +23,7 @@ Ari Lerner}
23
23
  s.rubyforge_project = %q{dslify}
24
24
  s.rubygems_version = %q{1.3.1}
25
25
  s.summary = %q{Easily add DSL-like calls to any class}
26
- s.test_files = ["test/test_dslify.rb", "test/test_helper.rb"]
26
+ s.test_files = ["test/test_dslify.rb"]
27
27
 
28
28
  if s.respond_to? :specification_version then
29
29
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -0,0 +1,23 @@
1
+ # Quick 1-file dsl accessor
2
+ class Object
3
+ def h
4
+ @h||={}
5
+ end
6
+ def dsl_options;h;end
7
+ def set_vars_from_options(h={})
8
+ h.each{|k,v|send k.to_sym, v } unless h.empty?
9
+ end
10
+ def method_missing(m,*a,&block)
11
+ if block
12
+ if args.empty?
13
+ ((a[0].class==self.class)?a[0].instance_eval(&block): super)
14
+ else
15
+ inst = a[0]
16
+ inst.instance_eval(&block)
17
+ h[m] = inst
18
+ end
19
+ else
20
+ ((a.empty?)?h[m]:h[m.to_s.gsub(/\=/,"").to_sym]=(a.size>1?a:a[0]))
21
+ end
22
+ end
23
+ end
@@ -2,7 +2,7 @@ module Dslify
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 3
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  self
data/lib/dslify.rb CHANGED
@@ -4,9 +4,4 @@ $:.unshift(File.dirname(__FILE__)) unless
4
4
  Dir["#{File.dirname(__FILE__)}/dslify/*.rb"].each {|f| require f }
5
5
 
6
6
  module Dslify
7
- def self.included(base)
8
- %w(Configurable MethodMissingSugar).each do |inc|
9
- base.send :include, "Dslify::#{inc}".constantize
10
- end
11
- end
12
7
  end
data/test/test_dslify.rb CHANGED
@@ -1,11 +1,46 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class TestDslify < Test::Unit::TestCase
4
-
5
- def setup
6
- end
7
-
8
- def test_truth
9
- assert true
10
- end
11
- end
1
+ require "rubygems"
2
+ require "#{::File.dirname(__FILE__)}/../lib/dslify"
3
+ require "matchy"
4
+ require "context"
5
+
6
+ class Quickie
7
+ end
8
+
9
+ class QuickieTest < Test::Unit::TestCase
10
+ context "setting" do
11
+ before do
12
+ @q = Quickie.new
13
+ end
14
+ it "should be able to set methods on self" do
15
+ lambda{@q.bank "bobs"}.should_not raise_error
16
+ end
17
+ it "should set and then retrieve the same value back" do
18
+ @q.snobs "are mean"
19
+ @q.snobs.should == "are mean"
20
+ end
21
+ it "should set and retrieve values back with an = sign" do
22
+ @q.author = "Ari Lerner"
23
+ @q.author.should == "Ari Lerner"
24
+ end
25
+ it "should set these values in the h Hash on the object" do
26
+ @q.movies "can be fun"
27
+ @q.h.keys.should == [:movies]
28
+ end
29
+ it "should set multiple keys with set_vars_from_options" do
30
+ @q.set_vars_from_options({:a => "a", :b => "b"})
31
+ @q.a.should == "a"
32
+ @q.b.should == "b"
33
+ end
34
+ it "should set methods even when they are called with a block" do
35
+ @q.bobs Quickie.new do
36
+ end
37
+ @q.bobs.class.should == Quickie
38
+ end
39
+ it "should set the methods on the inner block" do
40
+ @q.bobs Quickie.new do
41
+ franks "franke"
42
+ end
43
+ @q.bobs.franks.should == "franke"
44
+ end
45
+ end
46
+ end
data/website/index.html CHANGED
@@ -1,11 +1,86 @@
1
- <html>
2
- <head>
3
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
4
- <title>dslify</title>
5
-
6
- </head>
7
- <body id="body">
8
- <p>This page has not yet been created for RubyGem <code>dslify</code></p>
9
- <p>To the developer: To generate it, update website/index.txt and run the rake task <code>website</code> to generate this <code>index.html</code> file.</p>
10
- </body>
11
- </html>
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
+ <title>
8
+ dslify
9
+ </title>
10
+ <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
+ <style>
12
+
13
+ </style>
14
+ <script type="text/javascript">
15
+ window.onload = function() {
16
+ settings = {
17
+ tl: { radius: 10 },
18
+ tr: { radius: 10 },
19
+ bl: { radius: 10 },
20
+ br: { radius: 10 },
21
+ antiAlias: true,
22
+ autoPad: true,
23
+ validTags: ["div"]
24
+ }
25
+ var versionBox = new curvyCorners(settings, document.getElementById("version"));
26
+ versionBox.applyCornersToAll();
27
+ }
28
+ </script>
29
+ </head>
30
+ <body>
31
+ <div id="main">
32
+
33
+ <h1>dslify</h1>
34
+ <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/dslify"; return false'>
35
+ <p>Get Version</p>
36
+ <a href="http://rubyforge.org/projects/dslify" class="numbers">0.0.4</a>
37
+ </div>
38
+ <h1>&amp;#x2192; &#8216;dslify&#8217;</h1>
39
+ <h2>What</h2>
40
+ <h2>Installing</h2>
41
+ <p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">dslify</span></pre></p>
42
+ <h2>The basics</h2>
43
+ <h2>Demonstration of usage</h2>
44
+ <h2>Forum</h2>
45
+ <p><a href="http://groups.google.com/group/dslify">http://groups.google.com/group/dslify</a></p>
46
+ <p><span class="caps">TODO</span> &#8211; create Google Group &#8211; dslify</p>
47
+ <h2>How to submit patches</h2>
48
+ <p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people&#8217;s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
49
+ <p><span class="caps">TODO</span> &#8211; pick <span class="caps">SVN</span> or Git instructions</p>
50
+ <p>The trunk repository is <code>svn://rubyforge.org/var/svn/dslify/trunk</code> for anonymous access.</p>
51
+ <p><span class="caps">OOOORRRR</span></p>
52
+ <p>You can fetch the source from either:</p>
53
+ <ul>
54
+ <li>rubyforge: <span class="caps">MISSING</span> IN <span class="caps">ACTION</span></li>
55
+ </ul>
56
+ <p><span class="caps">TODO</span> &#8211; You can not created a RubyForge project, OR have not run <code>rubyforge config</code><br />
57
+ yet to refresh your local rubyforge data with this projects&#8217; id information.</p>
58
+ <p>When you do this, this message will magically disappear!</p>
59
+ <p>Or you can hack website/index.txt and make it all go away!!</p>
60
+ <ul>
61
+ <li>github: <a href="http://github.com/GITHUB_USERNAME/dslify/tree/master">http://github.com/GITHUB_USERNAME/dslify/tree/master</a></li>
62
+ </ul>
63
+ <pre>git clone git://github.com/GITHUB_USERNAME/dslify.git</pre>
64
+ <p><span class="caps">TODO</span> &#8211; add &#8220;github_username: username&#8221; to ~/.rubyforge/user-config.yml and newgem will reuse it for future projects.</p>
65
+ <ul>
66
+ <li>gitorious: <a href="git://gitorious.org/dslify/mainline.git">git://gitorious.org/dslify/mainline.git</a></li>
67
+ </ul>
68
+ <pre>git clone git://gitorious.org/dslify/mainline.git</pre>
69
+ <h3>Build and test instructions</h3>
70
+ <pre>cd dslify
71
+ rake test
72
+ rake install_gem</pre>
73
+ <h2>License</h2>
74
+ <p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
75
+ <h2>Contact</h2>
76
+ <p>Comments are welcome. Send an email to <a href="mailto:FIXME"><span class="caps">FIXME</span> full name</a> email via the <a href="http://groups.google.com/group/dslify">forum</a></p>
77
+ <p class="coda">
78
+ <a href="FIXME email">FIXME full name</a>, 26th January 2009<br>
79
+ Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
80
+ </p>
81
+ </div>
82
+
83
+ <!-- insert site tracking codes here, like Google Urchin -->
84
+
85
+ </body>
86
+ </html>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auser-dslify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ari Lerner
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-16 00:00:00 -08:00
12
+ date: 2009-03-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -45,26 +45,17 @@ files:
45
45
  - config/requirements.rb
46
46
  - dslify.gemspec
47
47
  - lib/dslify.rb
48
- - lib/dslify/core.rb
49
- - lib/dslify/core/object.rb
50
- - lib/dslify/core/string.rb
51
- - lib/dslify/modules.rb
52
- - lib/dslify/modules/configurable.rb
53
- - lib/dslify/modules/method_missing_sugar.rb
48
+ - lib/dslify/dslify.rb
54
49
  - lib/dslify/version.rb
55
50
  - script/console
56
51
  - script/destroy
57
52
  - script/generate
58
53
  - script/txt2html
59
54
  - setup.rb
60
- - spec/configureable_spec.rb
61
- - spec/method_missing_spec.rb
62
- - spec/spec_helper.rb
63
55
  - tasks/deployment.rake
64
56
  - tasks/environment.rake
65
57
  - tasks/website.rake
66
58
  - test/test_dslify.rb
67
- - test/test_helper.rb
68
59
  - website/index.html
69
60
  - website/index.txt
70
61
  - website/javascripts/rounded_corners_lite.inc.js
@@ -104,4 +95,3 @@ specification_version: 2
104
95
  summary: Easily add DSL-like calls to any class
105
96
  test_files:
106
97
  - test/test_dslify.rb
107
- - test/test_helper.rb
@@ -1,15 +0,0 @@
1
- class Object
2
- def vputs(m="", o=self)
3
- puts m if o.verbose rescue ""
4
- end
5
- def returning(receiver)
6
- yield receiver
7
- receiver
8
- end
9
- def run_in_context(context=self, &block)
10
- name="temp_#{self.class}_#{respond_to?(:parent) ? parent.to_s : Time.now.to_i}".to_sym
11
- meta_def name, &block
12
- self.send name, context
13
- meta_undef name rescue ""
14
- end
15
- end
@@ -1,12 +0,0 @@
1
- class String
2
- def constantize
3
- names = self.split('::')
4
- names.shift if names.empty? || names.first.empty?
5
-
6
- constant = Object
7
- names.each do |name|
8
- constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
9
- end
10
- constant
11
- end
12
- end
data/lib/dslify/core.rb DELETED
@@ -1 +0,0 @@
1
- Dir["#{File.dirname(__FILE__)}/core/*.rb"].each {|f| require f }
@@ -1,40 +0,0 @@
1
- module Dslify
2
- module Configurable
3
- module ClassMethods
4
- def default_options(h={})
5
- @default_options ||= h
6
- end
7
- end
8
-
9
- module InstanceMethods
10
- def __options(h={})
11
- @__options ||= self.class.default_options.merge(h)
12
- end
13
-
14
- def configure(h={})
15
- __options(h).merge!(h)
16
- end
17
-
18
- def reconfigure(h={})
19
- @__options = nil
20
- __options(h)
21
- end
22
-
23
- def set_vars_from_options(opts={})
24
- opts.each {|k,v| self.send k.to_sym, v } unless opts.empty?
25
- end
26
-
27
- def dsl_options_keys
28
- __options.keys
29
- end
30
- def dsl_options
31
- __options
32
- end
33
- end
34
-
35
- def self.included(receiver)
36
- receiver.extend ClassMethods
37
- receiver.send :include, InstanceMethods
38
- end
39
- end
40
- end
@@ -1,23 +0,0 @@
1
- module Dslify
2
- module MethodMissingSugar
3
-
4
- def method_missing(m, *args, &block)
5
- if block_given?
6
- (args[0].class == self.class) ? args[0].run_in_context(&block) : super
7
- else
8
- get_from_options(m.to_s, *args, &block)
9
- end
10
- end
11
-
12
- def get_from_options(meth, *args, &block)
13
- key = meth.include?("=") ? meth.delete("=") : meth
14
- sym_key = key.to_sym
15
- if args.empty?
16
- __options.has_key?(sym_key) ? __options[sym_key] : nil
17
- else
18
- __options[sym_key] = (args.is_a?(Array) && args.size > 1) ? args : args[0]
19
- end
20
- end
21
-
22
- end
23
- end
@@ -1,4 +0,0 @@
1
- Dir["#{File.dirname(__FILE__)}/modules/*.rb"].each {|f| require f }
2
-
3
- module Dslify
4
- end
@@ -1,33 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- class TestClass2
4
- include Configurable
5
- end
6
-
7
- describe "configurable" do
8
- before(:each) do
9
- @tc = TestClass2.new
10
- end
11
- it "should set the name as frank" do
12
- @tc.configure({:name => "frank"})
13
- @tc.name.should == "frank"
14
- end
15
- it "should reset the name after it's been set" do
16
- @tc.configure({:name => "frank"})
17
- @tc.configure({:name => "timmy"})
18
- @tc.name.should == "timmy"
19
- end
20
- it "should be able to reconfigure itself" do
21
- @tc.configure(:name => "walter")
22
- @tc.reconfigure(:name => "dewey")
23
- @tc.name.should == "dewey"
24
- end
25
- it "should send an array if two arguments are given" do
26
- @tc.configure({:name => ["array", "ishere"]})
27
- @tc.name.should == ["array", "ishere"]
28
- end
29
- it "should return a list of the configured keys" do
30
- @tc.configure :name => "bob"
31
- @tc.dsl_option_keys.should == [:name]
32
- end
33
- end
@@ -1,28 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- class TestClass
4
- include MethodMissingSugar
5
- end
6
-
7
- describe "MethodMissingSugar" do
8
- before(:each) do
9
- @tc = TestClass.new
10
- end
11
- it "should add the value of the unknown variable into the options of the instance" do
12
- @tc.__options[:name].should be_nil
13
- @tc.name "is_my_name"
14
- @tc.__options[:name].should_not be_nil
15
- end
16
- it "should call the value in the options when calling it as a method" do
17
- @tc.__options[:valentine] = "will you be my"
18
- @tc.valentine.should == "will you be my"
19
- end
20
- it "should accept a method called on the instance without an = sign" do
21
- @tc.pop "goes the weasel"
22
- @tc.pop.should == "goes the weasel"
23
- end
24
- it "should accept a method with the = sign which should set the variable" do
25
- @tc.hop = "goes the bunny"
26
- @tc.hop.should == "goes the bunny"
27
- end
28
- end
data/spec/spec_helper.rb DELETED
@@ -1,15 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
-
4
- require "rubygems"
5
- %w(spec).each do |library|
6
- begin
7
- require library
8
- rescue
9
- STDERR.puts "== Cannot run test without #{library}"
10
- end
11
- end
12
-
13
- require "#{File.dirname(__FILE__)}/../lib/dslify"
14
-
15
- include Dslify
data/test/test_helper.rb DELETED
@@ -1,2 +0,0 @@
1
- require 'test/unit'
2
- require File.dirname(__FILE__) + '/../lib/dslify'