{"id":13411878,"url":"https://github.com/thoughtbot/high_voltage","last_synced_at":"2025-05-14T07:07:57.363Z","repository":{"id":39615980,"uuid":"182062","full_name":"thoughtbot/high_voltage","owner":"thoughtbot","description":"Easily include static pages in your Rails app.","archived":false,"fork":false,"pushed_at":"2025-03-05T15:10:16.000Z","size":968,"stargazers_count":3219,"open_issues_count":0,"forks_count":152,"subscribers_count":59,"default_branch":"main","last_synced_at":"2025-05-07T06:38:34.192Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://thoughtbot.github.io/high_voltage","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thoughtbot.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"thoughtbot"}},"created_at":"2009-04-21T19:54:37.000Z","updated_at":"2025-05-05T02:06:05.000Z","dependencies_parsed_at":"2022-09-15T21:42:08.317Z","dependency_job_id":"43154b48-aace-43e3-8eba-965ce3e8c9be","html_url":"https://github.com/thoughtbot/high_voltage","commit_stats":{"total_commits":413,"total_committers":76,"mean_commits":5.434210526315789,"dds":"0.46731234866828086","last_synced_commit":"7bfe2f4d3ddbcb33d53f5ca83974808082e2c88a"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Fhigh_voltage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Fhigh_voltage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Fhigh_voltage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Fhigh_voltage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thoughtbot","download_url":"https://codeload.github.com/thoughtbot/high_voltage/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254092650,"owners_count":22013290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T20:01:17.904Z","updated_at":"2025-05-14T07:07:57.164Z","avatar_url":"https://github.com/thoughtbot.png","language":"Ruby","readme":"# High Voltage [![Build Status](https://github.com/thoughtbot/high_voltage/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/thoughtbot/high_voltage/actions) [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)\n\n\u003e [!NOTE]\n\u003e `high_voltage` is in maintenance-mode. We’re not actively adding new features,\nbut we’ll fix bugs and keep it up to date, and compatible with the latest Ruby\nand Rails versions.\n\nRails engine for static pages.\n\n... but be careful. [Danger!](https://www.youtube.com/watch?v=R-FxmoVM7X4)\n\n## Static pages?\n\nYeah, like \"About us\", \"Directions\", marketing pages, etc.\n\n## Installation\n\nThere are two ways to install High Voltage.\n\nYou can run:\n\n    $ gem install high_voltage\n\nOr you can include in your Gemfile:\n\n```ruby\ngem 'high_voltage', '~\u003e 4.0.0'\n```\n\n## Usage\n\nWrite your static pages and put them in the RAILS_ROOT/app/views/pages directory.\n\n    $ mkdir app/views/pages\n    $ touch app/views/pages/about.html.erb\n\nAfter putting something interesting there, you can link to it from anywhere in your app with:\n\n```ruby\n\u003c%= link_to 'About', page_path('about') %\u003e\n```\n\nYou can nest pages in a directory structure, if that makes sense from a URL perspective for you:\n\n```ruby\n\u003c%= link_to 'Q4 Reports', page_path('about/corporate/policies/HR/en_US/biz/sales/Quarter-Four') %\u003e\n```\n\nBam.\n\nYou can also get a list of your static pages by calling `HighVoltage.page_ids`\nThis might be useful if you need to build a sitemap. For example, if you are\nusing the [sitemap_generator](https://github.com/kjvarga/sitemap_generator) gem,\nyou could add something like this to your sitemap config file:\n\n```ruby\nHighVoltage.page_ids.each do |page|\n  add page, changefreq: 'monthly'\nend\n```\n\n## Configuration\n\n#### Routing overview\n\nBy default, the static page routes will be like /pages/:id (where :id is the view filename).\n\nIf you want to route to a static page in another location (for example, a homepage), do this:\n\n```ruby\nget 'pages/home' =\u003e 'high_voltage/pages#show', id: 'home'\n```\n\nIn that case, you'd need an `app/views/pages/home.html.erb` file.\n\nGenerally speaking, you need to route to the 'show' action with an `:id` param of the view filename.\n\nHigh Voltage will generate a named route method of `page_path`. If you want to generate\nyour own named route (with the :as routing option), make sure not to use `:page`\nas it will conflict with the High Voltage named route.\n\n#### Specifying a root path\n\nYou can configure the root route to a High Voltage page like this:\n\n```ruby\n# config/initializers/high_voltage.rb\nHighVoltage.configure do |config|\n  config.home_page = 'home'\nend\n```\n\nWhich will render the page from `app/views/pages/home.html.erb` when the '/'\nroute of the site is accessed.\n\nNote: High Voltage also creates a search engine friendly 301 redirect. Any attempt to\naccess the path '/home' will be redirected to '/'.\n\n#### Top-level routes\n\nYou can remove the directory `pages` from the URL path and serve up routes from\nthe root of the domain path:\n\n    http://www.example.com/about\n    http://www.example.com/company\n\nWould look for corresponding files:\n\n    app/views/pages/about.html.erb\n    app/views/pages/company.html.erb\n\nThis is accomplished by setting the `route_drawer` to `HighVoltage::RouteDrawers::Root`\n\n```ruby\n# config/initializers/high_voltage.rb\nHighVoltage.configure do |config|\n  config.route_drawer = HighVoltage::RouteDrawers::Root\nend\n```\n\n#### Disabling routes\n\nThe default routes can be completely removed by setting the `routes` to `false`:\n\n```ruby\n# config/initializers/high_voltage.rb\nHighVoltage.configure do |config|\n  config.routes = false\nend\n```\n\n#### Specifying Rails engine for routes\n\nIf you are using multiple Rails engines within your application, you can\nspecify which engine to define the default HighVoltage routes on.\n\n```ruby\n# config/initializers/high_voltage.rb\nHighVoltage.configure do |config|\n  config.parent_engine = MyEngine\nend\n```\n\n#### Page titles and meta-data\n\nWe suggest using `content_for` and `yield` for setting custom page titles and\nmeta-data on High Voltage pages.\n\n```ruby\n# app/views/pages/about.html.erb\n\u003c% content_for :page_title, 'About Us - Custom page title' %\u003e\n```\n\nThen print the contents of `:title` into the layout:\n\n```ruby\n# app/views/layouts/application.html.erb\n\u003ctitle\u003e\u003c%= yield(:page_title) %\u003e\u003c/title\u003e\n```\n\n#### Content path\n\nHigh Voltage uses a default path and folder of 'pages', i.e. 'url.com/pages/contact',\n'app/views/pages'.\n\nYou can change this in an initializer:\n\n```ruby\n# config/initializers/high_voltage.rb\nHighVoltage.configure do |config|\n  config.content_path = 'site/'\nend\n```\n\n#### Caching\n\nBuilt in caching support has been removed in HighVoltage. See [PR 221](https://github.com/thoughtbot/high_voltage/pull/221).\n\nPage caching and action caching can be done via Rails. Visit the [Caching with\nRails: An overview](http://guides.rubyonrails.org/caching_with_rails.html) guide\nfor more details. You can utilize the methods described there by overriding the\nHighVoltage controller as described [below](#override).\n\n## Override\n\nMost common reasons to override?\n\n- You need authentication around the pages to make sure a user is signed in.\n- You need to render different layouts for different pages.\n- You need to render a partial from the `app/views/pages` directory.\n- You need to use your own Page resource and would like to use StaticPage resource for high voltage\n\nCreate a `PagesController` of your own:\n\n    $ rails generate controller pages\n\nDisable the default routes:\n\n```ruby\n# config/initializers/high_voltage.rb\nHighVoltage.configure do |config|\n  config.routes = false\nend\n```\n\nDefine a route for the new `PagesController`:\n\n```ruby\n# config/routes.rb\nget \"/pages/*id\" =\u003e 'pages#show', as: :page, format: false\n\n# if routing the root path, update for your controller\nroot to: 'pages#show', id: 'home'\n```\n\nThen modify new `PagesController` to include the High Voltage static page concern:\n\n```ruby\n# app/controllers/pages_controller.rb\nclass PagesController \u003c ApplicationController\n  include HighVoltage::StaticPage\n\n  before_action :authenticate\n  layout :layout_for_page\n\n  private\n\n  def layout_for_page\n    case params[:id]\n    when 'home'\n      'home'\n    else\n      'application'\n    end\n  end\nend\n```\n\nTo set up a different layout for all High Voltage static pages, use an initializer:\n\n```ruby\n# config/initializers/high_voltage.rb\nHighVoltage.configure do |config|\n  config.layout = 'your_layout'\nend\n```\n\nTo use StaticPage resource, turn off routing and use this route:\n\n```ruby\nget \"/static_pages/*id\" =\u003e 'high_voltage/pages#show', as: :static_page, format: false\n```\n\n## Custom finding\n\nYou can further control the algorithm used to find pages by overriding\nthe `page_finder_factory` method:\n\n```ruby\n# app/controllers/pages_controller.rb\nclass PagesController \u003c ApplicationController\n  include HighVoltage::StaticPage\n\n  private\n\n  def page_finder_factory\n    Rot13PageFinder\n  end\nend\n```\n\nThe easiest thing is to subclass `HighVoltage::PageFinder`, which\nprovides you with `page_id`:\n\n```ruby\nclass Rot13PageFinder \u003c HighVoltage::PageFinder\n  def find\n    paths = super.split('/')\n    directory = paths[0..-2]\n    filename = paths[-1].tr('a-z','n-za-m')\n\n    File.join(*directory, filename)\n  end\nend\n```\n\nUse this to create a custom file mapping, clean filenames for your file\nsystem, A/B test, and so on.\n\n## Localization\n\n[Rails I18n guides](http://guides.rubyonrails.org/i18n.html).\n\nAdd a before filter to the Application controller\n\n```ruby\n# app/controllers/application_controller.rb\nbefore_action :set_locale\n\ndef set_locale\n  I18n.locale = params[:locale] || I18n.default_locale\nend\n```\n\nDisable the default High Voltage routes\n\n```ruby\n# config/initializers/high_voltage.rb\nHighVoltage.configure do |config|\n  config.routes = false\nend\n```\n\n```ruby\n# config/routes.rb\nscope \"/:locale\", locale: /en|bn|hi/ do\n  get \"/pages/:id\" =\u003e \"high_voltage/pages#show\", :as =\u003e :page, :format =\u003e false\nend\n```\n\nAdd a static page to the project\n\n```\n# app/views/pages/about.html.erb\n\u003c%= t \"hello\" %\u003e\n```\n\nMake sure that there are corresponding locale files\n\n```\n/config/locale/bn.yml\n/config/locale/en.yml\n/config/locale/hi.yml\n```\n\nOne last note is there is a [known\nissue](https://github.com/thoughtbot/high_voltage/issues/59) with High Voltage.\n\nYou'll need to specify routes like this `\u003c%= link_to \"About Us\", page_path(id:\n\"about\") %\u003e`\n\n## Testing\n\nYou can test your static pages using [RSpec](https://github.com/rspec/rspec-rails)\nand [shoulda-matchers](https://github.com/thoughtbot/shoulda-matchers):\n\n```ruby\n# spec/controllers/pages_controller_spec.rb\ndescribe PagesController, '#show' do\n  %w(earn_money screencast about contact).each do |page|\n    context \"on GET to /pages/#{page}\" do\n      before do\n        get :show, id: page\n      end\n\n      it { should respond_with(:success) }\n      it { should render_template(page) }\n    end\n  end\nend\n```\n\nIf you're not using a custom PagesController be sure to test\n`HighVoltage::PagesController` instead.\n\nEnjoy!\n\n## Contributing\n\nPlease see [CONTRIBUTING.md].\nThank you, [contributors]!\n\n[CONTRIBUTING.md]: /CONTRIBUTING.md\n[contributors]: https://github.com/thoughtbot/high_voltage/graphs/contributors\n\n## License\n\nHigh Voltage is copyright © 2009 thoughtbot. It is free software, and may\nbe redistributed under the terms specified in the [`LICENSE`] file.\n\n[`LICENSE`]: /MIT-LICENSE\n\n\u003c!-- START /templates/footer.md --\u003e\n## About thoughtbot\n\n![thoughtbot](https://thoughtbot.com/thoughtbot-logo-for-readmes.svg)\n\nThis repo is maintained and funded by thoughtbot, inc.\nThe names and logos for thoughtbot are trademarks of thoughtbot, inc.\n\nWe love open source software!\nSee [our other projects][community].\nWe are [available for hire][hire].\n\n[community]: https://thoughtbot.com/community?utm_source=github\n[hire]: https://thoughtbot.com/hire-us?utm_source=github\n\n\n\u003c!-- END /templates/footer.md --\u003e\n","funding_links":["https://github.com/sponsors/thoughtbot"],"categories":["Ruby","Content Management \u0026 Blogging","Static Site Generation","Gems","Static Pages","Views and related"],"sub_categories":["Static Website Generation","Rails"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoughtbot%2Fhigh_voltage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthoughtbot%2Fhigh_voltage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoughtbot%2Fhigh_voltage/lists"}