Code Review: Cleanup of examples + Rackification
Hey guys, I had some unfinished stuff in my working directory which I've now pushed out to the rackification-branch at my fork. Even though I have push-permissions to why's repo, I still like the idea that we should all decide which ways Camping should go, and this includes quite a bit of code: == Cleanup of blog.rb http://github.com/judofyr/camping/commit/957c907cc925ab8c58ddff94f4bc6ddd27f7285f Just making it simpler and not so magically. == Removal of tepee.rb and campsh.rb http://github.com/judofyr/camping/commit/3c87b0a6f028bb315ddb2196a1f09d5ba640b865 Currently these are not working 100% correctly so until we clean these up, I think it's a good idea to remove them to avoid confusion. They're still hidden in Git's history, so it's more like hiding them than removing them. == Add Camping.use http://github.com/judofyr/camping/commit/0d21c240963226bb40038de3fe0f111928889215 This allows the user to inject middlewares so they become a part of the app: module App use Somemiddleware, 123, 456 # Equals to adding Somemiddleware.new(App, 123, 456) on the "outside". use Stackable, :yes => "they are" end == Session refactoring http://github.com/judofyr/camping/commit/332e0a190a6bbf1af7e8d7812ec3f816727efc38 Okay, this is larger one: Now that we can inject middleware, we can make Camping::Session simply "use Rack::Session::Cookie". This means a smaller Camping (lib/camping that is, not camping.rb) and less code to maintain. I've also added a "secret" method to change the secret key (the name may be a little too generic though): module App include Camping::Session secret "Hello!" end However, in order to use Rack::Session::Cookie I had to change some internal stuff. First of all, @env is now the Hash passed into #call (earlier this was a Camping::h...@env]). This is because all the rack.session stuff require changing the originial @env in order to save sessions. @state is also now set in Base#initialize and is always based on rack.session. This means that any middleware who sets env['rack.session'] to some Hash will make Camping pick it up and put it in @state. In Base#to_a (which is used to finialize stuff) there's a simple "@env['rack.session'] = @state" to save the sessions. I've also removed Camping::ARSession, since I didn't feel like rewriting it as a Rack middleware. Please call out if it's missed. == Simplify things that Rack gives us for free http://github.com/judofyr/camping/commit/a7cff36813b899b48fe0d196d2ea54bd7377e6e5 Rack now parses nested params and we can now safely assume SCRIPT_NAME and REQUEST_METHOD to be set thanks to the Rack spec. Saves us some bytes. camping.rb is at 2999 bytes after these patches. -- So what do you think? Any obvious things I'm missing? Yeah, I know I've probably broken some backward compatibility, but remember that 1.9 is after all a preview release, and 2.0 *is* a major update. Have a look and don't be afraid to call out the stupid parts :-) //Magnus Holm (who now has no excuse for not starting on the docs) ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: The D-word
hiya chiming in a little late. but i think many people would be attracted to a basic cms, as often as it's been done. possibly without all the role and permissions fuss but a basic page hierarchy and editable pages so people can make their scrap books, photo albums and so on. make it very basic, and explain it well, and then every other month it can be expanded on, add an ajax sprinkle, add a permissions/group role what have you. must have's. 1. db access, how to setup, run etc. 2. illustrate various types of relationships, hierarchical would be nice to show :-) 3. file upload and management, file delete on record delete etc. 4. login / logout for the basic admin user then every other month or when someone adds a feature (eg, ajax rich text editing, user and group roles) or mutates it for a specific purpose (photo album, address book) we can make a tutorial out of it. Using our basic cms structure... i'd be glad to contribute some of the writing and such, i'm quite fluent in english and my grammar is a lot more robust than my emails would lead you to believe. i'd need help with the coding though, since i'm new to ruby and camping and i've honestly been sort of following along from the side lines. it's a hobby but one i'd be willing to invest time on if the community is interested. just my 2cents best cornelius On 09.06.2009, at 23:56, Magnus Holm wrote: Oh, that would be very nice! Right now there is an example at camping.rubyforge.org showing a blog skeleton (with controllers, models and views). It might be better to rather have a tiny, fully functional one (to get the feel of Camping), and a link to blog.rb (which should be simplified even more, and actually work). The book could then take it from there and slightly expand into the blog.rb (or maybe even totally different; we should at least end up with something) You know, I remember stumbling on Camping after trying out Rails, and it was a horrible feeling ending up at page 3 of the tutorial (on the old wiki) where a giant "TODO" screamed at me. I think many newcomers would have a look at alternatives to Rails, and it would be great if we could guide them not only through Camping, but also on the way you have to think when you're developing on the web. Without boring them too much. At the same time, there will probably be some Rubyists/webdevs who just want to learn about Camping too. What if we start easy with lots of code and introduce them to Camping, then (if we bother to) more in-depth about the web, HTTP, GET/POST/PUT/DELETE, limitations? You could follow the book right through and will end up with basic understanding of the web, or just skip after the quickstart (and three months later, after you've experimented a bit, you take the trouble to trouble to read the rest). Maybe "book" is the wrong word for this too. A book is so formal and strict. This should be light, simple and something you just can dive right into whenever you want. Let's keep it simple and precise, yet informal! The API as a cheat is a great idea too, let's not forget that :-) When it comes to the dependency on Rack, I'm not that worried. You almost can't do any webdev in Ruby today without meeting on Rack. And you only need to have the Rack-library somewhere where Camping can find it (just download and unzip it to vendor/rack for instance), even though using the gem is preferred. Anyone else want to chime in? (Yes, you do!) I currently have some RDoc templates which renders the book/readme/ api. It definitely needs to be cleaned up a lot, but I guess I can push it out at a branch when I get back to my computer. //Magnus Holm ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: Camping tutorials for education?
On Thu, Jun 11, 2009 at 10:44:30AM -0400, David Susco wrote: @Jonathan - Re: your apache conf, I actually didn't need the directory directive and the execcgi option to get this to work. Why did you list it? You don't need the execcgi, and the reason I give the directory directive is to set the permissions to allow, deny just for that directory (by default all my permissions are set to deny,allow for extra security). So skip the section if you don't need it. 3. Look into performance and security. Would installing fastcgi or something similar speed passenger up any? Fastcgi, which creates persistent ruby backend processes does a similar thing to passenger. It only makes sense to my mind to have one thing managing your ruby processes. Cheers, Jonathan. ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: sqlite3 connection problem
On Tue, Jun 09, 2009 at 11:35:26AM +0100, Dave Everitt wrote: Any feedback appreciated on the following. My most recent attempt to identify the issue is a minimal Ruby/SQLite/ActiveRecord script, Pastied here: http://pastie.textmate.org/492514 which brings up the following when run from the command line (an empty database file already exists): $ ./simple_db.rbx [SNIP]/active_record/connection_adapters/sqlite3_adapter.rb:29:in `table_structure': Could not find table 'users' (1) Not really a 'camping' related pastie. See (3) for the same thing done the 'camping way'. (2) There seems to be nothing in the code above telling activerecord to create your database schema unless you're doing seperate rake db:migrate scripts outside of this script. My suspicion, therefore is that the 'users' table simply does not exist in your database. (3) This is a full working solution for camping 1.5: #!/usr/bin/env ruby $:.unshift File.dirname(__FILE__) + "/../../lib" require 'camping' Camping.goes :Dave module Dave::Models class User < Base end class CreateTables < V 1.0 def self.up create_table :dave_users, :force => true do |t| t.column :id, :integer, :null => false t.column :name, :string, :limit => 255 t.column :password, :string, :limit => 255 end def self.down drop_table :dave_users end end end end module Dave::Controllers class Index < R '/' def get user = User.new() user.id = "dave" user.name = "Dave Everitt" user.password = "davepass" user.save # user = User.find("dave") # user.destroy() render :fin end end end module Dave::Views def fin "Finished, no errors" end end def Dave.create Dave::Models.create_schema :assume => (Dave::Models::User.table_exists? ? 1.0 : 0.0) end *** Save this file as dave.rb. Note the Dave::Models.create_schema call (as per point 2 above) To get this to work I have the following gems installed: $ gem list *** LOCAL GEMS *** activerecord (2.3.2) activesupport (2.3.2) builder (2.1.2) camping (1.5.180) markaby (0.5) metaid (1.0) sqlite3-ruby (1.2.4) I run it with: camping dave.rb I then visited http://localhost:3301/ with my browser (which showed "Finished, no errors"). To confirm that there is a table in the sqlite database with the correct fields and with one record: $ sqlite3 ~/.camping.db SQLite version 3.6.10 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> .tables dave_schema_infos dave_users sessions sqlite> .header on sqlite> select * from dave_users; id|name|password 0|Dave Everitt|davepass Hope some of the above points you in the 'right' direction. Cheers, Jonathan. ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: Camping tutorials for education?
Scratch that, got everything working with 1.8.7-p173 and selinux disabled. I have to say, rack apps are pretty easy to deploy with passenger once you get the thing installed and working :P. @Jonathan - Re: your apache conf, I actually didn't need the directory directive and the execcgi option to get this to work. Why did you list it? So here's my TODO list: 1. Try to get it working with selinux enabled. 2. Put together a tutorial for the wiki (which one would you guys like to see it on? github?) 3. Look into performance and security. Would installing fastcgi or something similar speed passenger up any? On Wed, Jun 10, 2009 at 8:45 PM, David Susco wrote: > OK, good to know. What the latest version I can use? > > Dave > > On Wed, Jun 10, 2009 at 5:46 PM, Magnus Holm wrote: >> Unfornately, Camping doesn't (yet) work on Ruby 1.9.1. Unless someone else want to try >> now, I'm going to have a look at it *after* 2.0 is released. >> >> //Magnus Holm >> >> >> On Wed, Jun 10, 2009 at 22:30, David Susco wrote: >>> >>> I've disabled SELinux to see if I could get any farther. >>> >>> I managed to get passenger installed and working, however a fancy >>> passenger generated page is telling me the app couldn't be started due >>> to this error: >>> >>> `require': >>> /usr/local/lib/ruby/gems/1.9.1/gems/camping-1.9.316/lib/camping.rb:11: >>> syntax error, unexpected tLABEL (SyntaxError) >>> p[0]==?/?...@root+p:p end;def URL c='/',*a;c=R(c,... >>> >>> It's the same thing when I try to rackup the .ru file, and the same >>> when I try to execute this little bit of code: >>> >>> #!/usr/bin/env ruby -rubygems >>> gem 'camping', '>=1.9.316' >>> %w(rack camping).each { |lib| require lib } >>> puts 'done' >>> >>> I'm tried reinstalled camping 1.9.316 but that didn't change anything. >>> Any ideas? >>> >>> Dave >>> >>> On Wed, Jun 10, 2009 at 10:39 AM, David Susco wrote: >>> > I'm trying to get passenger working presently, once I do I'll let you >>> > know how the rest of it goes. >>> > >>> > When I try to load the module in the apache conf I get the following >>> > error: >>> > >>> > Cannot load >>> > /usr/lib/ruby/gems/1.8/gems/passenger-2.2.2/ext/apache2/mod_passenger.so >>> > into server: >>> > /usr/lib/ruby/gems/1.8/gems/passenger-2.2.2/ext/apache2/mod_passenger.so: >>> > failed to map segment from shared object: Permission denied >>> > >>> > I'm assuming it's an SELinux problem, has anyone run into it before? >>> > I've done the following already, so it hasn't helped: >>> > >>> > http://www.modrails.com/documentation/Users%20guide.html#_the_apache_error_log_says_that_the_spawn_manager_script_does_not_exist_or_that_it_does_not_have_permission_to_execute_it >>> > >>> > Dave >>> > >>> > >>> > On Tue, Jun 9, 2009 at 11:28 AM, Jonathan Groll >>> > wrote: >>> >> Hi David, >>> >> >>> >> On Tue, Jun 09, 2009 at 09:29:22AM -0400, David Susco wrote: >>> >>> >>> >>> I'd definitely be interested in seeing any work you do with this. >>> >>> Having it up on the wiki would be nice too. >>> >>> >>> >>> I'm still trying to figure out deployment with camping 1.5. I've >>> >>> experimented with 1.9.316 and rack but have yet to get an app to work >>> >>> with that. The same with Picnic. >>> >> >>> >> Been meaning to write a quick overview of how I did it for you (as >>> >> documentation is super sparse still). Briefly: >>> >> >>> >> (1) Read the passenger user guide at: >>> >> http://www.modrails.com/documentation/Users%20guide.html >>> >> >>> >> I installed passenger from a gem but see the user's guide if you need >>> >> to install on debian using apt (it is in the Ubuntu repositories >>> >> already). >>> >> Similarly rack is from a gem, and I use the same version of camping as >>> >> you (from Judofyr's gem server). >>> >> >>> >> (2) Try and get the "hello world" from the passenger user guide to >>> >> work for you. >>> >> >>> >> (3) Then try and get the blog example working that is shipped with >>> >> camping. Here is a config.ru that works for that: >>> >> >>> >> require 'rubygems' >>> >> require 'rack' >>> >> require 'camping' >>> >> require 'blog' >>> >> Blog::Models::Base.establish_connection :adapter => "sqlite3", >>> >> :database => "/home/jonathan/.camping.db" >>> >> run Blog >>> >> >>> >> Change the database path to one you have on your system. You may need >>> >> something like: >>> >> Blog::Models.create_schema :assume => (Blog::Models::Post.table_exists? >>> >> ? >>> >> 1.0 : 0.0) >>> >> >>> >> before "run blog" if your sqlite database doesn't yet have the schema >>> >> for the blog example. >>> >> >>> >> (4) And the apache config that I used was something like: >>> >> >>> >> >>> >> Options ExecCGI FollowSymLinks >>> >> AllowOverride all >>> >> Allow from all >>> >> >>> >> >>> >> ServerName www.rackexample.com >>> >> DocumentRoot /var/www/blog/public >>> >> >>> >> >>> >> You may need to edit your hosts file so that www.rackexample.com >>> >> resolves to your apache serve
Re: Camping tutorials for education?
On 11 Jun 2009, at 02:45, David Susco wrote: OK, good to know. What the latest version I can use? Well if Magnus has indeed released 1.5.180 then this is the latest baseline stable. I am running it on many apps and it works pretty OK with most irritating bugs (like R not working properly for additiona option hashes) weeded out. If you are into experiments, you can try 2.0 but I never tried it out in earnest. If you want to issue good reading materials to students you will possibly have to write them yourself, must be doable in a day. -- Julik Tarkhanov m...@julik.nl ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: Release?
Awesome. On 11 Jun 2009, at 15:16, Magnus Holm wrote: Totally right :-) It's released now... //Magnus Holm On Thu, Jun 11, 2009 at 01:12, Julik Tarkhanov > wrote: On 10 Jun 2009, at 23:49, Magnus Holm wrote: Oh, sorry. I totally forgot about this. Are we absolutely sure that 1.5.180 is stable enough to be pushed out to Rubyforge? For about a year I think, and if not it can be followed by 1.5.181 right? -- Julik Tarkhanov m...@julik.nl ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list -- Julik Tarkhanov m...@julik.nl ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: Release?
Totally right :-) It's released now... //Magnus Holm On Thu, Jun 11, 2009 at 01:12, Julik Tarkhanov wrote: > > On 10 Jun 2009, at 23:49, Magnus Holm wrote: > > Oh, sorry. I totally forgot about this. >> >> Are we absolutely sure that 1.5.180 is stable enough to be pushed out to >> Rubyforge? >> > > > For about a year I think, and if not it can be followed by 1.5.181 right? > -- > Julik Tarkhanov > m...@julik.nl > > > > > > ___ > Camping-list mailing list > Camping-list@rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list