Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Checking a View Exists
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
DAZ  
View profile  
 More options Mar 4 2011, 11:35 am
From: DAZ <daz4...@gmail.com>
Date: Fri, 4 Mar 2011 08:35:31 -0800 (PST)
Local: Fri, Mar 4 2011 11:35 am
Subject: Checking a View Exists
Is it possible to have check if a view exists?

For example

get '/foo' do
  haml :foo IF there is a foo view,
  else just display haml :generic
end

cheers,

DAZ


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
djangst  
View profile  
 More options Mar 4 2011, 2:35 pm
From: djangst <djan...@gmail.com>
Date: Fri, 4 Mar 2011 11:35:29 -0800 (PST)
Local: Fri, Mar 4 2011 2:35 pm
Subject: Re: Checking a View Exists
If there's no built-in way to accomplish this, you could always try to
load the view from the local file system using standard Ruby
(File.exist?, for example).

On Mar 4, 11:35 am, DAZ <daz4...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Francisco Cabrita  
View profile  
 More options Mar 4 2011, 8:36 pm
From: Francisco Cabrita <francisco.cabr...@gmail.com>
Date: Sat, 5 Mar 2011 01:36:50 +0000
Local: Fri, Mar 4 2011 8:36 pm
Subject: Re: Checking a View Exists

Hi DAZ,

On Fri, Mar 4, 2011 at 4:35 PM, DAZ <daz4...@gmail.com> wrote:
> Is it possible to have check if a view exists?

> For example

> get '/foo' do
>  haml :foo IF there is a foo view,
>  else just display haml :generic
> end

Interesting question but, sorry, I can't see how and why I need use this.
Lights please :)

> cheers,

> DAZ

> --
> You received this message because you are subscribed to the Google Groups
> "sinatrarb" group.
> To post to this group, send email to sinatrarb@googlegroups.com.
> To unsubscribe from this group, send email to
> sinatrarb+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sinatrarb?hl=en.

--
--

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Konstantin Haase  
View profile  
 More options Mar 5 2011, 3:49 am
From: Konstantin Haase <k.ha...@finn.de>
Date: Sat, 5 Mar 2011 09:49:27 +0100
Local: Sat, Mar 5 2011 3:49 am
Subject: Re: Checking a View Exists
If you're on Sinatra 1.2, try something like this:

        helpers do
                def find_template(views, name, engine, &block)
                        super(views, name, engine, &block)  # will try to render :foo
                        super(views, :generic, engine, &block)      # if that is missing, try :generic
                end
        end

        get '/foo' do
                haml :foo
        end

Note that this will use :generic for all templates. You can of course check the value of name and engine.
If you use that with a lot of different fallback templates, try something like this:

        helpers do
                def template_exists?(engine, name)
                        find_template(settings.views, name, Tilt[engine]) do |file|
                                return true if File.exist? file
                        end
                        false
                end
        end

        get '/foo' do
                if template_exists? :haml, :foo
                        haml :foo
                else
                        haml :generic
                end
        end

Konstantin

On Mar 4, 2011, at 17:35 , DAZ wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Zachary Scott  
View profile  
 More options Mar 5 2011, 9:00 am
From: Zachary Scott <zachary.s.sc...@gmail.com>
Date: Sat, 5 Mar 2011 09:00:58 -0500
Local: Sat, Mar 5 2011 9:00 am
Subject: Re: Checking a View Exists
Excellent solution Konstantin, thanks for sharing!

This should go in contrib imo :)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
DAZ  
View profile  
 More options Mar 6 2011, 3:23 pm
From: DAZ <daz4...@gmail.com>
Date: Sun, 6 Mar 2011 12:23:19 -0800 (PST)
Local: Sun, Mar 6 2011 3:23 pm
Subject: Re: Checking a View Exists
Thanks for the info guys ... and the solution Konstantin (I always
find just looking at your code examples helps me immensley!)

Here is what I'm trying to do (to answer Francisco's question and
hopefully make things clearer):

    set :pages, %w[about download contact]

    settings.pages.each do |page|
      get '/'+page do
        @title = page.capitalize
        #CODE NEEDS TO GO HERE
      end
    end

    __END__
    @@about
    Howdy!
    ========
    Welcome to the home page

    @@page
    h1= @title
    p This is the #{@title} page.

Basically, you put your page names in the array, then it generates
some urls for you. The idea is to then create some simple pages using
markdown, but if they haven't been created yet, then the generic page
view is shown using slim.

I'll give Konstantin's code a try and get back to you all.

cheers,

DAZ

On Mar 5, 2:00 pm, Zachary Scott <zachary.s.sc...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »