Coder Social home page Coder Social logo

inert's Introduction

Inert

An experimental static site builder with unambitious goals.

Project Goals

  • Be fast
  • Allow reading of YAML frontmatter
  • Allow queueing of manual URLs for preservation

Usage

Install the gem:

gem install inert

Create a few folders:

mkdir static views

And a layout file:

echo "<%= yield %>" > views/layout.erb

And then start the Inert server:

inert

When you're ready to deploy, build the site:

inert build

Configuring

By default, Inert expects a few things, and should work without configuration. Because it's built on top of Roda, it's very easily extendable, and Inert provides hooks to do this via the Inertfile it will read from your project root at runtime.

# Inertfile
Inert.config do |inert|
   inert.helpers do
     def generator
       "Inert v#{Inert::VERSION}"
     end
   end

  inert.app do
    plugin :h
  end

  inert.routes do |r|
    r.on "employees.html" do
      @employees = [] # Read in actual data here
      view("employees.html.erb")
    end
  end
end

Asset Fingerprinting

Use asset fingerprinting to enable max-cache times on all your static assets.

# Inertfile
Inert.config do |inert|
  inert.app do
    plugin :timestamp_public
  end

  inert.routes do |r|
    r.timestamp_public
  end
end

And inside your views, use the timestamp_path helper with the name of the file in static/ wherever you'd just use the filename itself:

<img src="<%= timestamp_path "some_image_in_static_folder.png" %>">

Asset Minification

Use asset minification to compile and compress all your CSS and JS assets into a single file.

# Inertfile

Inert.config do |inert|
  inert.app do
    plugin :assets, css: %w"text.css layout.css"
    compile_assets if Inert.building?
  end

  inert.routes do |r|
    r.assets
  end
end

And inside your layout, use the assets helper with the name of the asset group:

<%= assets(:css) %>

Make sure you put your assets in assets/group. For the example above, you'd have assets/css/text.css and assets/css/layout.css.

Live Reloads

Use the roda-live_reload gem to enable live reloads:

# Gemfile
gem "roda-live_reload"
gem "puma" # Webrick wont' currently work with roda-live_reload


# Inertfile
Inert.config do |inert|
  inert.app do
    plugin :live_reload if Inert.development?
  end

  inert.routes do |r|
    r.live_reload if Inert.development?
  end
end

Contributing

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

I love pull requests! If you fork this project and modify it, please ping me to see if your changes can be incorporated back into this project.

That said, if your feature idea is nontrivial, you should probably open an issue to discuss it before attempting a pull request.

License

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

inert's People

Contributors

adam12 avatar dependabot[bot] avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

inert's Issues

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.