Automated page building

Dear All,

I started using Radiant and appreciate much its elegant interface. As
a user I find it easy to use the Radiant interface for creating
new pages and developing complex webpages with minimal effort.
I wonder if there is a way to create certain pages automatically
using some kind of script.

The situation is that we have weekly updates to our climate monitoring
webpage. For this, about 50 images have to be uploaded to the site
and the corresponding pages built every week. Wonder if Radiant could be
provided instructions to do this using a script than a person sitting
and typing it all in.

Thanks for any pointers,
saji

Saji N. Hameed

APEC Climate Center +82 51 668 7470
National Pension Corporation Busan Building 12F
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 [email protected]
KOREA

You could write a Ruby script that you invoke with script/runner, or
better yet, a Rake task. It will require some knowledge of the inner
workings of Radiant (at least how the models interact).
Alternatively, if you’re not comfortable with using the shell,
Capistrano could help you automate this, especially if the images are
local and not from external service.

Sean

require ‘config/environment’

parent = Page.find_by_url(’/path/to/parent’)

50.times do {|i|
child = Page.new
child.parent = parent
child.title = “Page #{i}”
child.breadcrumb = “Page #{i}”
child.slug = “page-#{i}”
body = PagePart.new
body.content = “This is page #{i}”
child.parts = body
child.save!
}

Dear Sean,
Thank you for the tips. I am comfortable with writing shell or
Ruby scripts for this task, but have no idea of the inner workings of
Radiant. I have briefly looked at the Capistrano manuals and it
is a possible tool for my purpose.
If there is an example showing how to use scripting (ruby/bash) for
this kind of job, I would be grateful to learn from it.

Thanks,
saji

Dear All,
provided instructions to do this using a script than a person sitting
KOREA
Site: http://lists.radiantcms.org/mailman/listinfo/radiant

Saji N. Hameed

APEC Climate Center +82 51 668 7470
National Pension Corporation Busan Building 12F
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 [email protected]
KOREA

Hi Daniel,
Thanks very much. I ran the following code (included inside a file
test.rb)

Start of code

parent = Page.find_by_url(/articles/)

i=1
child = Page.new
child.parent = parent
child.title = “Page #{i}”
child.breadcrumb = “Page #{i}”
child.slug = “page-#{i}”
body = PagePart.new
body.content = “This is page #{i}”
child.parts = body
child.save!

End of code

And then went to root of my application and ran:

“script/runner -e production test.rb”

Unfortunately I got the following error messages. Any further tips
would be greatly appreciated.

saji

/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/railties/lib/commands/runner.rb:45:
undefined method `strip’ for /articles/:Regexp (NoMethodError)

    from 

/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/app/models/page.rb:129:in
`find_by_url’

    from 

/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/app/models/page.rb:151:in
`find_by_url’

    from (eval):3
    from 

/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in eval' from /usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/railties/lib/commands/runner.rb:45 from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require’
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from script/runner:3

body = PagePart.new

To: [email protected]
Thanks,
images are

new pages and developing complex webpages with minimal effort.
and typing it all in.
[email protected]
Search: http://radiantcms.org/mailing-list/search/


Radiant mailing list
Post: [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site: http://lists.radiantcms.org/mailman/listinfo/radiant


Radiant mailing list
Post: [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site: http://lists.radiantcms.org/mailman/listinfo/radiant


Saji N. Hameed

APEC Climate Center +82 51 668 7470
National Pension Corporation Busan Building 12F
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 [email protected]
KOREA

Saji,

Make sure to put quotes around that URL. It should be a string, not a
regex.

parent = Page.find_by_url("/articles/")

Sean

Subject: Re: [Radiant] automated page building

Very funny Daniel ;).

Sean

Funny? That code is pretty much verbatim from a script I have to
generate a bunch of pages for benchmarking find_by_url.

Dan.

Very funny Daniel ;).

Sean

Well, I thought it was funny. Don’t mind the crazy person! (me)

Sean

child.parts should be an array

Sean,

Thanks…

With the URL now enclosed by quotes, I get the following error …hmmm.
what could i be doing wrong?

saji

Start of Ruby code

#require ‘config/environment’ ! i commented this out

parent = Page.find_by_url(“/articles/”)

i=1
child = Page.new
child.parent = parent
child.title = “Page #{i}”
child.breadcrumb = “Page #{i}”
child.slug = “page-#{i}”
body = PagePart.new
body.content = “This is page #{i}”
child.parts = body
child.save!

End of Ruby code

START OF ERROR MESSAGE

(/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/railties/lib/commands/runner.rb:45:
undefined method each' for #<PagePart:0xb765b49c> (NoMethodError) from /usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:137:in replace’
from
/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/activerecord/lib/active_record/associations.rb:950:in
parts=' from (eval):13 from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in eval’
from
/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/railties/lib/commands/runner.rb:45
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require’
from script/runner:3

END OF ERROR MESSAGE

Thanks very much. I ran the following code (included inside a file test.rb)
body = PagePart.new
would be greatly appreciated.
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `eval’

parent = Page.find_by_url(‘/path/to/parent’)
child.save!

Dear Sean,

Sean

saji
Radiant mailing list

Search: http://radiantcms.org/mailing-list/search/


Radiant mailing list
Post: [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site: http://lists.radiantcms.org/mailman/listinfo/radiant


Saji N. Hameed

APEC Climate Center +82 51 668 7470
National Pension Corporation Busan Building 12F
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 [email protected]
KOREA

Dear Dan,

Thanks very much. I put child.parts as an array.
child.parts = [ body ]

Now the error is while
saving.

   child.save!

Here is the error message. Do I need to enter pass on
login and password information through the script? If so how may i do
that. Or what else could be the source of the error?

Thanks much for your patience and kind help.

saji

/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/railties/lib/commands/runner.rb:45:
/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/activerecord/lib/active_record/validations.rb:764:in
save_without_transactions!': Validation failed: Parts is invalid (ActiveRecord::RecordInvalid) from /usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/activerecord/lib/active_record/transactions.rb:133:in save!’
from
/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in
transaction' from /usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/activerecord/lib/active_record/transactions.rb:95:in transaction’
from
/usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/activerecord/lib/active_record/transactions.rb:121:in
transaction' from /usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/activerecord/lib/active_record/transactions.rb:133:in save!’
from (eval):16
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in eval' from /usr/lib/ruby/gems/1.8/gems/radiant-0.6.1/vendor/rails/railties/lib/commands/runner.rb:45 from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in gem_original_require’
from
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from script/runner:3

Sean,
#require ‘config/environment’ ! i commented this out
body.content = “This is page #{i}”
child.parts = body
child.save!


Radiant mailing list
Post: [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site: http://lists.radiantcms.org/mailman/listinfo/radiant


Saji N. Hameed

APEC Climate Center +82 51 668 7470
National Pension Corporation Busan Building 12F
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 [email protected]
KOREA

On May 16, 2007, at 5:16 AM, Francesco L. wrote:


I think it should be child.parts << body

I prefer the following, as it gives me the necessary associations of
things to one another. Perhaps the other code is failing as it is
missing the part name of “body”?


require ‘config/environment’

parent = Page.find_by_url(’/request’)

50.times do |i|
child = parent.children.build(
:title => “Page #{i}”,
:breadcrumb => “Page #{i}”,
:slug => “page-#{i}”)
child.parts.build(
:content => “This is page #{i}”,
:name => “body”)
child.save!
end

Saji Njarackalazhikam H. ha scritto:


I think it should be child.parts << body

ciao


Francesco L.
Ymir s.r.l.
Viale Verona 190/11
38100 Trento

Thank you, this works… thanks to all who helped.
best wishes,
saji

require ‘config/environment’
:name => “body”)
child.save!
end


Radiant mailing list
Post: [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site: http://lists.radiantcms.org/mailman/listinfo/radiant


Saji N. Hameed

APEC Climate Center +82 51 668 7470
National Pension Corporation Busan Building 12F
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705 [email protected]
KOREA

+1 for model.association_name.build

Sean