librelist archives

« back to archive

Code outside the Shoes.app

Code outside the Shoes.app

From:
Filemon Salas
Date:
2012-01-08 @ 13:55
Hi,

I have been try new things with Shoes and I'm impressed about how easy
it is, thats awesome!

Originally I thought that all code needed to be within the Shoes.app
but apparently not.  After looking at the manual I noticed some
examples have code outside the Shoes application.

Why would you add code outside the Shoes app?
 filename = ask_open_file
 Shoes.app do
   para File.read(filename)
 end

Why not keep everything inside?

 Shoes.app do
 filename = ask_open_file
   para File.read(filename)
 end


Can someone explain why code can live outside the Shoes.app?

Sorry if my question doesn't make a lot of sense.

Re: [shoes] Code outside the Shoes.app

From:
J. Kaiden
Date:
2012-01-08 @ 14:14
hi Fily,

  one reason to have code outside the main app might be to keep the size
and readability of the main app reasonable if it uses lots of custom
widgets.  all of the widgets can be written separately, and then called
from within the app.

  imagine you're writing an audio player app (as i happen to be ;) ) that
has a main ui, a directory browser, and a playlist.  the code for each of
these elements would most likely be pretty lengthy, and if you wrote each
of them from within the main app, you'd end up scrolling through miles of
code to find your widgets - it would become very easy to get lost, as well
as nearly impossible for anyone else to figure out your code.  if you wrote
each element as a seperate widget/file, you could keep things nice and
orderly...

  check out this link on writing widgets:
https://github.com/lljk/shoes-stuff/wiki/Shoes-Widgets


hth,

Shoes On!

  - j




On Sun, Jan 8, 2012 at 2:55 PM, Filemon Salas <fs.dolphin@gmail.com> wrote:

> Hi,
>
> I have been try new things with Shoes and I'm impressed about how easy
> it is, thats awesome!
>
> Originally I thought that all code needed to be within the Shoes.app
> but apparently not.  After looking at the manual I noticed some
> examples have code outside the Shoes application.
>
> Why would you add code outside the Shoes app?
>  filename = ask_open_file
>  Shoes.app do
>   para File.read(filename)
>  end
>
> Why not keep everything inside?
>
>  Shoes.app do
>  filename = ask_open_file
>   para File.read(filename)
>  end
>
>
> Can someone explain why code can live outside the Shoes.app?
>
> Sorry if my question doesn't make a lot of sense.
>

Re: [shoes] Code outside the Shoes.app

From:
Filemon Salas
Date:
2012-01-08 @ 14:53
Make sense, thanks a lot for your reply.

The reason for the question is because I originally thought the
interpreter inside Shoes was only going to compile code within the
Shoes.app and ignore or stop functioning if code was found outside the
app but apparently it compiles any Ruby code found outside.

To have a better understanding let me ask this last question...

Only Ruby code can live outside Shoes.app, right?  In other words any
classes or methods from the Shoes.app must be inside right?

Thanks a lot for the clarification

On Sun, Jan 8, 2012 at 8:14 AM, J. Kaiden <jakekaiden@gmail.com> wrote:
> hi Fily,
>
>   one reason to have code outside the main app might be to keep the size and
> readability of the main app reasonable if it uses lots of custom widgets.
>  all of the widgets can be written separately, and then called from within
> the app.
>
>   imagine you're writing an audio player app (as i happen to be ;) ) that
> has a main ui, a directory browser, and a playlist.  the code for each of
> these elements would most likely be pretty lengthy, and if you wrote each of
> them from within the main app, you'd end up scrolling through miles of code
> to find your widgets - it would become very easy to get lost, as well as
> nearly impossible for anyone else to figure out your code.  if you wrote
> each element as a seperate widget/file, you could keep things nice and
> orderly...
>
>   check out this link on writing
> widgets: https://github.com/lljk/shoes-stuff/wiki/Shoes-Widgets
>
>
> hth,
>
> Shoes On!
>
>   - j
>
>
>
>
> On Sun, Jan 8, 2012 at 2:55 PM, Filemon Salas <fs.dolphin@gmail.com> wrote:
>>
>> Hi,
>>
>> I have been try new things with Shoes and I'm impressed about how easy
>> it is, thats awesome!
>>
>> Originally I thought that all code needed to be within the Shoes.app
>> but apparently not.  After looking at the manual I noticed some
>> examples have code outside the Shoes application.
>>
>> Why would you add code outside the Shoes app?
>>  filename = ask_open_file
>>  Shoes.app do
>>   para File.read(filename)
>>  end
>>
>> Why not keep everything inside?
>>
>>  Shoes.app do
>>  filename = ask_open_file
>>   para File.read(filename)
>>  end
>>
>>
>> Can someone explain why code can live outside the Shoes.app?
>>
>> Sorry if my question doesn't make a lot of sense.
>
>

Re: [shoes] Code outside the Shoes.app

From:
Steve Klabnik
Date:
2012-01-08 @ 16:02
> Only Ruby code can live outside Shoes.app, right?  In other words any
> classes or methods from the Shoes.app must be inside right?

Shoes has a (mostly) regular old Ruby inside of it. You can think of a
Shoes script as being like a regular old Ruby program, except you
don't need to "require 'shoes'" at all, it's already included.

So you know how in regular ruby, you could have this?

class Foo
  def bar
  end
end

And if you called bar outside of the context of a Foo, it wouldn't
make sense, and it would error? Same thing:

class Shoes
  def para(text)
  end
end

Which is a simplified example, but you get the idea!

Re: [shoes] Code outside the Shoes.app

From:
Fily
Date:
2012-01-08 @ 18:21
Thanks a lot for your help!


On Jan 8, 2012, at 10:02 AM, Steve Klabnik <steve@steveklabnik.com> wrote:

>> Only Ruby code can live outside Shoes.app, right?  In other words any
>> classes or methods from the Shoes.app must be inside right?
> 
> Shoes has a (mostly) regular old Ruby inside of it. You can think of a
> Shoes script as being like a regular old Ruby program, except you
> don't need to "require 'shoes'" at all, it's already included.
> 
> So you know how in regular ruby, you could have this?
> 
> class Foo
>  def bar
>  end
> end
> 
> And if you called bar outside of the context of a Foo, it wouldn't
> make sense, and it would error? Same thing:
> 
> class Shoes
>  def para(text)
>  end
> end
> 
> Which is a simplified example, but you get the idea!

Re: [shoes] Code outside the Shoes.app

From:
ashbb
Date:
2012-01-14 @ 01:57
Hi Fily,

J and Steve have already answered, but I'd like to add a little.

Try to run the following two with your Shoes and click 'cancel' btuton
(meaning: choose nothing). You can find the difference. ;-)

  if filename = ask_open_file
    Shoes.app do
      para File.read(filename)
    end
  end


  Shoes.app do
    if filename = ask_open_file
      para File.read(filename)
    end
  end

ashbb