glue 0.24.0 → 0.25.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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  TITLE : &title Glue
4
4
  NAME : &pkg glue
5
- VERSION : '0.24.0'
5
+ VERSION : '0.25.0'
6
6
  STATUS : beta
7
7
 
8
8
  AUTHOR : George Moschovitis
@@ -15,7 +15,7 @@ DESCRIPTION: >
15
15
  Utility methods and classes for Nitro.
16
16
 
17
17
  DEPENDENCIES:
18
- - [ facets, '= 2005.10.15' ]
18
+ - [ facets, '= 2005.10.30' ]
19
19
  - [ cmdparse, '= 2.0.0' ]
20
20
 
21
21
  DISTRIBUTE: [ gem, tgz, zip ]
@@ -39,9 +39,6 @@ ANNOUNCE:
39
39
  sectype: tls # ~, tls, ssl (tls is broke)
40
40
  file: ANN
41
41
  slogan: Glue
42
-
43
-
44
-
45
42
  links:
46
43
  - http://www.nitrohq.com
47
44
 
@@ -1,3 +1,11 @@
1
+ == Version 0.25.0
2
+
3
+ This is the first in a series of releases focused on stability
4
+ and refinement. Many bugs where fixed, the high level api was
5
+ improved where needed, and we still got some small but incredibly
6
+ useful new features. Enjoy!
7
+
8
+
1
9
  == Version 0.24.0
2
10
 
3
11
  * Totaly recoded annotation / property system. The property
@@ -12,14 +12,22 @@ require 'English'
12
12
  require 'pp'
13
13
 
14
14
  require 'mega/null'
15
+ require 'mega/dynamod'
16
+ require 'nano/module/is'
15
17
 
16
18
  require 'glue/property'
17
19
  require 'glue/attribute'
18
20
 
19
- # Fix for Mega.
21
+ module Glue
22
+
23
+ # The version.
24
+
25
+ Version = '0.25.0'
26
+
27
+ # Library path.
28
+
29
+ LibPath = File.dirname(__FILE__)
20
30
 
21
- class NullClass
22
- def [](key); nil; end
23
31
  end
24
32
 
25
33
  class NilClass
@@ -60,18 +68,6 @@ module Kernel
60
68
  end
61
69
  end
62
70
 
63
- module Glue
64
-
65
- # The version.
66
-
67
- Version = '0.24.0'
68
-
69
- # Library path.
70
-
71
- LibPath = File.dirname(__FILE__)
72
-
73
- end
74
-
75
71
  # Include in the top level binding for easy access.
76
72
 
77
73
  include Glue
@@ -1,8 +1,8 @@
1
1
  require 'glue/builder'
2
2
 
3
- require 'nitro/mixin/xhtml'
4
- require 'nitro/mixin/form'
5
- require 'nitro/mixin/table'
3
+ require 'nitro/helper/xhtml'
4
+ require 'nitro/helper/form'
5
+ require 'nitro/helper/table'
6
6
 
7
7
  module Glue
8
8
 
@@ -12,9 +12,9 @@ module Glue
12
12
  #++
13
13
 
14
14
  class XmlBuilder < Builder
15
- include_builder Nitro::XhtmlMixin
16
- include_builder Nitro::TableMixin
17
- include_builder Nitro::FormMixin
15
+ include_builder Nitro::XhtmlHelper
16
+ include_builder Nitro::TableHelper
17
+ include_builder Nitro::FormHelper
18
18
 
19
19
  def method_missing(tag, *args, &block)
20
20
  self.class.module_eval <<-"end_eval", __FILE__, __LINE__
@@ -1,7 +1,3 @@
1
- # * George Moschovitis <gm@navel.gr>
2
- # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: mixins.rb 182 2005-07-22 10:07:50Z gmosx $
4
-
5
1
  module Glue
6
2
 
7
3
  # Generic expiring functionality mixin.
@@ -34,3 +30,5 @@ module Expirable
34
30
  end
35
31
 
36
32
  end
33
+
34
+ # * George Moschovitis <gm@navel.gr>
@@ -0,0 +1,121 @@
1
+ require 'singleton'
2
+ require 'redcloth'
3
+ require 'cgi'
4
+
5
+ require 'glue/sanitize'
6
+
7
+ module Glue
8
+
9
+ # Generalised Markup transformations.
10
+ #
11
+ # The expand methods evaluate (expand) the markup
12
+ # code to produce the final content. The compact
13
+ # methods reverse this process to create the original
14
+ # markup code. Not all markup transformations are
15
+ # reversible.
16
+ #
17
+ # When this library is included, the default PropertyUtils
18
+ # implementation is overriden to add markup support.
19
+ #
20
+ # === Examples
21
+ #
22
+ # Define your custom markup methods like this:
23
+ #
24
+ # module Markup
25
+ # def markup_simple
26
+ # ...
27
+ # end
28
+ # def markup_special
29
+ # ...
30
+ # end
31
+ #
32
+ # # maps the {{..}} macro
33
+ # alias_method :sanitize, :markup_simple
34
+ # # maps the {|..|} macro
35
+ # alias_method :markup, :markup_special
36
+ # end
37
+ #
38
+ # here comes the #{obj.body} # => prints the expanded version.
39
+ #
40
+ # obj.body = markup(@params['body'])
41
+
42
+ module Markup
43
+ # The default markup method. You should override this method
44
+ # in your application to call your custom markup
45
+ # methods.
46
+
47
+ def expand(str)
48
+ if str
49
+ xstr = str.dup
50
+ xstr.gsub!(/</, '&lt;')
51
+ xstr.gsub!(/>/, '&gt;')
52
+ xstr.gsub!(/\n/m, '<br/>')
53
+ return String.sanitize(xstr)
54
+ end
55
+ return nil
56
+ end
57
+ alias_method :sanitize, :expand
58
+
59
+ # ...
60
+
61
+ def expand_redcloth(str)
62
+ if str
63
+ return RedCloth.new(expand(str)).to_html
64
+ end
65
+ return nil
66
+ end
67
+ alias_method :markup, :expand_redcloth
68
+
69
+ # Compact (reverse) the content to the origial markup
70
+ # code. Not all markup transformations are reversible.
71
+ # You should override this method in your application
72
+ # to call your custom markup methods.
73
+ #
74
+ # NOT IMPLEMENTED.
75
+
76
+ def compact(str, meth = nil)
77
+ end
78
+
79
+ # Remove markup code from the input string.
80
+ #
81
+ # NOT IMPLEMENTED.
82
+
83
+ def clear(str)
84
+ end
85
+
86
+ def escape(str)
87
+ return nil unless str
88
+ CGI.escape(str.gsub(/ /, '_'))
89
+ end
90
+
91
+ def unescape(str)
92
+ CGI.unescape(str.gsub(/_/, ' '))
93
+ end
94
+
95
+ class << self
96
+ # Helper method for manipulating the sanitize transformation.
97
+
98
+ def setup_sanitize_transform(&block)
99
+ self.send :define_method, :sanitize, block
100
+ end
101
+ alias_method :setup_sanitize_transformation, :setup_sanitize_transform
102
+
103
+ # Helper method for manipulating the markup transformation.
104
+
105
+ def setup_markup_transform(&block)
106
+ self.send :define_method, :markup, block
107
+ end
108
+ alias_method :setup_markup_transformation, :setup_markup_transform
109
+ end
110
+ end
111
+
112
+ # An abstract Markup class.
113
+
114
+ class MarkupKit
115
+ extend Markup
116
+ include Markup
117
+ end
118
+
119
+ end
120
+
121
+ # * George Moschovitis <gm@navel.gr>
@@ -1,6 +1,6 @@
1
1
  require 'mega/annotation'
2
2
  require 'mega/inheritor'
3
- require 'mega/ohash'
3
+ require 'mega/dictionary'
4
4
 
5
5
  require 'glue/on_included'
6
6
  require 'og/entity'
@@ -69,7 +69,7 @@ class Property
69
69
  # if incoming file then read contents into a string.
70
70
 
71
71
  prop_value = values[prop_name]
72
- prop_value.read if prop_value.respond_to?(:read)
72
+ #TODO remove this? prop_value.read if prop_value.respond_to?(:read)
73
73
  prop_value = prop_value.to_s unless prop_value.is_a?(Hash) or prop_value.is_a?(Array)
74
74
 
75
75
  # If property is a Blob dont overwrite current property's data if "".
@@ -84,20 +84,7 @@ class Property
84
84
  # Only enabled if force_boolean == true.
85
85
 
86
86
  obj.send("__force_#{prop_name}", 0)
87
- else
88
- # check if there is a hashed version of the property (in the form values[symbol.part])
89
87
 
90
- property_parts = Hash.new
91
- values.each do |k,v|
92
- if k =~ /^#{prop_name}\./
93
- part_key = k.sub("#{prop_name}.", "")
94
- property_parts[part_key.to_sym] = values[k].to_s
95
- end
96
- end
97
-
98
- # pass the hashed version to __force_hash_ for processing.
99
-
100
- obj.send("__force_hash_#{prop_name}", property_parts) unless property_parts.empty?
101
88
  end
102
89
  end
103
90
 
@@ -116,7 +103,7 @@ class Property
116
103
  if foreign_oid = values[rel_name]
117
104
  foreign_oid = nil if foreign_oid == 'nil' or foreign_oid == 'none'
118
105
  end
119
- obj.send("__force_#{rel.foreign_key}", foreign_oid)
106
+ obj.send("__force_#{rel.foreign_key}", foreign_oid.to_s)
120
107
  elsif rel.kind_of? Og::JoinsMany or rel.kind_of? Og::HasMany
121
108
  # Empty current relationships.
122
109
 
@@ -143,30 +130,20 @@ class Property
143
130
 
144
131
  code = %{
145
132
  def __force_#{sym}(val)
146
- self.#{sym}=(} + case klass.name
147
- when 'Fixnum': 'val.nil? ? nil : val.to_i'
148
- when 'String': 'val.to_s'
149
- when 'Float': 'val.nil? ? nil : val.to_f'
150
- when 'Time': 'Time.parse(val.to_s)'
151
- when 'TrueClass', 'FalseClass': '(val == "on" or val == "true") ? true : (val.to_i > 0)'
152
- when 'Og::Blob': 'val'
153
- else
154
- 'val'
155
- end + %{)
156
- end
157
-
158
- def __force_hash_#{sym}(hash)
159
- }
160
-
161
- case klass.name
162
- when Time.name
163
- code << %{
164
- self.#{sym} = Time.local(hash[:year],hash[:month],hash[:day],hash[:hour],hash[:min])
165
- }
166
- end
167
-
168
- code << %{
169
- end
133
+ if respond_to?(:force_#{sym})
134
+ self.#{sym} = force_#{sym}(val)
135
+ else
136
+ self.#{sym}=(} << case klass.name
137
+ when Fixnum.name: 'val.nil? ? nil : val.to_i'
138
+ when String.name: 'val.to_s'
139
+ when Float.name: 'val.to_f'
140
+ when Time.name: 'val.is_a?(Hash) ? Time.local(val["year"],val["month"],val["day"],val["hour"],val["min"]) : Time.parse(val.to_s)'
141
+ when Date.name: 'val.is_a?(Hash) ? Time.local(val["year"],val["month"],val["day"]).to_date : Time.parse(val.to_s).to_date'
142
+ when TrueClass.name, FalseClass.name: 'val == "on" or val == "true" ? true
143
+ else 'val'
144
+ end + %{)
145
+ end
146
+ end
170
147
  }
171
148
 
172
149
  m.module_eval(code)
@@ -37,12 +37,12 @@ module TemplateMixin
37
37
  #
38
38
  # Example:
39
39
  # <?include href="root/myfile.sx" ?>
40
-
40
+
41
41
  text.gsub!(/<\?include href=["|'](.*?)["|'](.*)\?>/) do |match|
42
- text = File.read("#{base_dir}/#$1")
43
- text.gsub!(/<\?xml.*\?>/, '')
44
- text.gsub!(/<\/?root(.*?)>/m, ' ');
45
- text
42
+ itext = File.read("#{base_dir}/#$1")
43
+ itext.gsub!(/<\?xml.*\?>/, '')
44
+ itext.gsub!(/<\/?root(.*?)>/m, ' ');
45
+ itext
46
46
  end
47
47
 
48
48
  # Transform include instructions <include href="xxx" />
@@ -53,7 +53,7 @@ module TemplateMixin
53
53
  # add load_statically_included fixes.
54
54
 
55
55
  text.gsub!(/<include href=["|'](.*?)["|'](.*)(.?)\/>/) do |match|
56
- "<?r File.read( '\#\{@dispatcher.root\}/#$1' ?>"
56
+ "<?r File.read( '\#{@dispatcher.root}/#$1' ?>"
57
57
  end
58
58
 
59
59
  # xform render/inject instructions <render href="xxx" />
@@ -7,6 +7,9 @@ module Glue
7
7
  # objects. Typically used in Validator objects but can be
8
8
  # included in managed objects too.
9
9
  #
10
+ # Additional og-related validation macros can be found
11
+ # in lib/og/validation.
12
+ #
10
13
  # The following validation macros are available:
11
14
  #
12
15
  # * validate_value
@@ -55,7 +58,6 @@ module Glue
55
58
  #
56
59
  #--
57
60
  # TODO: all validation methods should imply validate_value
58
- # TODO: add validate_unique
59
61
  #++
60
62
 
61
63
  module Validation
@@ -5,13 +5,13 @@ require 'glue/property'
5
5
 
6
6
  module Mixin
7
7
  prop_accessor :date
8
- ann :this, :dummy => [123]
8
+ ann self, :dummy => [123]
9
9
  end
10
10
 
11
11
  class MixedOnly
12
12
  include Mixin
13
- ann.this.dummy! << 5
14
- ann.this.dummy! << 3
13
+ ann.self.dummy! << 5
14
+ ann.self.dummy! << 3
15
15
  end
16
16
 
17
17
  class MixedOnly2
@@ -33,12 +33,12 @@ end
33
33
 
34
34
  class Base
35
35
  prop_accessor :date
36
- ann :this, :dummy => [123]
36
+ ann self, :dummy => [123]
37
37
  end
38
38
 
39
39
  class Child1 < Base
40
- ann.this.dummy!.first << 5
41
- ann.this.dummy!.first << 3
40
+ ann.self.dummy!.first << 5
41
+ ann.self.dummy!.first << 3
42
42
  end
43
43
 
44
44
  class Child2 < Base
@@ -71,10 +71,10 @@ class TC_MixinsTest < ::Test::Unit::TestCase
71
71
  end
72
72
 
73
73
  def test_crosspolination
74
- assert_equal 3, MixedOnly.ann.this[:dummy].size
74
+ assert_equal 3, MixedOnly.ann.self[:dummy].size
75
75
  # FIXME:
76
- # assert_equal 1, MixedOnly2.ann.this[:dummy].size
77
- # assert_equal 1, Mixin.ann.this[:dummy].size
76
+ # assert_equal 1, MixedOnly2.ann.self[:dummy].size
77
+ # assert_equal 1, Mixin.ann.self[:dummy].size
78
78
  =begin
79
79
  gmosx: THINK!
80
80
  assert_equal 3, Child1.__meta[:dummy].first.size
@@ -28,5 +28,8 @@ class TestTemplate < Test::Unit::TestCase # :nodoc: all
28
28
  assert_match %r{\<li\>nitro\</li\>}, out
29
29
  assert_match %r{\<li\>really\</li\>}, out
30
30
  assert_match %r{Hello gmosx}, out
31
+
32
+ # TODO: add test for static inclusion.
33
+
31
34
  end
32
35
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: glue
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.24.0
7
- date: 2005-10-28
6
+ version: 0.25.0
7
+ date: 2005-11-17
8
8
  summary: Utility methods and classes for Nitro.
9
9
  require_paths:
10
10
  - lib
@@ -44,20 +44,18 @@ files:
44
44
  - lib/html
45
45
  - lib/glue/aspects.rb
46
46
  - lib/glue/attribute.rb
47
- - lib/glue/bit.rb
48
47
  - lib/glue/builder
49
48
  - lib/glue/builder.rb
50
49
  - lib/glue/configuration.rb
50
+ - lib/glue/expirable.rb
51
51
  - lib/glue/fixture.rb
52
52
  - lib/glue/flexob.rb
53
- - lib/glue/helper.rb
54
53
  - lib/glue/localization.rb
55
54
  - lib/glue/logger.rb
56
55
  - lib/glue/mail.rb
57
56
  - lib/glue/mailer
58
57
  - lib/glue/mailer.rb
59
- - lib/glue/mixins.rb
60
- - lib/glue/mock.rb
58
+ - lib/glue/markup.rb
61
59
  - lib/glue/on_included.rb
62
60
  - lib/glue/property.rb
63
61
  - lib/glue/sanitize.rb
@@ -112,7 +110,7 @@ dependencies:
112
110
  -
113
111
  - "="
114
112
  - !ruby/object:Gem::Version
115
- version: 2005.10.15
113
+ version: 2005.10.30
116
114
  version:
117
115
  - !ruby/object:Gem::Dependency
118
116
  name: cmdparse
@@ -1,53 +0,0 @@
1
- # (c) 2005 George Moschovitis <gm@navel.gr>
2
-
3
- def bitmask(bit)
4
- 1 << bit
5
- end
6
-
7
- def set_bit(num, bit)
8
- mask = bitmask(bit)
9
- num |= mask
10
- end
11
-
12
- def clear_bit(num, bit)
13
- mask = bitmask(bit)
14
- num &= mask
15
- end
16
-
17
- def test_bit(num, bit)
18
- mask = bitmask(bit)
19
- (num & mask) != 0
20
- end
21
- alias :bit? :test_bit
22
- alias :bit_set? :test_bit
23
-
24
- def set_bitmask(num, mask)
25
- num |= mask
26
- end
27
-
28
- def test_bitmask(num, mask)
29
- num &= mask
30
- end
31
- alias :bitmask? :test_bitmask
32
-
33
- if $0 == __FILE__
34
- a = 1
35
- m = bitmask(4)
36
- a = set_bitmask(a, m)
37
- p a
38
- p test_bitmask(a, m)
39
- p test_bit(a, 4)
40
- p bit_set?(a, 4)
41
- p test_bit(a, 12)
42
- end
43
-
44
- __END__
45
-
46
- Is it possible to get an interface like this?
47
-
48
- a = 1
49
- a.set_bit(3)
50
- if a.test_bit(3)
51
-
52
- if a.bit_set? 3
53
- end
@@ -1,31 +0,0 @@
1
- require 'nano/module/by_name'
2
-
3
- require 'glue/attribute'
4
-
5
- module Glue
6
-
7
- # Helpers are standard Ruby modules that contain utility
8
- # methods. By using the special 'helper'
9
- # macro provided by HelperSupport, the utility methods are
10
- # included as private methods.
11
-
12
- module Helpers
13
-
14
- def self.append_features(base)
15
- super
16
- base.module_eval do
17
- def self.helper(*modules)
18
- for mod in modules
19
- symbols = mod.instance_methods.collect { |m| m.to_sym }
20
- self.send(:include, mod)
21
- self.send(:private, *symbols)
22
- end
23
- end
24
- end
25
- end
26
-
27
- end
28
-
29
- end
30
-
31
- # * George Moschovitis <gm@navel.gr>
@@ -1,40 +0,0 @@
1
- require 'ostruct'
2
-
3
- # A simple mocking facility. Typically used in test cases.
4
- #
5
- # === Example:
6
- #
7
- # class ContextMock < Mock
8
- # mock :response_headers, {}
9
- # mock :host_url, 'http://www.nitrohq.com'
10
- # end
11
- #
12
- # ctx = ContextMock.new
13
- # ctx.response_headers['location'] = url
14
- # ctx.host_url
15
-
16
- class Mock < OpenStruct
17
- class << self
18
- attr :mocks
19
-
20
- # Mock a symbol, val is the default values. Useful
21
- # for mocking structured variables like arrays and
22
- # hashes.
23
-
24
- def mock(sym, val)
25
- @mocks ||= {}
26
- @mocks[sym] = val
27
- attr_accessor sym
28
- end
29
- end
30
-
31
- def initialize
32
- super
33
-
34
- for sym, val in self.class.mocks
35
- unless val.is_a? Proc
36
- instance_variable_set "@#{sym}", val
37
- end
38
- end
39
- end
40
- end