Re: First time on Camping

2010-06-17 Thread Magnus Holm
Hey Raimon,

I see that you've been experimenting with Camping and Reststop lately,
and just thought I should chime in a bit.

You definitely don't *need* Reststop in order to achieve what you
want, so it might be a good idea to just leave Reststop until it gets
a little more robust. Let's see how we can tackle your problem with
Camping only:

For serving XML, you can use Builder (http://builder.rubyforge.org/).
Here's a little helper for you:

require 'camping'
require 'builder'

Camping.goes :App

module App
  # We include the Views module so we can call them as methods.
  include Views

  module Helpers
def xml(name)
  # We'll need to send this as text/xml
  @headers[Content-Type] = text/xml
  result = String.new
  # The builder takes a `target` where the XML will end up
  builder = Builder::XmlMarkup.new(:target = result, :indent = 2)
  # Generates a ?xml version=1.0 encoding=UTF-8 ?
  builder.instruct!
  # Calls the method you sent in, passing in the builder as an argument
  send(name, builder)
  # Return the restult
  result
end
  end
end



If you for instance want to generate this XML:

posts
  post title=Post titleContent of post/post
/posts

You would have the following view:

module App::Views
  def posts(xml)
xml.posts do
  @posts.each do |post|
xml.post(post.content, :title = post.title)
  end
end
  end
end

And if you want this XML:

?xml version=1.0 encoding=UTF-8?
posts
  post
titleHiya/title
contentHey/content
  /post
/posts

You have this view:

module App::Views
  def posts(xml)
xml.posts do
  @posts.each do |post|
xml.post do
  xml.title(post.title)
  xml.content(post.content)
end
  end
end
  end
end

-

You render the XML in the controller like this:

module App::Controllers
  class Index
def get
  # The view has access to this variable
  @posts = Post.all
  # Calls the helper, which in turn calls the view
  xml :posts
end
  end
end



That's (hopefully) the simplest way to generate XML with Camping.

You still need to create a model to store/retrieve the data. Before we
can help you here, we need to know a few things: Is it going to fetch
data from a specific place, or should it create its own database (from
scratch)? Any specific database you want to use?

Here's a Pastie with all the code: http://pastie.org/1008983 (Should
work on any version of Camping).

// Magnus Holm



On Tue, Jun 8, 2010 at 08:25, Raimon Fernandez co...@montx.com wrote:
 hi list,


 This is my first time here, my first time reading seriously something about 
 Camping.

 I need to create a very simple web server for serving only .xml files, 
 extracted from a sqlite database with some queries.

 I'm quite comfortable with Ruby on Rails, but it would be too much for this 
 project, so I've decided to take a look at Camping or Sinatra, not sure 
 what's the best option.

 There would be only 5 tables, 100 rows per table, and the idea is fetch data 
 from a device like iPad/iPhone/iPod, update it and persist the changes in the 
 server. The data transfer would be in plain .xml files, no html or css.

 Any helpful directions would be great

 :-)

 thanks,

 r.
 ___
 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


Re: First time on Camping

2010-06-17 Thread Matt Zukowski
Something's not right with your rubygems install maybe try `gem update
--system` first?

On Tue, Jun 8, 2010 at 3:33 PM, Raimon Fernandez co...@montx.com wrote:


 On 8jun, 2010, at 21:18 , David Susco wrote:

  Is the hoe gem installed?

 no, the same error as before:

 Last login: Tue Jun  8 18:43:33 on ttys002
 MacBook-ProII-2:~ montx$ sudo gem install hoe
 Password:
 ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
SocketError: getaddrinfo: nodename nor servname provided, or not known (
 http://gems.rubyforge.org/gems/json_pure-1.4.3.gem)
 MacBook-ProII-2:~ montx$


 we have to wait ...

 thanks,

 r.

 
  Dave
 
  On Tue, Jun 8, 2010 at 1:01 PM, Raimon Fernandez co...@montx.com
 wrote:
 
  On 8jun, 2010, at 18:43 , David Susco wrote:
 
  I don't believe the gem has been updated to include Matt's or
  Philippe's latest changes. You could clone it from GitHub though and
  rake and install it yourself.
 
  I think it requieres 'hoe' and I can't install without rubygems working
 or once again, find where the repo is and start digging again ...
 
  :-)
 
  MacBook-ProII-2:reststop montx$ sudo rake Rakefile
  (in /Users/montx/Documents/Camping/reststop)
  rake aborted!
  no such file to load -- hoe
  /Users/montx/Documents/Camping/reststop/rakefile:10
 
 
  thanks!
 
  r.
  ___
  Camping-list mailing list
  Camping-list@rubyforge.org
  http://rubyforge.org/mailman/listinfo/camping-list
 
 
 
 
  --
  Dave
  ___
  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

___
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list