Class: Middleman::S3SyncExtension

Inherits:
Extension
  • Object
show all
Defined in:
lib/middleman-s3_sync/extension.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options_hash = {}, &block) ⇒ S3SyncExtension

Returns a new instance of S3SyncExtension.



35
36
37
# File 'lib/middleman-s3_sync/extension.rb', line 35

def initialize(app, options_hash = {}, &block)
  super
end

Instance Method Details

#after_buildObject



53
54
55
# File 'lib/middleman-s3_sync/extension.rb', line 53

def after_build
  ::Middleman::S3Sync.sync() if options.after_build
end

#after_configurationObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/middleman-s3_sync/extension.rb', line 39

def after_configuration
  read_config
  options.aws_access_key_id ||= ENV['AWS_ACCESS_KEY_ID']
  options.aws_secret_access_key ||= ENV['AWS_SECRET_ACCESS_KEY']
  options.bucket ||= ENV['AWS_BUCKET']
  options.http_prefix = app.http_prefix if app.respond_to? :http_prefix
  options.build_dir ||= app.build_dir if app.respond_to? :build_dir
  if options.prefix
    options.prefix = options.prefix.end_with?("/") ? options.prefix : options.prefix + "/"
    options.prefix = "" if options.prefix == "/"
  end
  ::Middleman::S3Sync.s3_sync_options = s3_sync_options
end

#caching_policy(content_type, policy = {}) ⇒ Object



92
93
94
# File 'lib/middleman-s3_sync/extension.rb', line 92

def caching_policy(content_type, policy = {})
  ::Middleman::S3Sync.add_caching_policy(content_type, policy)
end

#default_caching_policy(policy = {}) ⇒ Object



88
89
90
# File 'lib/middleman-s3_sync/extension.rb', line 88

def default_caching_policy(policy = {})
  ::Middleman::S3Sync.add_caching_policy(:default, policy)
end

#manipulate_resource_list(mm_resources) ⇒ Object



57
58
59
# File 'lib/middleman-s3_sync/extension.rb', line 57

def manipulate_resource_list(mm_resources)
  ::Middleman::S3Sync.mm_resources = mm_resources
end

#read_config(io = nil) ⇒ void

This method returns an undefined value.

Read config options from an IO stream and set them on ‘self`. Defaults to reading from the `.s3_sync` file in the MM project root if it exists.

Parameters:

  • io (IO) (defaults to: nil)

    an IO stream to read from



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/middleman-s3_sync/extension.rb', line 70

def read_config(io = nil)
  unless io
    root_path = ::Middleman::Application.root
    config_file_path = File.join(root_path, ".s3_sync")

    # skip if config file does not exist
    return unless File.exists?(config_file_path)

    io = File.open(config_file_path, "r")
  end

  config = (YAML.load(io) || {}).symbolize_keys

  config.each do |key, value|
    options[key.to_sym] = value
  end
end

#s3_sync_optionsObject



61
62
63
# File 'lib/middleman-s3_sync/extension.rb', line 61

def s3_sync_options
  options
end