Class: SharingTags::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/sharing_tags/install/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_javascriptsObject



25
26
27
28
29
30
31
32
# File 'lib/generators/sharing_tags/install/install_generator.rb', line 25

def add_javascripts
  source_file = "app/assets/javascripts/application.js"
  match_string = "sharing_tags"

  insert_into_file_if source_file, match_string, after: /\z/ do
    "\n//= require #{match_string}"
  end
end

#add_layoutObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/generators/sharing_tags/install/install_generator.rb', line 48

def add_layout
  ## slim
  source_file = "app/views/layouts/application.html.slim"
  render_meta_tags = "sharing_meta_tags"
  buttons_tags = "sharing_tags_buttons"

  insert_into_file_if(source_file, render_meta_tags, before: "body") do
    "  \n    = #{render_meta_tags}\n\n  "
  end

  insert_into_file_if(source_file, buttons_tags, after: "body") do
    "\n    = #{buttons_tags}\n"
  end

  ## erb
  source_file = "app/views/layouts/application.html.erb"
  insert_into_file_if(source_file, render_meta_tags, before: "</head>") do
    "  <%= #{render_meta_tags} %>\n"
  end

  insert_into_file_if(source_file, buttons_tags, after: "<body>") do
    "\n  <%= #{buttons_tags} %>\n"
  end

  ## TODO: haml
end

#add_stylesObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/generators/sharing_tags/install/install_generator.rb', line 34

def add_styles
  source_file = "app/assets/stylesheets/application.css"

  match_string = "sharing_tags"
  insert_into_file_if source_file, "#{match_string}\n", before: "*/" do
    "*= require #{match_string}\n "
  end

  match_string = "sharing_tags/icons"
  insert_into_file_if source_file, match_string, before: "*/" do
    "*= require #{match_string}\n "
  end
end

#copy_initializer_fileObject



17
18
19
20
21
22
23
# File 'lib/generators/sharing_tags/install/install_generator.rb', line 17

def copy_initializer_file
  if File.exist?("config/initializers/sharing_tags.rb")
    say_skipped("create initializer sharing_tags.rb")
  else
    template 'initializer.rb', 'config/initializers/sharing_tags.rb'
  end
end

#display_post_installObject



75
76
77
# File 'lib/generators/sharing_tags/install/install_generator.rb', line 75

def display_post_install
  readme "POST_INSTALL" if behavior == :invoke
end