tagz 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/a.rb +11 -0
  2. data/gemspec.rb +27 -0
  3. data/gen_readme.rb +32 -0
  4. data/install.rb +210 -0
  5. data/lib/tagz.rb +376 -0
  6. data/lib/tagz/rails.rb +198 -0
  7. data/rails/README +182 -0
  8. data/rails/Rakefile +10 -0
  9. data/rails/app/controllers/application.rb +7 -0
  10. data/rails/app/controllers/tagz_controller.rb +51 -0
  11. data/rails/app/helpers/application_helper.rb +3 -0
  12. data/rails/app/helpers/tagz_helper.rb +2 -0
  13. data/rails/app/views/layouts/layout.rb +16 -0
  14. data/rails/app/views/tagz/b.rb +19 -0
  15. data/rails/app/views/tagz/c.rb +9 -0
  16. data/rails/app/views/tagz/d.rhtml +17 -0
  17. data/rails/app/views/tagz/e.rb +3 -0
  18. data/rails/config/boot.rb +45 -0
  19. data/rails/config/database.yml +36 -0
  20. data/rails/config/environment.rb +65 -0
  21. data/rails/config/environments/development.rb +21 -0
  22. data/rails/config/environments/production.rb +18 -0
  23. data/rails/config/environments/test.rb +19 -0
  24. data/rails/config/lighttpd.conf +54 -0
  25. data/rails/config/routes.rb +23 -0
  26. data/rails/doc/README_FOR_APP +2 -0
  27. data/rails/log/development.log +6713 -0
  28. data/rails/log/fastcgi.crash.log +103 -0
  29. data/rails/log/lighttpd.access.log +171 -0
  30. data/rails/log/lighttpd.error.log +116 -0
  31. data/rails/log/production.log +0 -0
  32. data/rails/log/server.log +0 -0
  33. data/rails/log/test.log +0 -0
  34. data/rails/public/404.html +30 -0
  35. data/rails/public/500.html +30 -0
  36. data/rails/public/dispatch.cgi +10 -0
  37. data/rails/public/dispatch.fcgi +24 -0
  38. data/rails/public/dispatch.rb +10 -0
  39. data/rails/public/favicon.ico +0 -0
  40. data/rails/public/images/rails.png +0 -0
  41. data/rails/public/index.html +277 -0
  42. data/rails/public/javascripts/application.js +2 -0
  43. data/rails/public/javascripts/controls.js +833 -0
  44. data/rails/public/javascripts/dragdrop.js +942 -0
  45. data/rails/public/javascripts/effects.js +1088 -0
  46. data/rails/public/javascripts/prototype.js +2515 -0
  47. data/rails/public/robots.txt +1 -0
  48. data/rails/script/about +3 -0
  49. data/rails/script/breakpointer +3 -0
  50. data/rails/script/console +3 -0
  51. data/rails/script/destroy +3 -0
  52. data/rails/script/generate +3 -0
  53. data/rails/script/performance/benchmarker +3 -0
  54. data/rails/script/performance/profiler +3 -0
  55. data/rails/script/plugin +3 -0
  56. data/rails/script/process/inspector +3 -0
  57. data/rails/script/process/reaper +3 -0
  58. data/rails/script/process/spawner +3 -0
  59. data/rails/script/runner +3 -0
  60. data/rails/script/server +4 -0
  61. data/rails/test/functional/tagz_controller_test.rb +18 -0
  62. data/rails/test/test_helper.rb +28 -0
  63. data/rails/tmp/cache/index.html-gzip-1958902-7552-1181801882 +0 -0
  64. data/rails/tmp/cache/javascripts/effects.js-gzip-1958907-38200-1181801882 +0 -0
  65. data/rails/tmp/cache/javascripts/prototype.js-gzip-1958906-71260-1181801882 +0 -0
  66. data/rails/tmp/sessions/ruby_sess.365e696810aa7418 +0 -0
  67. data/rails/tmp/sessions/ruby_sess.3ab0cb2f589d3855 +0 -0
  68. data/rails/tmp/sessions/ruby_sess.c812e68d96a6e99f +0 -0
  69. data/rails/tmp/sessions/ruby_sess.e0a954440a7e27d7 +0 -0
  70. data/sample/a.rb +9 -0
  71. data/test/tagz.rb +436 -0
  72. data/tidy +3 -0
  73. metadata +161 -0
@@ -0,0 +1,198 @@
1
+ module Tagz::Rails
2
+ class Renderer
3
+ class Erbout
4
+ def self.for *a, &b
5
+ new *a, &b
6
+ end
7
+ def initialize context
8
+ @context = context
9
+ end
10
+ def nil?
11
+ true
12
+ end
13
+ def method_missing m, *a, &b
14
+ @context.send m, *a, &b
15
+ end
16
+ end
17
+
18
+ class Context
19
+ include Tagz
20
+
21
+ attr_accessor "__view__"
22
+ attr_accessor "__erbout__"
23
+ attr_accessor "__eol__"
24
+
25
+ def self.create view, local_assigns
26
+ context = new
27
+ context.__view__ = view
28
+
29
+ view.assigns.merge(local_assigns).each do |k,v|
30
+ context.instance_variable_set "@#{ k }", v
31
+ end
32
+
33
+ local_assigns.each do |k,v|
34
+ context.singleton_class{ define_method(k.to_s){ v } }
35
+ end
36
+
37
+ context.instance_variable_set "@content_for_layout", view.instance_variable_get("@content_for_layout")
38
+ context
39
+ end
40
+
41
+ def self.render view, local_assigns, *argv
42
+ context = create view, local_assigns
43
+
44
+ pushing context do
45
+ source = argv.first
46
+ filename = argv.last
47
+
48
+ content_for_lookup = lambda do |*names|
49
+ name = names.shift || :layout
50
+ context.instance_variable_get "@content_for_#{ name }"
51
+ end
52
+
53
+ before_ivars = context.instance_variables
54
+
55
+ content_for_layout = context.__render__ source, filename, &content_for_lookup
56
+
57
+ after_ivars = context.instance_variables
58
+
59
+ #new_ivars = ( after_ivars - before_ivars ).delete_if{|ivar| ivar =~ %r/^@(__|content_for_)/o}
60
+ new_ivars = ( after_ivars - before_ivars ).delete_if{|ivar| ivar =~ %r/^@(__)/o}
61
+
62
+ new_ivars.each do |ivar|
63
+ key = ivar[1..-1]
64
+ value = context.instance_variable_get ivar
65
+ view.assigns[key] = value
66
+ end
67
+
68
+ content_for_layout
69
+ end
70
+ end
71
+
72
+ def self.stack
73
+ @stack ||= []
74
+ end
75
+
76
+ def self.pushing context
77
+ stack.push context
78
+ begin
79
+ yield
80
+ ensure
81
+ stack.pop
82
+ end
83
+ end
84
+
85
+ def self.depth
86
+ stack.size
87
+ end
88
+
89
+ def __render__ source, filename
90
+ tagz {
91
+ content_for_layout = eval source.to_s, binding, filename
92
+ }
93
+ end
94
+
95
+ def singleton_class &b
96
+ sc =
97
+ class << self
98
+ self
99
+ end
100
+ b ? sc.module_eval(&b) : sc
101
+ end
102
+
103
+ def method_missing m, *a, &b
104
+ case m.to_s
105
+ when %r/^(.*[^_])_(!)?$/o
106
+ m, bang = $1, $2
107
+ unless bang
108
+ __tag_start__ m, *a, &b
109
+ else
110
+ __tag_start__(m, *a){}
111
+ end
112
+ when %r/^_([^_].*)$/o
113
+ m = $1
114
+ __tag_stop__ m, *a, &b
115
+ else
116
+ __view__.send m, *a, &b
117
+ end
118
+ end
119
+
120
+ def flash *a, &b
121
+ __view__.controller.send :flash, *a, &b
122
+ end
123
+
124
+ def _erbout
125
+ self.__erbout__ ||= Erbout.for(self)
126
+ #Erbout.for self
127
+ end
128
+
129
+ def << s
130
+ __ s; nil
131
+ end
132
+
133
+ def puts *a
134
+ a.each{|elem| self << "#{ elem.to_s.chomp }#{ eol }"}
135
+ end
136
+
137
+ def p *a
138
+ a.each{|elem| self << "#{ CGI.escapeHTML elem.inspect }#{ eol }"}
139
+ end
140
+
141
+ def print *a
142
+ a.each{|elem| self << elem}
143
+ end
144
+
145
+ def eol
146
+ if __view__.controller.response.content_type =~ %r|text/plain|io
147
+ "\n"
148
+ else
149
+ "<br />"
150
+ end
151
+ end
152
+
153
+ def capture *a, &b
154
+ b.call *a
155
+ end
156
+
157
+ def content_for(name, &block)
158
+ name, ivar = "content_for_#{ name }", "@content_for_#{ name }"
159
+ value = instance_variable_get(ivar).to_s
160
+ value << capture(&block).to_s
161
+ instance_variable_set ivar, value
162
+ __view__.assigns[name] = value
163
+ nil
164
+ end
165
+
166
+ end
167
+
168
+ def initialize view
169
+ @view = view
170
+ end
171
+
172
+ def render template, local_assigns, path
173
+ (( Context.render @view, local_assigns, template, path )).to_s
174
+ end
175
+ end
176
+
177
+ def self.new *a, &b
178
+ Renderer.new *a, &b
179
+ end
180
+
181
+ #if defined? ::ActionView and defined? ::ActionView::Base
182
+ ### TODO - see if this hack can be pulled out
183
+ module ::ActionView # thanks _why !
184
+ class Base
185
+ def render_template(template_extension, template, file_path = nil, local_assigns = {})
186
+ if handler = @@template_handlers[template_extension]
187
+ template ||= read_template_file(file_path, template_extension)
188
+ handler.new(self).render(template, local_assigns, file_path)
189
+ else
190
+ compile_and_render_template(template_extension, template, file_path, local_assigns)
191
+ end
192
+ end
193
+ end
194
+ end
195
+ ::ActionView::Base.register_template_handler 'rb', Tagz::Rails
196
+ ::ActionView::Base.register_template_handler 'tagz', Tagz::Rails
197
+ #end
198
+ end
@@ -0,0 +1,182 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application and persistence framework that includes everything
4
+ needed to create database-backed web-applications according to the
5
+ Model-View-Control pattern of separation. This pattern splits the view (also
6
+ called the presentation) into "dumb" templates that are primarily responsible
7
+ for inserting pre-built data in between HTML tags. The model contains the
8
+ "smart" domain objects (such as Account, Product, Person, Post) that holds all
9
+ the business logic and knows how to persist themselves to a database. The
10
+ controller handles the incoming requests (such as Save New Account, Update
11
+ Product, Show Post) by manipulating the model and directing data to the view.
12
+
13
+ In Rails, the model is handled by what's called an object-relational mapping
14
+ layer entitled Active Record. This layer allows you to present the data from
15
+ database rows as objects and embellish these data objects with business logic
16
+ methods. You can read more about Active Record in
17
+ link:files/vendor/rails/activerecord/README.html.
18
+
19
+ The controller and view are handled by the Action Pack, which handles both
20
+ layers by its two parts: Action View and Action Controller. These two layers
21
+ are bundled in a single package due to their heavy interdependence. This is
22
+ unlike the relationship between the Active Record and Action Pack that is much
23
+ more separate. Each of these packages can be used independently outside of
24
+ Rails. You can read more about Action Pack in
25
+ link:files/vendor/rails/actionpack/README.html.
26
+
27
+
28
+ == Getting started
29
+
30
+ 1. At the command prompt, start a new rails application using the rails command
31
+ and your application name. Ex: rails myapp
32
+ (If you've downloaded rails in a complete tgz or zip, this step is already done)
33
+ 2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
34
+ 3. Go to http://localhost:3000/ and get "Welcome aboard: You’re riding the Rails!"
35
+ 4. Follow the guidelines to start developing your application
36
+
37
+
38
+ == Web Servers
39
+
40
+ By default, Rails will try to use Mongrel and lighttpd if they are installed, otherwise
41
+ Rails will use the WEBrick, the webserver that ships with Ruby. When you run script/server,
42
+ Rails will check if Mongrel exists, then lighttpd and finally fall back to WEBrick. This ensures
43
+ that you can always get up and running quickly.
44
+
45
+ Mongrel is a Ruby-based webserver with a C-component (which requires compilation) that is
46
+ suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
47
+ getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
48
+ More info at: http://mongrel.rubyforge.org
49
+
50
+ If Mongrel is not installed, Rails will look for lighttpd. It's considerably faster than
51
+ Mongrel and WEBrick and also suited for production use, but requires additional
52
+ installation and currently only works well on OS X/Unix (Windows users are encouraged
53
+ to start with Mongrel). We recommend version 1.4.11 and higher. You can download it from
54
+ http://www.lighttpd.net.
55
+
56
+ And finally, if neither Mongrel or lighttpd are installed, Rails will use the built-in Ruby
57
+ web server, WEBrick. WEBrick is a small Ruby web server suitable for development, but not
58
+ for production.
59
+
60
+ But of course its also possible to run Rails on any platform that supports FCGI.
61
+ Apache, LiteSpeed, IIS are just a few. For more information on FCGI,
62
+ please visit: http://wiki.rubyonrails.com/rails/pages/FastCGI
63
+
64
+
65
+ == Debugging Rails
66
+
67
+ Have "tail -f" commands running on the server.log and development.log. Rails will
68
+ automatically display debugging and runtime information to these files. Debugging
69
+ info will also be shown in the browser on requests from 127.0.0.1.
70
+
71
+
72
+ == Breakpoints
73
+
74
+ Breakpoint support is available through the script/breakpointer client. This
75
+ means that you can break out of execution at any point in the code, investigate
76
+ and change the model, AND then resume execution! Example:
77
+
78
+ class WeblogController < ActionController::Base
79
+ def index
80
+ @posts = Post.find(:all)
81
+ breakpoint "Breaking out from the list"
82
+ end
83
+ end
84
+
85
+ So the controller will accept the action, run the first line, then present you
86
+ with a IRB prompt in the breakpointer window. Here you can do things like:
87
+
88
+ Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint'
89
+
90
+ >> @posts.inspect
91
+ => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
92
+ #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
93
+ >> @posts.first.title = "hello from a breakpoint"
94
+ => "hello from a breakpoint"
95
+
96
+ ...and even better is that you can examine how your runtime objects actually work:
97
+
98
+ >> f = @posts.first
99
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
100
+ >> f.
101
+ Display all 152 possibilities? (y or n)
102
+
103
+ Finally, when you're ready to resume execution, you press CTRL-D
104
+
105
+
106
+ == Console
107
+
108
+ You can interact with the domain model by starting the console through <tt>script/console</tt>.
109
+ Here you'll have all parts of the application configured, just like it is when the
110
+ application is running. You can inspect domain models, change values, and save to the
111
+ database. Starting the script without arguments will launch it in the development environment.
112
+ Passing an argument will specify a different environment, like <tt>script/console production</tt>.
113
+
114
+ To reload your controllers and models after launching the console run <tt>reload!</tt>
115
+
116
+ To reload your controllers and models after launching the console run <tt>reload!</tt>
117
+
118
+
119
+
120
+ == Description of contents
121
+
122
+ app
123
+ Holds all the code that's specific to this particular application.
124
+
125
+ app/controllers
126
+ Holds controllers that should be named like weblogs_controller.rb for
127
+ automated URL mapping. All controllers should descend from ApplicationController
128
+ which itself descends from ActionController::Base.
129
+
130
+ app/models
131
+ Holds models that should be named like post.rb.
132
+ Most models will descend from ActiveRecord::Base.
133
+
134
+ app/views
135
+ Holds the template files for the view that should be named like
136
+ weblogs/index.rhtml for the WeblogsController#index action. All views use eRuby
137
+ syntax.
138
+
139
+ app/views/layouts
140
+ Holds the template files for layouts to be used with views. This models the common
141
+ header/footer method of wrapping views. In your views, define a layout using the
142
+ <tt>layout :default</tt> and create a file named default.rhtml. Inside default.rhtml,
143
+ call <% yield %> to render the view using this layout.
144
+
145
+ app/helpers
146
+ Holds view helpers that should be named like weblogs_helper.rb. These are generated
147
+ for you automatically when using script/generate for controllers. Helpers can be used to
148
+ wrap functionality for your views into methods.
149
+
150
+ config
151
+ Configuration files for the Rails environment, the routing map, the database, and other dependencies.
152
+
153
+ components
154
+ Self-contained mini-applications that can bundle together controllers, models, and views.
155
+
156
+ db
157
+ Contains the database schema in schema.rb. db/migrate contains all
158
+ the sequence of Migrations for your schema.
159
+
160
+ doc
161
+ This directory is where your application documentation will be stored when generated
162
+ using <tt>rake doc:app</tt>
163
+
164
+ lib
165
+ Application specific libraries. Basically, any kind of custom code that doesn't
166
+ belong under controllers, models, or helpers. This directory is in the load path.
167
+
168
+ public
169
+ The directory available for the web server. Contains subdirectories for images, stylesheets,
170
+ and javascripts. Also contains the dispatchers and the default HTML files. This should be
171
+ set as the DOCUMENT_ROOT of your web server.
172
+
173
+ script
174
+ Helper scripts for automation and generation.
175
+
176
+ test
177
+ Unit and functional tests along with fixtures. When using the script/generate scripts, template
178
+ test files will be generated for you and placed in this directory.
179
+
180
+ vendor
181
+ External libraries that the application depends on. Also includes the plugins subdirectory.
182
+ This directory is in the load path.
@@ -0,0 +1,10 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
5
+
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+
10
+ require 'tasks/rails'
@@ -0,0 +1,7 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ # Pick a unique cookie name to distinguish our session data from others'
6
+ session :session_key => '_rails_session_id'
7
+ end
@@ -0,0 +1,51 @@
1
+ class TagzController < ApplicationController
2
+ include Tagz
3
+ helper{ include Tagz }
4
+
5
+ ### menu
6
+ def index
7
+ menu = %w( a b c d e ).map{|action| "<br><a href='#{ action }'>#{ action }</a>"}
8
+ render :text => "<html> <body> #{ menu } </body> </html>"
9
+ end
10
+
11
+ ### setup a little data
12
+ def initialize
13
+ @title = 'tagz!'
14
+ @list = %w( a b c )
15
+ end
16
+
17
+ ### just using tagz inline
18
+ def a
19
+ text = tagz {
20
+ html_{
21
+ head_{ title_{ @title } }
22
+
23
+ body_{
24
+ ul_{ @list.each{|elem| li_{ elem } } }
25
+ }
26
+ }
27
+ }
28
+
29
+ render :text => text
30
+ end
31
+
32
+ ### using a simple template : app/views/tagz/b.rb
33
+ def b
34
+ render
35
+ end
36
+
37
+ ### using content_for : app/views/layouts/layout.rb app/views/tagz/c.rb
38
+ def c
39
+ render :layout => 'layout'
40
+ end
41
+
42
+ ### mixing erb and tagz
43
+ def d
44
+ render
45
+ end
46
+
47
+ ### rendering fubar content see app/views/tagz/e.rb
48
+ def e
49
+ render
50
+ end
51
+ end