rxhp 0.1.2 → 0.2.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/lib/rxhp/fragment.rb CHANGED
@@ -5,6 +5,9 @@ module Rxhp
5
5
  #
6
6
  # Can be used like an array, or if you just need something that acts like
7
7
  # an element - this is used internally as the root of all render trees.
8
+ #
9
+ # You probably don't want to use this directly, as it doesn't know to
10
+ # render strings. You might want {HtmlFragment} instead.
8
11
  class Fragment < Element
9
12
  # Call {#render_children}
10
13
  def render options = {}
@@ -12,3 +15,6 @@ module Rxhp
12
15
  end
13
16
  end
14
17
  end
18
+
19
+ Rxhp::Scope.define_element :fragment, Rxhp::Fragment
20
+ Rxhp::Scope.define_element :frag, Rxhp::Fragment
data/lib/rxhp/html.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rxhp/data/html/attributes'
2
2
  require 'rxhp/data/html/tags'
3
+ require 'rxhp/html_fragment'
3
4
 
4
5
  module Rxhp
5
6
  # Namespace for all HTML-related classes and methods.
@@ -7,28 +8,8 @@ module Rxhp
7
8
  # Most of RXhp is for generic trees; everything that is HTML or XML
8
9
  # specific is defined here, or in {HtmlElement} and its subclasses.
9
10
  module Html
10
- # Add a child node.
11
- #
12
- # @example
13
- # include Rxhp::Html
14
- # p do
15
- # text 'foo'
16
- # text 'bar'
17
- # end
18
- def fragment x
19
- Rxhp::Scope.current.children.push x
20
- end
21
- alias :frag :fragment
22
- alias :text :fragment
23
-
24
- class <<self
25
- def fragment x
26
- scope = Rxhp::Scope.current
27
- scope.children.push x
28
- scope
29
- end
30
- alias :frag :fragment
31
- alias :text :fragment
11
+ def self.escape text
12
+ text.gsub('&','&amp;').gsub('<','&lt;').gsub('>','&gt;').gsub('"','&quot;')
32
13
  end
33
14
  end
34
15
  end
@@ -55,3 +36,11 @@ Rxhp::Html::TAGS.each do |tag, data|
55
36
  Rxhp::Scope.define_element tag, klass, Rxhp::Html
56
37
  end
57
38
  end
39
+
40
+ [
41
+ :fragment,
42
+ :frag,
43
+ :text,
44
+ ].each do |name|
45
+ Rxhp::Scope.define_element name, Rxhp::HtmlFragment, Rxhp::Html
46
+ end
@@ -151,7 +151,7 @@ module Rxhp
151
151
 
152
152
  # Don't pull in ActiveSupport just for this...
153
153
  def html_escape s
154
- s.gsub('&','&amp;').gsub('<','&lt;').gsub('>','&gt;').gsub('"','&quot;')
154
+ Rxhp::Html.escape(s)
155
155
  end
156
156
  end
157
157
  end
@@ -0,0 +1,19 @@
1
+ require 'rxhp/fragment'
2
+ require 'rxhp/html'
3
+
4
+ module Rxhp
5
+ # Subclass of fragment that is able to render strings.
6
+ #
7
+ # This is available as +Rxhp::Html#fragment+, +#frag+, and +#text+.
8
+ class HtmlFragment < Fragment
9
+ def render_string string, options = {}
10
+ escaped = Rxhp::Html.escape(string)
11
+ if options[:pretty]
12
+ indent = ' ' * (options[:indent] * options[:depth])
13
+ indent + escaped + "\n"
14
+ else
15
+ escaped
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/rxhp/scope.rb CHANGED
@@ -9,25 +9,6 @@ module Rxhp
9
9
  # The actual HTML classes are defined in rxhp/html.rb
10
10
  #
11
11
  module Scope
12
- # Helper function to append a child to the current context.
13
- #
14
- # @example Here's one I made earlier
15
- # inner = body { 'hi' }
16
- # html do
17
- # fragment inner
18
- # end
19
- #
20
- # @example Multiple +String+ children
21
- # p do
22
- # text 'foo'
23
- # text 'bar'
24
- # end
25
- def fragment x
26
- Rxhp::Scope.current.children.push x
27
- end
28
- alias :frag :fragment
29
- alias :text :fragment
30
-
31
12
  # The element nesting scope.
32
13
  #
33
14
  # @example
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rxhp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-26 00:00:00.000000000Z
12
+ date: 2012-02-05 00:00:00.000000000 +01:00
13
+ default_executable:
13
14
  dependencies: []
14
15
  description: An object-oriented validating HTML template system
15
16
  email:
@@ -28,11 +29,13 @@ files:
28
29
  - lib/rxhp/fragment.rb
29
30
  - lib/rxhp/html.rb
30
31
  - lib/rxhp/html_element.rb
32
+ - lib/rxhp/html_fragment.rb
31
33
  - lib/rxhp/html_self_closing_element.rb
32
34
  - lib/rxhp/html_singleton_element.rb
33
35
  - lib/rxhp/scope.rb
34
36
  - lib/rxhp/tags/html_tag.rb
35
37
  - lib/rxhp.rb
38
+ has_rdoc: true
36
39
  homepage: https://github.com/fredemmott/rxhp
37
40
  licenses: []
38
41
  post_install_message:
@@ -53,9 +56,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
56
  version: '0'
54
57
  requirements: []
55
58
  rubyforge_project:
56
- rubygems_version: 1.8.6
59
+ rubygems_version: 1.6.2
57
60
  signing_key:
58
61
  specification_version: 3
59
62
  summary: An object-oriented validating HTML template system
60
63
  test_files: []
61
- has_rdoc: