
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
This Rails plugin provides an easy way to insert a tag multiple times in an HTML document with IE conditional comments. This is an alternate approach to conditional stylesheets and CSS hacks, and is explained in detail by Paul Irish.
You can learn more about conditional comments at QuirksMode.
Shown generating the html
tag (as recommended), and adding a
custom class:
<!DOCTYPE html>
<%= ie_conditional_tag :html, class: 'some-custom-class' %>
<head>
<title>New HTML5 page</title>
</head>
<body>
<%= yield %>
</body>
</html>
This would give you (with some prettied indentation):
<!DOCTYPE html>
<!--[if lt IE 7]><html class="ie ie6 some-custom-class"><![endif]-->
<!--[if IE 7]><html class="ie ie7 some-custom-class"><![endif]-->
<!--[if IE 8]><html class="ie ie8 some-custom-class"><![endif]-->
<!--[if IE 9]><html class="ie ie9 some-custom-class"><![endif]-->
<!--[if gt IE 9]><html class="ie some-custom-class"><![endif]-->
<!--[if !IE]><!--><html class="some-custom-class"><!--<![endif]-->
<head>
<title>New HTML5 page</title>
</head>
<body>
<!-- your content -->
</body>
</html>
ie_conditional_tag
will also accept a block, so this also works:
<!DOCTYPE html>
<%= ie_conditional_tag :html, class: 'some-custom-class' do %>
<head>
<title>New HTML5 page</title>
</head>
<body>
<%= yield %>
</body>
<% end %>
We aimed for descriptive and agnostic; you may want to add a helper to call it, eg:
module ApplicationHelper
# ...
def html_tag(*args, &block)
ie_conditional_tag(*args, &block)
end
end
Use bundler. In your Gemfile
:
gem 'ie_conditional_tag'
Install it:
$ bundler install
Then, run the following:
$ rails generate ie_conditional_tag:install
This will add config/initializers/ie_conditional_tag.rb
.
You may want to look/tweak the settings there.
Note: By default, when IE 6, 7, 8, 9 are given the CSS classes 'ie6', 'ie7', 'ie8', and 'ie9' respectively. IE > 9 has no additional class added besides 'ie' (which may be overly optimistic). YMMV.
For details on how to configure the plugin, see lib/ie_conditional_tag/dsl.rb
.
This plugin is only designed to work with Rails 3.0+.
Copyright (c) 2010-2014 Anthony Burns, Bruce Williams. See LICENSE for details.
FAQs
Unknown package
We found that ie_conditional_tag demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.