2017-10-08 11 views
1

erb를 사용하여 중개인과 렌더링하려는 yaml로 작성된 파일이 있습니다. yaml 파일을 HTML로 변환 할 수 있도록 어떻게 렌더링합니까? 나중에 CSS를 사용하여 스타일을 지정하고 싶습니다. 나는 어디서나이 기본 작업을 수행하는 방법에 대한 정보를 찾지 못했습니다. 내가 YAML 데이터에 액세스를 엄격하게이 대답을 제한 할 수 있습니다erb를 사용하여 중개자에서 렌더링 할 YAML 파일을 얻는 방법

main_title: 'Ruby Operators' 

sections: 
    - section_title: 'Arithmetic' 
    items: 
     - title: '[ + ] Addition: ' 
     value: 'Adds values on either side of the operator' 
     - title: '[ − ] Subtraction: ' 
     value: 'Subtracts right hand operand from left hand operand' 
     - title: '[ * ] Multiplication: ' 
     value: 'Multiplies values on either side of the operator.' 

    - section_title: 'Comparison' 
    items: 
     - title: '[ == ]' 
     value: 'Checks if the value of two operands are equal or not, if yes then condition becomes true.' 
     - title: '[ != ]' 
     value: 'Checks if the value of two operands are equal or not, if values are not equal then condition becomes true.' 

내가 HTML

<!DOCTYPE html> 
<html> 

<head> 
    <title>Beautifyconverter.com Yaml To HTML Converter</title> 
</head> 

<body> 
    <table> 
     <tr> 
      <td>main_title</td> 
      <td>sections.0.section_title</td> 
      <td>sections.0.items.0.title</td> 
      <td>sections.0.items.0.value</td> 
      <td>sections.0.items.1.title</td> 
      <td>sections.0.items.1.value</td> 
      <td>sections.0.items.2.title</td> 
      <td>sections.0.items.2.value</td> 
      <td>sections.1.section_title</td> 
      <td>sections.1.items.0.title</td> 
      <td>sections.1.items.0.value</td> 
      <td>sections.1.items.1.title</td> 
      <td>sections.1.items.1.value</td> 
     </tr> 
     <tr> 
      <td>Ruby Operators</td> 
      <td>Arithmetic</td> 
      <td>[ + ] Addition: </td> 
      <td>Adds values on either side of the operator</td> 
      <td>[ − ] Subtraction: </td> 
      <td>Subtracts right hand operand from left hand operand</td> 
      <td>[ * ] Multiplication: </td> 
      <td>Multiplies values on either side of the operator.</td> 
      <td>Comparison</td> 
      <td>[ == ]</td> 
      <td>"Checks if the value of two operands are equal or not</td> 
      <td> if yes then condition becomes true."</td> 
      <td>[ != ]</td> 
      <td>"Checks if the value of two operands are equal or not</td> 
      <td> if values are not equal then condition becomes true."</td> 
     </tr> 
     <tr> 
      <td></td> 
     </tr> 
    </table> 
</body> 

</html> 
+0

: 파일을 가정

mydata.yaml 이름과 중매인 응용 프로그램의 /data 폴더에있는 다음 코드는 당신이 찾고있는 루프 중첩 된 데이터를 생성하기 위해 노력할 것 테이블을 어떻게 보일지에 대해 더 자세히 설명 할 수 있습니다. 그것은 세포의 수의 관점에서 고정 너비 또는 높이가 있습니까? 열과 행은 무엇을 나타내야합니까? –

답변

0

이 같은 렌더링 싶습니다 : 예를 들어

내가 YAML 파일이 있다고 가정 해 파일. 이렇게하면 나중에 나오는 데이터 출력을 얻을 수 있고 거기에서 스타일을 지정하는 방법을 결정할 수 있습니다. 당신이 경우에 도움이 될 것

<h1><%= data.mydata.main_title %></h1> 

<% data.mydata.sections.each do |section| %> 
    <h2><%= section.section_title %><h2> 
    <% section.items.each do |item| %> 
     <h3><%= item.title %></h3> 
     <h4><%= item.value %></h4> 
    <% end %> 
<% end %>