ruby
  • haml
  • staticmatic
  • 2009-11-16 5 views 0 likes 
    0

    У меня есть конфигурационный файл, полное это ....haml синтаксис - лучший способ написать это?

    - if current_page.include? "test_string_one" 
         - @total_index = 3 
         - @next_location = '../random_string/page0.html' 
         - @next_name = 'title 2' 
    
        - if current_page.include? "test_string_two" 
         - @total_index = 10 
         - @next_location = '../another_random_string/page0.html' 
         - @next_name = 'title 3' 
    

    Есть уборщик способ написания этого? Использование Staticmatic.

    Я вижу, есть фильтры, доступные в haml. Должно ли все это быть в фильтре :ruby?

    +0

    Dup http://stackoverflow.com/questions/1743291/haml-syntax-better-way-of-writing-this –

    ответ

    1

    Этот код был бы лучше всего в помощнике.

    это может выглядеть следующим образом:

    module SomeHelper 
    
        def page_options 
        @page_options ||= begin 
         options = {} 
    
         if current_page.include? "test_string_one" 
         options[:total_index] = 3 
         options[:next_location] = '../random_string/page0.html' 
         options[:next_name] = 'title 2' 
         elsif current_page.include? "test_string_two" 
         options[:total_index] = 10 
         options[:next_location] = '../another_random_string/page0.html' 
         options[:next_name] = 'title 3' 
         end 
    
         options 
        end 
    
        end 
    
    end 
    

    Затем на каждой странице вам это нужно, вы можете получить доступ к параметрам, как это: page_options[:total_index]

    +0

    Кажется, что придумал ошибку - я сохранил htis-файл как page_helper.rb в помощниках - staticmatic/mixins/helpers.rb: 13: in 'load_helper ': (eval): 1: in 'load_helper': uninitialized constant Haml :: Helpers :: PageHelper (NameError) –

    +0

    Это потому, что SomeHelper следует сохранить как some_helper.rb в hel перс –

     Смежные вопросы

    • Нет связанных вопросов^_^