Textmate with HTML(rails) Problem - ruby-on-rails

I am editing a .html.erb file with HTML(rails) selected at the bottom. When I type if I get:
< ?php if (condition): ? >
< ?php endif ? >
Any ideas?
Cheers

Don't fully understand but when I type:
if and hit TAB, I get PHP instead:
<?php if (condition): ?>
<?php endif ?>
You could create your own ERB snippet for example on IF, TAB:
<% if ${1:value?} %>
${2}
<% end %>

Suggestion: Open your Bundle Editor and delete the PHP bundle in you don't need it. This way, I won't interfere with your ERB templates again.

You probably have an incorrect manual binding for .erb files. To see what manual bindings you have run
defaults read com.macromates.textmate OakLanguageFileBindings
If you want to get rid of all your manual bindings, quit TextMate and run
defaults delete com.macromates.textmate OakLanguageFileBindings
More info here http://blog.macromates.com/2007/file-type-detection-rspec-rails/

Related

Ruby and Sinatra: where does this extra string come from and how to eliminate it?

Part of the code in "routes.rb",
...
post '/csr' do
text = PkiSupport::display_csr('/etc/pki/subordinate_ca.csr')
erb :download_csr, :locals => { :csr => text }
end
In "PkiSupport.rb"
...
def display_csr(csr_file)
text = `more #{csr_file}`
return text
end
In "download_csr.erb"
...
<form id="csr-form" action="<%= url "/subordinate_ca/csr" %>" method="post">
<h4>csr</h4>
<textarea cols="80" rows="36" name="csr">
<%= csr %>
</textarea>
</form>
The idea is very simple, when user chooses "/csr", shell command "more ..." will be executed and the output string shown in the textarea of a form.
It does show up correctly, but contains extra preceding string (below), which is anything ahead of "-----BEGIN...". So how to prevent it?
::::::::::::::
/etc/pki/subordinate_ca.csr
::::::::::::::
-----BEGIN CERTIFICATE REQUEST-----
MIIFATCCAukCAQAwaDETMBEGCgmSJomT8ixkARkWA2NvbTETMBEGCgmSJomT8ixk
ARkWA3h5ejEQMA4GA1UECgwHWFlaIEluYzESMBAGA1UECwwJTWFya2V0aW5nMRYw
FAYDVQQDDA0xMC4xMC4xMzAuMTU4MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIIC
CgKCAgEAruWYRn7mjZkHeD+PPLpMSBRoYnLKNvYMte9XneFDh1TItLolYhM4bmWX
gewKOO9+kNY21CoVu1jYZ3q9WitgJlS3tMHPhc6IjuY9DfQ58aeJaZHO8+ISE3Op
l6xNcaxOeHXMlVgdeX4ouyzB2ykJVhu1KtE+XTKilUu6nIrH6ETHrxelBs36Hu1q
...
Thanks.
Most likely, your culprit line of code is this one:
text = `more #{csr_file}`
That code forks and runs the standard Unix more program. Some versions of more will detect if they're run from another program, and output things slightly differently. That's what you're seeing here.
The quickest fix would be to change that line to
text = `cat #{csr_file}`
cat doesn't try to be as smart as more and will give you just the contents of the file.
Now, that said, there's no reason why your Ruby program needs to run a separate program just to read the contents of a file - Ruby has support for reading files directly. So the best fix would be to change that line to:
text = File.read(csr_file)
That will be faster and more portable.

Paths with assemble and swig

i have a project running grunt with assemble and swig as the engine for templating. i need to know how to handle paths for my navigation, because i want to store some files in subfolders.
i just found this for assemble: http://assemble.io/helpers/helpers-path.html
but that doesn't work for me, it says "Warning: Unexpected string Use".
anyone knows a solution for that? do you need any further information?
Thanks for your help at first! I found a first solution myself today:
{{ _dirname(page) }} doesn't work either, because dirnameis related to the layout file where I created my navigation. It does work if I use page.dirname.
My code now looks like
<ul class="navigation-level-1">
<li class="item-level-1 {% if basename == "page" %}current{% endif %}">
<a href="{% if dirname != 'root' %}../{% endif %}page.html" class="text-level-1">
Guild
</a>
<ul class="navigation-level-2">
<li class="item-level-2">
subpage
</li>
</ul>
</li>
</ul>
But the Problem with this is, that I cannot get into subpages from other pages if i entered one subpage. I hope someone can understand what i mean :D
I try to visualize:
* Page A
** Subpage A
* Page B
** Subpage B
If I entered Subpage A and I want to visit Subpage B i can't do so because my solution just works if I am on the root, you know?
Any ideas? :)

Sublimetext 2 and rails html.erb if then else issue

Love Sublime text 2, but somehow can't get it to do 'if then else' properly within an html.erb template.
It correctly identifies the files as 'HTML (Rails)', but when I do 'if' followed by tab
I get:
<?php if (condition): ?>
<?php endif ?>
I've seen this reported a few other places, but not sure how to fix as new to Sublimetext.
Any tips much appreciated
I added a couple of custom snippets to cover if/elsif/else in erb files.
if-erb.sublime-snippet:
<snippet>
<content><![CDATA[<% if ${1:true} -%>]]></content>
<tabTrigger>if</tabTrigger>
<scope>text.html.ruby</scope>
<description>if (ERB)</description>
</snippet>
elsif-erb.sublime-snippet
<snippet>
<content><![CDATA[<% elsif ${1:true} -%>]]></content>
<tabTrigger>elsif</tabTrigger>
<scope>text.html.ruby</scope>
<description>elsif (ERB)</description>
</snippet>
else-erb.sublime-snippet
<snippet>
<content><![CDATA[<% else -%>]]></content>
<tabTrigger>else</tabTrigger>
<scope>text.html.ruby</scope>
<description>else (ERB)</description>
</snippet>
You have php autocomplete there.
Install ruby and rails plugins for rails development.
More at http://linuxrails.blogspot.com/2012/05/sublime-text-2-setup-for-rails.html
Well, the only way i could make it work was by deleting the php snippets and adding some of my own.
Steps:
1- Go to Preferences -> Browse Packages.
2- Go inside PHP folder.
3- Delete the else/elsif snippets.
4- Create your own like the following example:
<snippet>
<content><![CDATA[
<% else %>
]]></content>
<tabTrigger>else</tabTrigger>
<scope>text.html - source</scope>
</snippet>

PHP include outside url

When trying to include a php file into another it either does nothing at all (no errors). If i require it will give a useless message
"Failed opening required 'http://example.org.com/xxx.php' (include_path='.:/usr/local/php5/lib/php')
<div id="menu"> <?php include("http://www.sitename.com/menu.php") ?> </div>
The file im trying to include is on the same site and host.
The page im including from is:
root/wiki/skin/index.php (mediawiki)
menu.php is located:
root/menu.php
since mediawiki treats the /wiki/ path as the root i cannot back out with ../../ etc.
What am i doing wrong here? Thanks
Sir, try this:
<div id="menu"> <?php include("../../menu.php") ?> </div>
To include URLs in your PHP project you must have enabled (true) this option:
allow_url_include
in your php.ini configuration. More information you can find here:
http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-include

How to use joehewitt scrollability?

Can anyone help me out in implementing joehewitt's scrollability plugin.(https://github.com/joehewitt/scrollability.git)
I am trying to develop a mobile web app!
Thanks in advance!
Right so,
1)Include the javascript file and the css file (its in the static folder)
2) Head to http://scrollability.com/
and following the structure create the two divs:
<div id="overflow">
<div id="scrollysection">
</div>
</div>
With the following CSS
#overflow
overflow:hidden
position:absolute
top:0px
left:0px
width:100%
height:100%
#scrollysection
position:absolute
top:0px
left:0px
3)Then you need to apply the fix here: https://github.com/joehewitt/scrollability/issues/29
To get the code running just comment out or remove all of the exports
stuff (lines 77-84). Then on line 94 where require is mentioned, just
pull the two lines of code out of that ready function and comment the
ready function out.
Thats what I did and it worked.
Have a look at the source code of: http://www.uponahill.com/ It is done by Joe Hewitt and uses scrollability.

Resources