Skip to content

Commit

Permalink
Different behaviours for rails 4 & 5
Browse files Browse the repository at this point in the history
  • Loading branch information
southwolf committed Apr 9, 2016
1 parent 953fd04 commit eec659f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/bootscaf/cli.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# encoding: utf-8
require 'thor'
require 'net/http'
require 'rails' # Detecting rails version
require_relative 'utils.rb'
require_relative 'version.rb'

Expand Down Expand Up @@ -64,7 +65,11 @@ def nest(nestpath)
print `sed #{icmd} -e 's/#{modelname.capitalize} - $/#{modelname.capitalize} - #{singularized_ancestors.last.capitalize} <%= @#{singularized_ancestors.last}.id %>/' app/views/#{modelname}/index.html.erb`
print `sed #{icmd} -e 's/.html_safe, "\\/", /.html_safe, [#{singularized_ancestors.map{|sa| "@#{sa}"}.join(', ')}], /' app/views/#{modelname}/index.html.erb`
print `sed #{icmd} -e 's/.html_safe, \\[:new, :#{singular_modelname}\\], /.html_safe, [:new, #{singularized_ancestors.map{|sa| "@#{sa}"}.join(', ')}, :#{singular_modelname}], /' app/views/#{modelname}/index.html.erb`
print `sed #{icmd} -e 's/#{modelname.capitalize}$/#{modelname.capitalize}\\\n <small>#{singularized_ancestors.last.capitalize} <%= @#{singularized_ancestors.last}.id %><\\/small>/' app/views/#{modelname}/index.html.erb`
if Rails::VERSION::MAJOR >= 5
print `sed #{icmd} -e 's/#{modelname.capitalize}$/#{modelname.capitalize}\\\n <small>#{singularized_ancestors.last.capitalize} <%= @#{singularized_ancestors.last}.id %><\\/small>/' app/views/#{modelname}/index.html.erb`
else
print `sed #{icmd} -e 's/Listing #{modelname.capitalize}$/Listing #{modelname.capitalize}\\\n <small>#{singularized_ancestors.last.capitalize} <%= @#{singularized_ancestors.last}.id %><\\/small>/' app/views/#{modelname}/index.html.erb`
end
print `sed #{icmd} -e 's/data-href="<%= #{singular_modelname}_path(#{singular_modelname}) %>"/data-href="<%= polymorphic_path([#{singularized_ancestors.map{|sa| "@#{sa}"}.join(', ')}, #{singular_modelname}]) %>"/' app/views/#{modelname}/index.html.erb`
print `sed #{icmd} -e 's/, #{singular_modelname} %><\\/td>/, [#{singularized_ancestors.map{|sa| "@#{sa}"}.join(', ')}, #{singular_modelname}] %><\\/td>/' app/views/#{modelname}/index.html.erb`

Expand Down Expand Up @@ -115,7 +120,8 @@ def update(modelname = nil)
uri = URI.parse("http://code.jquery.com/")
http = Net::HTTP.new(uri.host, uri.port)
http_body = http.get(uri.request_uri).body
minor_version = /, <a href='\/jquery\-2\.(.*?)\.min\.js'>minified<\/a>/.match(http_body)[1]
# minor_version = /, <a href='\/jquery\-2\.(.*?)\.min\.js'>minified<\/a>/.match(http_body)[1]
minor_version=/<a .* href='\/jquery\-2\.(.*?)\.min\.js' .*>minified<\/a>/.match(http_body)[1]
latest_jquery_version = "2.#{minor_version}"
print "#{latest_jquery_version}\n"
latest_boostrap_version ||= LAST_KNOWN_BOOTSTRAP_VERSION
Expand Down Expand Up @@ -220,7 +226,11 @@ def update(modelname = nil)

print "Updating app/views/#{modelname}/index.html.erb. "
print `sed #{icmd} -e 's/<p id="notice"><%= notice %><\\/p>//' app/views/#{modelname}/index.html.erb`
print `sed #{icmd} -e 's/<h1>\\(.*\\)s<\\/h1>/<% content_for :page_title do %>\\\n\\1s - \\\n<% end %>\\\n<div class="container">\\\n<div class="page-header">\\\n<h1>\\\n<div class="pull-left">\\\n<%= link_to "<span class=\\\\"glyphicon glyphicon-step-backward\\\\" aria-hidden=\\\\"true\\\\"><\\/span>".html_safe, "\\/", class: "btn btn-default", title: "Back" %>\\\n\\&nbsp;\\\n<\\/div>\\\n\\\n<div class="pull-right">\\\n<%= link_to "<span class=\\\\"glyphicon glyphicon-plus-sign\\\\" aria-hidden=\\\\"true\\\\"><\\/span> New \\1".html_safe, [:new, :#{Bootscaf::Utils.singularize(modelname)}], class: "btn btn-success" %>\\\n<\\/div>\\\n\\1s\\\n<\\/h1>\\\n<\\/div>\\\n\\\n<table class="table table-striped table-hover tablesorter" id="#{modelname}-table">/' app/views/#{modelname}/index.html.erb`
if Rails::VERSION::MAJOR >= 5
print `sed #{icmd} -e 's/<h1>\\(.*\\)s<\\/h1>/<% content_for :page_title do %>\\\n\\1s - \\\n<% end %>\\\n<div class="container">\\\n<div class="page-header">\\\n<h1>\\\n<div class="pull-left">\\\n<%= link_to "<span class=\\\\"glyphicon glyphicon-step-backward\\\\" aria-hidden=\\\\"true\\\\"><\\/span>".html_safe, "\\/", class: "btn btn-default", title: "Back" %>\\\n\\&nbsp;\\\n<\\/div>\\\n\\\n<div class="pull-right">\\\n<%= link_to "<span class=\\\\"glyphicon glyphicon-plus-sign\\\\" aria-hidden=\\\\"true\\\\"><\\/span> New \\1".html_safe, [:new, :#{Bootscaf::Utils.singularize(modelname)}], class: "btn btn-success" %>\\\n<\\/div>\\\n\\1s\\\n<\\/h1>\\\n<\\/div>\\\n\\\n<table class="table table-striped table-hover tablesorter" id="#{modelname}-table">/' app/views/#{modelname}/index.html.erb`
else
print `sed #{icmd} -e 's/<h1>Listing \\(.*\\)s<\\/h1>/<% content_for :page_title do %>\\\n\\1s - \\\n<% end %>\\\n<div class="container">\\\n<div class="page-header">\\\n<h1>\\\n<div class="pull-left">\\\n<%= link_to "<span class=\\\\"glyphicon glyphicon-step-backward\\\\" aria-hidden=\\\\"true\\\\"><\\/span>".html_safe, "\\/", class: "btn btn-default", title: "Back" %>\\\n\\&nbsp;\\\n<\\/div>\\\n\\\n<div class="pull-right">\\\n<%= link_to "<span class=\\\\"glyphicon glyphicon-plus-sign\\\\" aria-hidden=\\\\"true\\\\"><\\/span> New \\1".html_safe, [:new, :#{Bootscaf::Utils.singularize(modelname)}], class: "btn btn-success" %>\\\n<\\/div>\\\nListing \\1s\\\n<\\/h1>\\\n<\\/div>\\\n\\\n<table class="table table-striped table-hover tablesorter" id="#{modelname}-table">/' app/views/#{modelname}/index.html.erb`
end
print `sed #{icmd} -e 's/<th>\\(.*\\)<\\/th>/<th><span>\\1<\\/span><\\/th>/g' app/views/#{modelname}/index.html.erb`
print `sed #{icmd} -e 's/<table>//' app/views/#{modelname}/index.html.erb`
print `sed #{icmd} -e 's/<\\/table>/<\\/table>\\\n<\\/div>/' app/views/#{modelname}/index.html.erb`
Expand Down

0 comments on commit eec659f

Please sign in to comment.