No commit activity in last 3 years
No release in over 3 years
Seems like `content_for`, content_for_once embed the HTML tags(especially, `javascript_include_tag` and `stylesheet_link_tag`) just only once.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0
~> 3.4.0

Runtime

 Project Readme

ContentForOnce

Gem Version Build Status

Seems like content_for, content_for_once embed the HTML tags(especially, javascript_include_tag and stylesheet_link_tag) just only once.

Usage

Add this line to your Rails application's Gemfile:

gem 'content_for_once'

Prepare some layout file.

-# layout.html.haml
%html
  %head
    = yield :css
    = yield :js

Write content_for_once block, and write tags that you want to use it only once in the page.

-# sample.html.haml
- content_for_once :css do
  = stylesheet_link_tag "sample1"

= render 'sample_mini'
-# _sample_mini.html.haml
- content_for_once :css do
  = stylesheet_link_tag "sample1"
  = stylesheet_link_tag "sample2"

Then rendered page has unique tags!

<html>
  <head>
    <link rel='stylesheet' href='sample1.css'>
    <link rel='stylesheet' href='sample2.css'>
  </head>
<html>

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/tanukiti1987/content_for_once.

License

The gem is available as open source under the terms of the MIT License.

Acknowledgment

content_for_once is being influenced s21g's article. Thanks.