What Language is this

I have to do a bit of work on a site, and it would help is I knew what language this is so I can find some reference somewhere (here some sample lines):

<% questions.useful.each do |q| %>
<% if category %>
<%= category.name.html %><% else %>Search Results<% end %>

(The last bit of the above code does not show on the web - but the code always starts with open bracket and percent sign, and closes with a percent sign and close bracket)


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

This looks like Ruby, in the erb (Embedded Ruby) syntax.

Walter


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I just fixed the formatter (ugh, again) so the closing tags render properly.

This code looks similar to that which you will find in a Ruby on Rails project. Are you working with a programmer, or have you been asked to change an existing site by someone non-technical?

I ask because there are a lot of hidden dependencies in a RoR project, and not a lot of guideposts. RoR is founded on the principle that you should “[follow] convention, not [edit] configuration [files]”, which means that there’s a lot of hidden knowledge needed to mess with anything.

Walter


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Its an existing project, where I am styling the look of a clients pages by hand coding the HTML and CSS.

*Some of the code bits are included, being passed out to many clients so they can style their section if they want to (being coders the basic layout options are not good).

*I must assume a lot more code is hidden elsewhere on the main site so clients don’t bring down the whole ship when they mess up. No feedback is given to the code bits, e.g if you break it, its your fault, you got to start again.

I’m happy styling the pages, but it would be nice to know what the language it is and see what resources I can find on it, as I’ve noticed a few things that might be nicer if tweaked. e.g. pulling down a few variables to appear on the pages in other places.


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

It would be helpful to see a larger context here, because if this is running in a Rails project, then there’s a particular way you structure the page – images have to be invoked in a particular way, forms are handled in another. Anything that is in a view (the part you would be changing) is context-dependent. A view is invoked by a controller, which sets up the variables that you have to play with.

Looking at the code you have here:

<% questions.useful.each do |q| %>
<% if category %>
<%= category.name.html %><% else %>Search Results<% end %>

This could be expressed in pseudocode (fake, made-up code to describe a functional structure) like this:

given an array of questions,
take the ones with a useful parameter,
loop over them:
    call each one 'q',
    if q has a property called category,
        print the html flavor of the category's name
    otherwise
        print the string 'Search Results'
    end the test on q
end the loop on questions

Ruby is a very flexible and expressive language, and it doesn’t need a lot of control operators (parentheses, curly braces, dollar signs) to make a function call or to pass variables around. This makes it very terse, but once you grasp it, it also makes it very pretty (if such a thing can be said about a programming language).

So in this example, if it’s a MVC (Model View Controller) programming environment like Rails, the Controller would gather up the questions, decorate each of them with additional properties, then pass the array of objects to the View for conversion into display html. As you edit the View, you have to know what you have to play with. This code fragment you posted shows one example, but there are likely others.

For example, you might have a view that shows one question. So you wouldn’t have a loop at all, and you might not even see the keyword ‘question’ in the code, either. Your view would just “know” that it was operating on a question, and you would need to know the individual properties that this question had, so you could call them by name.

If you work on moving HTML around, and leave the erb parts more or less alone – that is, edit the parts that look familiar – then this can be a great learning experience, because you probably won’t break anything and you’ll get to see the inner workings of a template engine in a very micro way. Where this will get frustrating and complex is if your client asks you to create new views that don’t have parallels in the existing code. The first time you have to code up an erb template from scratch, it will feel like building a ship in a bottle, while blindfolded and wearing oven mitts.

Walter


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks Walter for your input.

I looks like my thoughts were on the the similar lines, and this has helped to reassure me I’m following the right path, and not to mess with the structure of the code and keep it simple.

You can’t put any PHP code alongside it either, any PHP breaks the pages.

Thanks again :slight_smile:


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

You can’t put any PHP code alongside it either, any PHP breaks the pages.

Yeah, I’m not surprised. One language per customer, usually. That said, there’s nothing or very little that you can’t use Ruby to do that you could do in PHP. More likely the opposite is true, actually. Ruby is a younger language than PHP, and more evolved. It’s the love-child of Smalltalk and Perl, if two less likely parents could be imagined.

Post your PHP code, and I’ll try to tranlate it into Ruby for you. Fun exercise!

Walter


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks for asking, I was going to try adding an include to display some text from another part of main system page. This works fine on a PHP page but breaks on this Ruby page, so can only be put in as an HTML iframe and does not look very neat:-

<?php data("data 7b4f62c6cb1d0c73030") ?>

dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

That was not clear, I currently have to publish this code into to a php page to display the data, then create an iframe on the ruby page to display this php page contents. just not neat way :frowning:


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Please post the full source of the data() function, including any comments that there might be in the original source. If that’s not available, you may be able to call the php function using a system call, invoking the command-line php binary outside of the Web environment, but then you’re in for a long crawl of formatting.

Walter


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Sorry, that’s all there is. Its supplied by the programmers of the system. To display client data elsewhere on standard php pages hosted by the system. As I said there not giving much away, I assume so no-one breaks the system mucking about with it too much.


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

That’s really odd, then, that they have both Ruby and PHP code to interact with the data. I would follow this question up with them, because I can’t help you any further without knowing what the data() function requires or returns.

Walter


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

No problem - it was worth asking.

The php is on a different part on the system which works fine with just php pages I just would like to display something better than an iFrame in this bit which uses Ruby.

Is there a way of making an iFrame collapse to fit its content so there is no scroll bar?


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

The trouble is, its content is in a completely other context – it’s another site altogether – so the iframe itself doesn’t have any way of getting the size of that content from within the context of your page.

You can try modifying the iframe to appear borderless. Have a look on HTML School for the exact syntax – I try to avoid iframes when I can. But you won’t likely be able to make the iframe resize to match its content.

Another thing you can try is to use an object tag instead of an iframe. But that might have IE6 ramifications.

Walter


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options