Module: ShopifyTheme

Includes:
HTTParty
Defined in:
lib/shopify_theme.rb,
lib/shopify_theme/cli.rb,
lib/shopify_theme/version.rb

Defined Under Namespace

Classes: Cli

Constant Summary collapse

NOOPParser =
Proc.new {|data, format| {} }
VERSION =
"0.0.8"

Class Method Summary collapse

Class Method Details

.asset_list(env) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/shopify_theme.rb', line 7

def self.asset_list(env)
  # HTTParty parser chokes on assest listing, have it noop
  # and then use a rel JSON parser.
  response = shopify(env).get(path(env), :parser => NOOPParser)
  assets = JSON.parse(response.body)["assets"].collect {|a| a['key'] }
  # Remove any .css files if a .css.liquid file exists
  assets.reject{|a| assets.include?("#{a}.liquid") }
end

.configObject



30
31
32
# File 'lib/shopify_theme.rb', line 30

def self.config
  @config ||= YAML.load(File.read('config.yml'))
end

.delete_asset(asset, env) ⇒ Object



26
27
28
# File 'lib/shopify_theme.rb', line 26

def self.delete_asset(asset, env)
  shopify(env).delete(path(env), :body =>{:asset => {:key => asset}})
end

.get_asset(asset, env) ⇒ Object



16
17
18
19
20
# File 'lib/shopify_theme.rb', line 16

def self.get_asset(asset, env)
  response = shopify(env).get(path(env), :query =>{:asset => {:key => asset}}, :parser => NOOPParser)
  # HTTParty json parsing is broken?
  JSON.parse(response.body)["asset"]
end

.ignore_files(env) ⇒ Object



38
39
40
41
# File 'lib/shopify_theme.rb', line 38

def self.ignore_files(env)
  files_array = config[:"#{env}"][:ignore_files] || config[:ignore_files] || []
  @ignore_files ||= files_array.compact.collect { |r| Regexp.new(r) }
end

.is_binary_data?(string) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
# File 'lib/shopify_theme.rb', line 43

def self.is_binary_data?(string)
  if string.respond_to?(:encoding)
    string.encoding == "US-ASCII"
  else
    ( string.count( "^ -~", "^\r\n" ).fdiv(string.size) > 0.3 || string.index( "\x00" ) ) unless string.empty?
  end
end

.path(env) ⇒ Object



34
35
36
# File 'lib/shopify_theme.rb', line 34

def self.path(env)
  @path ||= config[:"#{env}"][:theme_id] ? "/admin/themes/#{config[:"#{env}"][:theme_id]}/assets.json" : "/admin/assets.json" 
end

.send_asset(data, env) ⇒ Object



22
23
24
# File 'lib/shopify_theme.rb', line 22

def self.send_asset(data, env)
  shopify(env).put(path(env), :body =>{:asset => data})
end