Class: Venus::Generators::AssetSyncGenerator

Inherits:
Base
  • Object
show all
Defined in:
lib/generators/venus/asset_sync/asset_sync_generator.rb

Instance Method Summary collapse

Methods inherited from Base

next_migration_number, source_root

Instance Method Details

#asksObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/generators/venus/asset_sync/asset_sync_generator.rb', line 10

def asks
  settingslogic_dependent
  @settings = {}
  @settings[:aws_access_key_id] = ask?("AWS access key", "") unless key_in_settingslogic?("aws_access_key_id")
  @settings[:aws_secret_access_key] = ask?("AWS secret key", "") unless key_in_settingslogic?("aws_secret_access_key")
  @settings[:aws_assets_region] = ask?("AWS S3 region for assets sync", "us-east-1") unless key_in_settingslogic?("aws_assets_region")
  @settings[:aws_assets_bucket] = ask?("AWS S3 bucket for assets sync", app_name) unless key_in_settingslogic?("aws_assets_bucket")
  @settings[:aws_assets_host] = ask?("AWS S3 host for assets sync", "#{app_name}.s3-website-us-east-1.amazonaws.com") unless key_in_settingslogic?("aws_assets_host")
  @settings[:aws_assets_path_prefix] = ask?("AWS S3 assets path prefix", "") unless key_in_settingslogic?("aws_assets_path_prefix")
  # @has_ckeditor_rails = ask?("has ckeditor-rails?", false)
end

#copy_initializer_fileObject



51
52
53
# File 'lib/generators/venus/asset_sync/asset_sync_generator.rb', line 51

def copy_initializer_file
  template 'asset_sync.rb.erb', 'config/initializers/asset_sync.rb'
end

#insert_to_yamlObject



27
28
29
30
31
32
# File 'lib/generators/venus/asset_sync/asset_sync_generator.rb', line 27

def insert_to_yaml
  Hash[@settings.to_a.reverse].each do |key, value|
    is_secret = key == :aws_secret_access_key ? true : false
    insert_settingslogics(key, value, :secret => is_secret)
  end
end

#nameObject



6
7
8
# File 'lib/generators/venus/asset_sync/asset_sync_generator.rb', line 6

def name
  "asset_sync"
end

#production_rbObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/generators/venus/asset_sync/asset_sync_generator.rb', line 34

def production_rb
  to_file = "config/environments/production.rb"
  # if(@has_ckeditor_rails) 
  line =  "#  config.relative_url_root = \"http://\#{#{@settinglogic_class}.aws_assets_host}\"\n"
  line += "  config.action_controller.asset_host = #{@settinglogic_class}.aws_assets_host"
  unless file_has_content?(to_file, line)
    comment_lines(to_file, /config\.action_controller\.asset_host/)
    insert_line_into_file(to_file, line, :before => /\nend[\n]*$/)
  end

  line2 = "  config.assets.prefix = #{@settinglogic_class}.aws_assets_path_prefix"
  unless file_has_content?(to_file, line2)
    comment_lines(to_file, /config\.assets\.prefix/)
    insert_line_into_file(to_file, line2, :before => /\nend[\n]*$/)
  end
end

#set_gemfileObject



22
23
24
25
# File 'lib/generators/venus/asset_sync/asset_sync_generator.rb', line 22

def set_gemfile
  add_gem("asset_sync", "~> 0.5.4")
  bundle_install
end