Sha256: bbec020e090e517ce22a0671c2b2e320fd327d9170205a93e80ead7e7333572a
Contents?: true
Size: 1.81 KB
Versions: 2
Compression:
Stored size: 1.81 KB
Contents
BarkestCore::InstallGenerator.class_eval do ## # Patches application.js and application.css def patch_assets target = 'barkest_core/application' [ [ 'app/assets/javascripts/application.js', '//=', "// Application.js\n//= require_tree .\n" ], [ 'app/assets/stylesheets/application.css', '*=', "/*\n * Application.css\n *= require_tree .\n *= require_self\n */\n" ] ].each do |(path, line_tag, def_contents)| lines = if File.exist?(path) File.read(path) else def_contents end.split("\n") first_tag = -1 first_pass = true loop do lines.each_with_index do |line, index| if line.strip[0...line_tag.length] == line_tag first_tag = index break end end if first_tag < 0 if first_pass lines += def_contents.split("\n") else raise StandardError.new("Failed to locate line starting with '#{line_tag}' in '#{path}'.") end else break end first_pass = false end regex = /^\s*#{line_tag.gsub('*',"\\*")}\s*require\s*['"]?#{target}['"]?\s*$/ tag_index = -1 lines.each_with_index do |line, index| if regex.match(line) tag_index = index break end end if tag_index < 0 if ask_for_bool("Would you like to add a reference to BarkestCore in '#{path}'?", true) lines.insert first_tag, "#{line_tag} require #{target}" perform "> updating '#{path}'..." do File.write path, lines.join("\n") end else tell "> '#{path}' is unchanged.", :bright_green end else tell "> '#{path}' is good.", :bright_green end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
barkest_core-1.5.4.0 | lib/generators/barkest_core/actions/03_patch_assets.rb |
barkest_core-1.5.3.0 | lib/generators/barkest_core/actions/03_patch_assets.rb |