magnetize 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +71 -0
- data/Rakefile +1 -0
- data/bin/magnetize +9 -0
- data/lib/magnetize/cli.rb +36 -0
- data/lib/magnetize/convert.rb +109 -0
- data/lib/magnetize/version.rb +3 -0
- data/lib/magnetize.rb +3 -0
- data/magnetize.gemspec +29 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3d8b644b0a8c6dfe892a68db2e9ae1ed86c07eb7
|
4
|
+
data.tar.gz: cbf056152442454a0316fa56e5912e078e098010
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4bbbf8569217b460960001da052650642bf69b96807c33111d314c32d410589eae3e8df7d831fa2648b3c421c9d69cbe30182e270f2c553e6dc1148549960a80
|
7
|
+
data.tar.gz: e714f703eaf7a62c644f2f32f39c650bec866c40a65c79880ccd070dba088356442331fb1a06a5587ce89996aea4896fa518ac21d63213314e244001a154fad3
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Robert Coleman
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Magnetize
|
2
|
+
|
3
|
+
CLI and library for generating Magento local.xml files.
|
4
|
+
Generates both `app/etc/local.xml` and `errors/local.xml` from the a specified [TOML]() configuration file.
|
5
|
+
Also supports converting an existing Magento XML configuration file into a TOML file.
|
6
|
+
|
7
|
+
Prefixes the TOML data with the `type` of Magento configuration file so that multiple Magento `local.xml` files can be stored in a common configuration and then seperate files be generated larter.
|
8
|
+
|
9
|
+
Supports arbitrary values in the both the `local.xml` and toml config, so new configration can be added without prior knowlege.
|
10
|
+
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'magnetize'
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install magnetize
|
21
|
+
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### CLI
|
26
|
+
|
27
|
+
* `$ magnetize help`
|
28
|
+
|
29
|
+
### Library
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'magnetize'
|
33
|
+
|
34
|
+
opts = {
|
35
|
+
:types => {
|
36
|
+
'app' => {
|
37
|
+
:magento => 'app/etc/local.xml',
|
38
|
+
:toml => 'config.toml'
|
39
|
+
},
|
40
|
+
'errors' => {
|
41
|
+
:magento => 'errors/local.xml',
|
42
|
+
:toml => 'config.toml'
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
Magnetize::Convert.new.to_toml(opts)
|
48
|
+
|
49
|
+
# => {"app"=> "[app.config.admin.routers.adminhtml.args]\nfrontName = \"admin\"\n[app.config.global]\ndisable_local_modules = \"false\"\n[app.config.global.crypt]\nkey = \"foo\"\n[app.config.global.install]\ndate = \"Tue, 04 Feb 2014\"...", "errors"=> "..."}
|
50
|
+
|
51
|
+
Magnetize::Convert.new.to_magento(opts)
|
52
|
+
|
53
|
+
# => {"app"=> "<config><admin><routers><adminhtml><args><frontName>admin</frontName></args></adminhtml></routers></admin><global><disable_local_modules>false</disable_local_modules><crypt><key>foo</key></crypt><install><date>Tues, 04 Feb 2014...," "error"=> ".."}
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
## Version 1
|
59
|
+
|
60
|
+
Version 1 is functionally equivalent in that it generates `local.xml` files from `ENV`. However it relies on all configuration values being present in the template which it's output to. This means it's inflexible when dealing with new configuration options.
|
61
|
+
|
62
|
+
Version 2 is a complete re-write and as such is API incompatable with V1. V1 is available here on [this branch](https://github.com/rjocoleman/magnetize/tree/v1)
|
63
|
+
|
64
|
+
|
65
|
+
## Contributing
|
66
|
+
|
67
|
+
1. Fork it ( http://github.com/<my-github-username>/magnetize/fork )
|
68
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
69
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
70
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
71
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/magnetize
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Magnetize
|
4
|
+
class CLI < Thor
|
5
|
+
default_task :help
|
6
|
+
|
7
|
+
desc 'to_magento', 'Write Magento XML from TOML config'
|
8
|
+
method_option :type, :type => :string, :required => false, :desc => 'Type of Magento config (e.g. app, errors). TOML is pulled from this prefix.' # ['app', 'errors']
|
9
|
+
method_option :input, :type => :string, :required => false, :desc => 'Path to input TOML file' # local.toml
|
10
|
+
method_option :output, :type => :string, :required => false, :desc => 'Path to output XML file' # app/etc/local.xml
|
11
|
+
method_option :force, :type => :boolean, :required => false, :desc => 'Overwrite existing output file'
|
12
|
+
def to_magento
|
13
|
+
unless options[:type] && options[:input] && options[:output]
|
14
|
+
Magnetize::Convert.new.to_magento write: true
|
15
|
+
else
|
16
|
+
Magnetize::Convert.new.to_magento write: true, types: { options[:type] => { :magento => options[:output], :toml => options[:input] }}
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'to_toml', 'Write TOML from existing Magento config'
|
22
|
+
method_option :type, :type => :string, :required => false, :desc => 'Type of Magento config (e.g. app, errors). Used as prefix in TOML.' # ['app', 'errors']
|
23
|
+
method_option :input, :type => :string, :required => false, :desc => 'Path to input XML file' # app/etc/local.xml
|
24
|
+
method_option :output, :type => :string, :required => false, :desc => 'Path to output TOML file' # local.toml
|
25
|
+
method_option :force, :type => :boolean, :required => false, :desc => 'Overwrite existing output file'
|
26
|
+
def to_toml
|
27
|
+
unless options[:type] && options[:input] && options[:output]
|
28
|
+
Magnetize::Convert.new.to_toml write: true
|
29
|
+
else
|
30
|
+
Magnetize::Convert.new.to_toml write: true, types: { options[:type] => { :magento => options[:input], :toml => options[:output] }}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'toml'
|
2
|
+
require 'active_support/core_ext/hash'
|
3
|
+
require 'gyoku'
|
4
|
+
require 'thor'
|
5
|
+
|
6
|
+
module Magnetize
|
7
|
+
class Convert < Thor
|
8
|
+
include Thor::Shell
|
9
|
+
|
10
|
+
DEFAULTS = {
|
11
|
+
:force => false,
|
12
|
+
:write => false,
|
13
|
+
:types => {
|
14
|
+
'app' => {
|
15
|
+
:magento => 'app/etc/local.xml',
|
16
|
+
:toml => 'config.toml'
|
17
|
+
},
|
18
|
+
'errors' => {
|
19
|
+
:magento => 'errors/local.xml',
|
20
|
+
:toml => 'config.toml'
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
no_commands do
|
26
|
+
def to_magento(options = {})
|
27
|
+
options = DEFAULTS.merge(options)
|
28
|
+
result = {}
|
29
|
+
options[:types].each do |type, config|
|
30
|
+
input = File.expand_path(config[:toml])
|
31
|
+
output = File.expand_path(config[:magento])
|
32
|
+
hash = read_toml(input)
|
33
|
+
xml = make_xml(hash[type.to_sym])
|
34
|
+
if options[:write]
|
35
|
+
write(output, xml, options[:force])
|
36
|
+
else
|
37
|
+
result[type] = xml
|
38
|
+
end
|
39
|
+
end
|
40
|
+
return result unless options[:write]
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_toml(options = {})
|
44
|
+
options = DEFAULTS.merge(options)
|
45
|
+
result = {}
|
46
|
+
options[:types].each do |type, config|
|
47
|
+
input = File.expand_path(config[:magento])
|
48
|
+
output = File.expand_path(config[:toml])
|
49
|
+
hash = { type.to_sym => read_xml(input) }
|
50
|
+
toml = make_toml(hash)
|
51
|
+
if options[:write]
|
52
|
+
write(output, toml, options[:force])
|
53
|
+
else
|
54
|
+
result[type] = toml
|
55
|
+
end
|
56
|
+
end
|
57
|
+
return result unless options[:write]
|
58
|
+
end
|
59
|
+
|
60
|
+
end # no_commands
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def read_toml(path)
|
65
|
+
TOML.load_file(path, symbolize_keys: true)
|
66
|
+
end
|
67
|
+
|
68
|
+
def make_toml(hash)
|
69
|
+
TOML.dump(hash)
|
70
|
+
end
|
71
|
+
|
72
|
+
def read_xml(path)
|
73
|
+
Hash.from_xml(IO.read(path))
|
74
|
+
end
|
75
|
+
|
76
|
+
def make_xml(hash)
|
77
|
+
Gyoku.xml(hash, { :key_converter => :none, :builder => { :indent => 2 } })
|
78
|
+
end
|
79
|
+
|
80
|
+
def write(path, content, force=false)
|
81
|
+
FileUtils.mkdir_p(File.dirname(path))
|
82
|
+
unless force
|
83
|
+
if File.exists?(path)
|
84
|
+
say("#{path} already exists. ", :red)
|
85
|
+
abort("----> Skipped #{File.basename(path)}") if no?("Overwrite? (y/N):", :yellow)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
File.open(path, 'w') {|f| f.write(content)}
|
89
|
+
puts "----> Wrote #{File.basename(path)}"
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# yuck, bad bad hack
|
96
|
+
module TOML
|
97
|
+
class Dumper
|
98
|
+
def to_toml(obj)
|
99
|
+
case
|
100
|
+
when obj.is_a?(Time)
|
101
|
+
obj.strftime('%Y-%m-%dT%H:%M:%SZ')
|
102
|
+
when obj.nil?
|
103
|
+
obj = '""'
|
104
|
+
else
|
105
|
+
obj.inspect
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/lib/magnetize.rb
ADDED
data/magnetize.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'magnetize/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'magnetize'
|
8
|
+
spec.version = Magnetize::VERSION
|
9
|
+
spec.authors = ['Robert Coleman']
|
10
|
+
spec.email = ['github@robert.net.nz']
|
11
|
+
spec.summary = %q{CLI/library for generating Magento local.xml files}
|
12
|
+
spec.description = %q{CLI/library for generating Magento local.xml files}
|
13
|
+
spec.homepage = 'https://github.com/rjocoleman/magnetize/'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'pry'
|
24
|
+
|
25
|
+
spec.add_dependency 'thor', '~> 0.18'
|
26
|
+
spec.add_dependency 'toml-rb', '~> 0.1'
|
27
|
+
spec.add_dependency 'activesupport', '~> 4.0'
|
28
|
+
spec.add_dependency 'gyoku', '~> 1.1'
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: magnetize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Coleman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.18'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.18'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: toml-rb
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.1'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activesupport
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: gyoku
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.1'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.1'
|
111
|
+
description: CLI/library for generating Magento local.xml files
|
112
|
+
email:
|
113
|
+
- github@robert.net.nz
|
114
|
+
executables:
|
115
|
+
- magnetize
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- .gitignore
|
120
|
+
- .ruby-version
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- bin/magnetize
|
126
|
+
- lib/magnetize.rb
|
127
|
+
- lib/magnetize/cli.rb
|
128
|
+
- lib/magnetize/convert.rb
|
129
|
+
- lib/magnetize/version.rb
|
130
|
+
- magnetize.gemspec
|
131
|
+
homepage: https://github.com/rjocoleman/magnetize/
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata: {}
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - '>='
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.0.14
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: CLI/library for generating Magento local.xml files
|
155
|
+
test_files: []
|