Tag: haml

HAML。变量的函数

我有大约30多个变量,其中包含一个包含多个字符串的数组。 1个变量= 1个数组。 我想知道是否可以创建一个包含所有变量名称的新变量,因此我可以遍历它们。 例如: 这些是单个数组: – @a = [“a”,”b”,”c”,”d”,”d”]; – @b = [“a”,”b”,”c”,”c”,”d”]; – @c = [“a”,”b”,”c”,”d”]; 现在我想在单独的变量中获取所有唯一且重复的字符串,如下所示: – @x_uniq = @a.uniq – @x_dup = @a.each_with_object(Hash.new(0)) { |e,h| h[e] += 1 }.select{ |k,v| v > 1 }.keys … – @x_uniq = @b.uniq – @x_dup = @b.each_with_object(Hash.new(0)) { |e,h| h[e] += 1 }.select{ |k,v| v […]

haml html属性中的正则表达式

是posibble有这样的东西? : %div{“data-regex”: “a/regular/expression”} 当我尝试这样做时,我收到此错误: syntax error, unexpected ‘:’, expecting tASSOC 我试过这个: %div{“data-regex”: #{“a/regular/expression”}} ,但是是一样的。

使fields_for块有条件

我有一个用户模型和一个讲师模型。 用户和教师之间存在一对一的关系。 有些用户将是教师,有些则不会。 因此,我有一个注册表单,使用fields_for方法写入两者。 如何只在他们说自己是教师的情况下才能写入教师表,例如通过复选框。 当他们写作时,我想保持表格的其他表格的validation 理想情况下,如果我可以通过模型做到这一点,这将是最好的,但我对所有建议持开放态度。 讲师模型 class Instructor < ActiveRecord::Base belongs_to :user validates_presence_of :school_url, :etc… attr_accessible :school_url, :etc… end 用户模型 class User :destroy validates_uniqueness_of :email validates :email, :confirmation => true accepts_nested_attributes_for :instructor attr_accessible :email, :password, :instructor_attributes, :etc end HAML中的表格 – resource.build_instructor – form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| = hidden_field_tag […]

纺织和maruku问题

我为HAML开发了自定义filter( http://github.com/alec-c4/cb-haml-filters ),并且纺织品和maruku有一个小问题。 也许你可以帮我这个 带代码的纺织品问题 %h2 Textile test :cbtextile h4. YouTube video http://www.youtube.com/watch?v=0_IXrjqKbE4&feature=player_embedded 解析后,我看到h4标签内嵌入youtubevideo(h4和http:// youtube之间有1个空行…我的意思是\ n \ n)。 但是在两个空行(\ n \ n \ n)上 – 所有渲染都正确。 在markdown中 – 所有html渲染都很好。 Maruku。 一切都好,但是scribdfilter会导致错误 REXML无法解析此XML / HTML:

载波图像未加载到源代码中

不知道我在这个问题上做错了什么。 我已经按照Rails Cast for Carrierwave进行了操作,但是我遇到了一个奇怪的错误,图像根本没有显示 – (HTML)源代码显示的是图像标记,但内部没有任何内容。 组合模型代码: class Portfolio < ActiveRecord::Base validates :title, :content, presence: true mount_uploader :feature_image, FeatureImageUploader end function图像上传代码: class FeatureImageUploader < CarrierWave::Uploader::Base storage :file def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end def extension_white_list %w(jpg jpeg gif png) end end Show.html.haml代码: = @portfolio.title =image_tag @portfolio.feature_image_url.to_s =markdown(@portfolio.content).html_safe 我的表格代码: .field = f.label :title %br = f.text_field :title […]

Sinatra自定义SASS目录

我的haml模板让我的sass工作有问题。 最近我在我的主要sinatra.rb应用程序中有以下代码: require ‘sinatra’ require ‘dm-core’ require ‘dm-migrations’ require ‘haml’ require ‘sass’ require ‘shotgun’ set :views, :sass => ‘views/css’, :haml => ‘template’, :default => ‘views’ helpers do def find_template(views, name, engine, &block) _, folder = views.detect { |k,v| engine == Tilt[k] } folder ||= views[:default] super(folder, name, engine, &block) end end get ‘/css/styles.css’ do sass […]

在Ruby脚本中使用SLIM / HAML等?

我目前正在编写一个脚本,分析一些遗传数据,然后在彩色Word文档上生成输出。 但是,脚本工作正常,脚本中的一个方法编写得很糟糕,即创建Word文档的方法。 创建文档的方法创建一个独立的HTML文件,然后使用’docx’扩展名保存,这允许我为文档的不同部分提供不同的样式。 以下是实现此function的最低要求。 它包括一些示例输入数据,这些数据将在最后一步之前以不同的方法创建并存储在散列中,以及必要的方法。 require ‘bio’ def make_hash(input_file) input_read = Hash.new biofastafile = Bio::FlatFile.open(Bio::FastaFormat, input_file) biofastafile.each_entry do |entry| input_read[entry.definition] = entry.aaseq end return input_read end def to_doc(hash, output, motif) output_file = File.new(output, “w”) output_file.puts ” .id{font-weight: bold;} .signalp{color:#000099; font-weight: bold;} .motif{color:#FF3300; font-weight: bold;} h3 {word-wrap: break-word;} p {word-wrap: break-word; font-family:Courier New, Courier, Mono;}” hash.each […]

在sinatra应用程序中使用自定义布局选项时出现NameError

要在我的应用程序中使用自定义布局文件,我使用以下代码, set :views, File.dirname(__FILE__) + “/../views” set :public_folder, File.dirname(__FILE__) + “/../public” get ‘/’ do if !Db.empty? then haml :home, {:layout => :nosetup-layout} elsif request.ip == “127.0.0.1” then haml :setup, {:layout => :nosetup-layout} else haml :nosetup, {:layout => :nosetup-layout} end end 布局选项似乎有问题 我收到以下错误 undefined local variable or method `layout’ for # 那么,我哪里出错了?

Rails Partial(Rails 3,HAML)任意慢

我使用的是Rails 3.0.1,HAML 0.3.22和Mongrel 1.1.5(以及MongoMapper而不是AR)。 我正在渲染一个列表,每个列表项都是它自己的部分。 每次页面渲染时,其中一个列表项部分需要花费几乎100倍的时间来渲染(并且每次都是一个任意不同的。另外,不用说,每个项目基本上都有相同的数据)。 知道这里发生了什么吗? 我应该将逻辑移动到块而不是部分吗? Rendered shared/_head.html.haml (5.6ms) Rendered tasks/_incomplete_task.haml (6.2ms) Rendered tasks/_incomplete_task.haml (6.4ms) Rendered tasks/_incomplete_task.haml (6.9ms) Rendered tasks/_incomplete_task.haml (6.2ms) Rendered tasks/_incomplete_task.haml (6.0ms) Rendered tasks/_incomplete_task.haml (6.1ms) Rendered tasks/_incomplete_task.haml (6.4ms) Rendered tasks/_incomplete_task.haml (6.2ms) Rendered tasks/_incomplete_task.haml (7.0ms) Rendered tasks/_incomplete_task.haml (531.6ms) Rendered tasks/_incomplete_task.haml (8.0ms) Rendered tasks/_incomplete_task.haml (6.8ms) Rendered tasks/_incomplete_task.haml (6.5ms) Rendered shared/_tasks.html.haml (633.0ms)

如何让一行以|结尾 (管道)在HAML?

问题是一个| 在行的末尾(由空格分隔)被识别为高级换行符的语法。 如果你想把这个角色作为输出怎么办? 例 假设您要创建一个菜单 Section 1 | Section 2 | … 注意:如果这正是您想要的,那么请看一下 使用pipe连接link_to 。 是否显示链接取决于某种条件。 在HAML / Ruby on Rails中,这可能看起来不起作用 %div.menu -if condition1? #{link_to ‘Section 1’, section_1_path} | -if condition2? #{link_to ‘Section 2’, section_2_path} | -if condition3? … 变通 作为一个(某种程度上是肮脏的)解决方法,我更改了代码: %div.menu -if condition1? #{link_to ‘Section 1’, section_1_path} #{‘|’} -if condition2? #{link_to ‘Section 2’, section_2_path} […]