Skip to content

Instantly share code, notes, and snippets.

@r3cha
Last active April 6, 2019 16:03
Show Gist options
  • Save r3cha/072e5f327feef870d5ed6aa0e1f37848 to your computer and use it in GitHub Desktop.
Save r3cha/072e5f327feef870d5ed6aa0e1f37848 to your computer and use it in GitHub Desktop.
Create Ruby on Rails application from bootstrap theme
//= require rails-ujs
//= require activestorage
//= require jquery
//= require jquery_ujs
//= require popper
//= require bootstrap
//= require aos.js
//= require clipboard.js
//= require jquery.fancybox.min.js
//= require flickity.pkgd.min.js
//= require ion.rangeSlider.min.js
//= require isotope.pkgd.min.js
//= require jarallax.min.js
//= require jarallax-video.min.js
//= require jarallax-element.min.js
//= require jquery.countdown.min.js
//= require plyr.polyfilled.min.js
//= require prism.js
//= require scrollMonitor.js
//= require smooth-scroll.polyfills.min.js
//= require twitterFetcher_min.js
//= require typed.min.js
//= require theme.js
//= require_self
window.addEventListener("load", function () {
document.querySelector('body').classList.add('loaded');
});
# add this gems to Gemfile
gem 'bootstrap', '~> 4.3.1'
gem 'jquery-rails'
gem 'popper_js', '~> 1.14.5'
namespace :parse_template do
task :start do
# get array of paths to html files (pages)
pages = Dir.glob("#{Rails.root}/tmp/BootstrapThemeOne/pages/**/*.html")
# goes trough each page path
pages.each do |page_path|
# find name of page
page_name = page_path.split('/').last.split('.').first
# open this page and parse with Nokogiri gem (includede in Rails by default)
parse_page = Nokogiri::HTML(open(page_path))
# take all html inside body tag expect common like header nav, footer
page_inner_content = parse_page.css('body > *:not(footer#footer):not(script):not(header.navbar-container):not(.loader):not(.back-to-top)')
# create app/views/pages/page_name.html.erb file and write content there
File.open("#{Rails.root}/app/views/pages/#{page_name.underscore}.html.erb", 'w') { |f|
f.write(page_inner_content.to_html)
}
end
end
end
@r3cha
Copy link
Author

r3cha commented Apr 6, 2019

This is rake task parse bootstrap theme into Rails app views

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment