English 中文(简体)
Sinatra(通过命名公约)中的具体风格
原标题:View specific stylesheets in Sinatra (by naming convention)
  • 时间:2010-08-20 12:46:07
  •  标签:
  • ruby
  • sinatra

我的Sinatra在布局中要有一个特定的风格。

考虑这一简单内容:

app_folder_root/
| my_app/
|   my_app.rb
| public/
|   css/
|     index.css
|     layout.css
| views/
|   index.haml
|   layout.haml
config.ru

config.ru:

require  rubygems 
require  ./my_app/my_app 

map  /  do
  run MyApp
end

注:

require  sinatra/base 

class MyApp < Sinatra::Base
  get  /  do
    haml :index
  end
end

我尝试在<条码>my_app.rb中设定一个变数,其中列出观点的名称,并试图在<条码>layout.haml中提及该词,但是这并不奏效(我可能没有这样做作为解决问题的最后解决办法,因为我认为这是一个法典轮).,只是试图尝试不同的可能性)。

这正在使用Haml,但我希望这是不相干的——认为它应当与er一样。

在<代码>layout.haml中,我谨提及将提出的观点,并通过命名公约列入一种特定风格。 例如,如果<代码>index.haml>将提交,我将列入<编码>cs/index.css。 做到这一点的最佳途径是什么?

最佳回答

我通过采取以下行动解决了这一问题:

<编码>index.haml (最高层)

- @views = Array.new unless defined? @views
- @views <<  index 

<编码>layout.haml 页: 1

%head
  - @views.each do |view|
    - haml_tag :link, {:rel =>  stylesheet , :type =>  text/css , :href => "css/#{view}.css"}

我对必须检查<代码>@views感到很失望,以确保该编码在评估之前确定,但现在可以管理。

EDIT:每个观点都界定了必须检查@views的问题。 www.un.org/Depts/DGACM/index_french.htm

before do
  @views = Array.new
end

我现在可以从以下观点中删除这一思路:

- @views = Array.new unless defined? @views
问题回答

暂无回答




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签