Giter Site home page Giter Site logo

skbull.github.io's Introduction

You earn, You yawn, You yeah you Yon. 🎪

skbull.github.io's People

Contributors

github-actions[bot] avatar skbull avatar

skbull.github.io's Issues

HTML とデータの分離

現在は source/index.html.erb の中身に文章などのコンテンツを直接記述していますが、コンテンツの編集が必要になるたびに HTML ファイルを直接編集するのは面倒だと思います。コンテンツだけでなく、タグの追加や整形なども必要だからです。

そこで、今後更新しうるコンテンツを別ファイルに分離したいです。具体的には以下のリストの部分ですね。

<h2>出身</h2>
<ul>
  <li>宗像市</li>
</ul>
<h2>好きなこと</h2>
<ul>
  <li>ペーパークラフト</li>
  <li>授業が2限からの日に1限ギリギリに学校にいって1限に急いでる人見ること</li>
  <li>寿司</li>
</ul>
<h2>好きな動物</h2>
<ul>
  <li>白くま</li>
  <li>ライオン</li>
  <li>クロヒョウ</li>
  <li>チンパンジー</li>
  <li>山猫</li>
</ul>

手順

01. YAML ファイルの作成

まず Ruby で以下の様な構造の配列を用意したいです。

lists = [
  { header: '出身', items: ['宗像市'] },
  { header: '好きな動物', items: ['イヌ', 'ネコ', 'キュウべえ'] },
]

このように構造を持ったデータを扱うのに YAML というフォーマットが便利で、よく使われます。まず YAML ファイルを用意して、Ruby で YAML ファイルを読み込み、上記のデータ構造を再現してください。

02. erb ファイルに Ruby コードを埋め込む

source/index.html.erb では h2 要素と ul 要素の並び方がパターン化していますね。せっかく erb という Ruby コードを埋め込めるファイル形式を使っているので、YAML から読み込んだデータを Ruby のループでコンテンツを埋め込めないでしょうか。

<% data.lists.each do |list| %>
  <%# ここを実装する。 %>
<% end %>

参考

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.