ruhl 0.6.0 → 0.7.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.
Files changed (7) hide show
  1. data/README +100 -18
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/lib/ruhl.rb +4 -3
  5. data/lib/ruhl/rails.rb +7 -4
  6. data/ruhl.gemspec +2 -2
  7. metadata +2 -2
data/README CHANGED
@@ -1,27 +1,109 @@
1
- Ruhl (Ruby Hypertext Language)
1
+ RuHL (Ruby Hypertext Language)
2
2
 
3
- This project is here to flesh out an idea. What I want is to have developers
4
- work with HTML and with the simple addition of a 'data-ruhl' attribute, convert it
5
- to a dynamic page.
6
3
 
7
- At no time in the dev process would the view be unviewable in a browser.
8
- The view could actually retain the original template data the designer used
9
- because this replaces the content. I think this is a nice plus.
4
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
+ :: What? ::
6
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7
+
8
+ RuHL parses HTML (using Nokogiri) and by using a data-ruhl attribute, makes
9
+ the contents dynamic!
10
+
11
+ Let's say you have the following HTML in a file called ('hello_world.ruhl')
12
+
13
+ <html>
14
+ <body>
15
+ <p data-ruhl="say_hello"/>
16
+ </body>
17
+ </html>
18
+
19
+ And you have the following method available to self:
20
+
21
+ def say_hello
22
+ "Hello World"
23
+ end
24
+
25
+ If you call
26
+
27
+ RuHL::Engine.new(File.read('hello_world.ruhl')).render(self)
28
+
29
+ It will return:
30
+
31
+ <html>
32
+ <body>
33
+ <p>Hello World</p>
34
+ </body>
35
+ </html>
36
+
37
+ Notice that it removes the data-ruhl attribute.
10
38
 
11
39
 
12
- Notes (use cases) for me to remember:
40
+ You can pass an options hash to RuHL:
41
+ RuHL::Engine.new(File.read('hello_world.ruhl'), options).render(self)
42
+
43
+ Right now, RuHL knows the following options:
44
+
45
+ :layout => This is the file name of the layout
46
+
47
+ :layout_source => If the framework (like Rails) has already read the file,
48
+ pass the contents through so RuHL doesn't have to reread
49
+ the file.
50
+
51
+ If you don't pass :layout_source, RuHL must be able to
52
+ find/read :layout
53
+
54
+ :local_object => If you are rendering a show page for @person, pass the
55
+ @person object into RuHL. RuHL will first try to call
56
+ the methods against the local_object then try the scope.
57
+
58
+ For example:
59
+ <li data-ruhl="first_name">
60
+
61
+ RuHL will first try @person.first_name.
62
+
63
+
64
+
65
+ There are some special methods defined by RuHL (examples follow):
66
+
67
+ _render_ - This is used in your layout and lets rule know where to inject
68
+ the rendered sub content.
69
+
70
+ _partial - Path to a partial file. RuHL must be able to find/read this file.
71
+
72
+ _if - If the method returns nil, the tag will not be included on output.
73
+
74
+ _render_if - If the method returns false, the tag will not be included on output.
75
+
76
+ _collection - RuHL expects the method reference to return an array of objects.
77
+ RuHL will iteratate over the collection and render the contents
78
+ of the tag agains the collection item. (example below)
79
+
80
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
81
+ :: Rails ::
82
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83
+
84
+ In your config/environment.rb :
85
+
86
+ config.gem 'ruhl', :lib => 'ruhl/rails'
87
+
88
+ Your filenames should end in .ruhl ('show.html.ruhl')
13
89
 
14
90
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15
- :: Basic Use ::
91
+ :: Sinatra ::
16
92
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17
93
 
18
- <h1 data-ruhl="page_header">
94
+ require 'ruhl/sinatra'
95
+
96
+ You can then do:
19
97
 
20
- Method :page_header would know how to represent itself in the context of
21
- the h1 element.
98
+ get '/' do
99
+ ruhl(:index, :layout => path_to_layout)
100
+ end
22
101
 
23
- The Ruby executed would replace the content of the element it was being
24
- called on.
102
+ *******************************************************************************
103
+ *
104
+ * EXAMPLES
105
+ *
106
+ *******************************************************************************
25
107
 
26
108
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27
109
  :: Replacing attribute values ::
@@ -96,12 +178,12 @@ Fragment:
96
178
 
97
179
  To use:
98
180
 
99
- Ruhl::Engine.new(File.read(fragment), :layout => path_to_layout).render(self)
181
+ RuHL::Engine.new(File.read(fragment), :layout => path_to_layout).render(self)
100
182
 
101
183
  Returns the expected result of parsed Layout w/ parsed Fragment.
102
184
 
103
185
  Note the use of the _render_ method. This is a 'special' method that
104
- Ruhl uses to inject the results of the parsed fragment into the layout.
186
+ RuHL uses to inject the results of the parsed fragment into the layout.
105
187
 
106
188
 
107
189
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -143,12 +225,12 @@ Sidebar:
143
225
 
144
226
  To use:
145
227
 
146
- Ruhl::Engine.new(File.read(path_to_main)).render(self)
228
+ RuHL::Engine.new(File.read(path_to_main)).render(self)
147
229
 
148
230
  Returns the expected result of parsed Main with sidebar div contents
149
231
  replaced with parsed sidebar partial contents.
150
232
 
151
- Note the use of the _partial key. This is a 'special' key that Ruhl
233
+ Note the use of the _partial key. This is a 'special' key that RuHL
152
234
  uses to inject the results of the parsed partial into the contents
153
235
  of the calling node.
154
236
 
data/Rakefile CHANGED
@@ -19,7 +19,7 @@ begin
19
19
  Jeweler::Tasks.new do |gemspec|
20
20
  gemspec.name = "ruhl"
21
21
  gemspec.summary = "Ruby Hypertext Language"
22
- gemspec.description = "Make your HTML dynamic with the addition of a ruby attribute."
22
+ gemspec.description = "Make your HTML dynamic with the addition of a data-ruhl attribute."
23
23
  gemspec.email = "andy@stonean.com"
24
24
  gemspec.homepage = "http://github.com/stonean/ruhl"
25
25
  gemspec.authors = ["Andrew Stone"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.7.0
@@ -5,10 +5,11 @@ require 'ruhl/errors'
5
5
 
6
6
  module Ruhl
7
7
  class Engine
8
- attr_reader :document, :scope, :layout, :local_object
8
+ attr_reader :document, :scope, :layout, :layout_source, :local_object
9
9
 
10
10
  def initialize(html, options = {})
11
- @local_object = options[:local_object]
11
+ @local_object = options[:local_object]
12
+ @layout_source = options[:layout_source]
12
13
 
13
14
  if @layout = options[:layout]
14
15
  raise LayoutNotFoundError.new(@layout) unless File.exists?(@layout)
@@ -44,7 +45,7 @@ module Ruhl
44
45
  private
45
46
 
46
47
  def render_with_layout
47
- render_file( File.read(@layout) )
48
+ render_file( @layout_source || File.read(@layout) )
48
49
  end
49
50
 
50
51
  def render_partial(tag, code)
@@ -1,3 +1,5 @@
1
+ require 'ruhl'
2
+
1
3
  module Ruhl
2
4
  class Plugin < ActionView::TemplateHandler
3
5
 
@@ -5,12 +7,13 @@ module Ruhl
5
7
  @action_view = action_view
6
8
  end
7
9
 
8
- def render(template, options)
10
+ def render(template, options = {})
9
11
  layout = @action_view.controller.send(:active_layout)
10
12
 
11
- puts "==========> @action_view: #{@action_view.controller.response.inspect}"
12
- puts "==========> template: #{template.inspect}"
13
- puts "==========> options: #{options.inspect}"
13
+ options[:layout] = layout.filename
14
+ options[:layout_source] = layout.source
15
+
16
+ Ruhl::Engine.new(template.source, options).render(@action_view)
14
17
  end
15
18
  end
16
19
  end
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruhl}
8
- s.version = "0.6.0"
8
+ s.version = "0.7.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrew Stone"]
12
12
  s.date = %q{2009-10-07}
13
- s.description = %q{Make your HTML dynamic with the addition of a ruby attribute.}
13
+ s.description = %q{Make your HTML dynamic with the addition of a data-ruhl attribute.}
14
14
  s.email = %q{andy@stonean.com}
15
15
  s.extra_rdoc_files = [
16
16
  "README"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruhl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Stone
@@ -32,7 +32,7 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: "0"
34
34
  version:
35
- description: Make your HTML dynamic with the addition of a ruby attribute.
35
+ description: Make your HTML dynamic with the addition of a data-ruhl attribute.
36
36
  email: andy@stonean.com
37
37
  executables: []
38
38