myhtml2haml 0.0.0 → 1.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 +4 -4
- data/README.md +45 -8
- data/bin/myhtml2haml +3 -0
- data/lib/myhtml2haml.rb +93 -2
- data/lib/myhtml2haml/version.rb +1 -1
- data/myhtml2haml.gemspec +7 -6
- metadata +35 -5
- data/.gitignore +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0036c730171557438b7bc290fb56eca72aba8478
|
4
|
+
data.tar.gz: 81fea5a341d29ad57ccf51fa9e29a00f737aff92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '05168d3238b201725603d4b92d18cba906e6042029de3cc1784257448aa0ea24791fc1fa805ed515e284023cc2536013a607de4ce2cf5b122ca890bf1b18c1dc'
|
7
|
+
data.tar.gz: 1d1b4bb95bca6667cb37d578ba4d4c32ae794556264027956564266bdbb4c9d95f105e867935fd4e233184c19438048ef12c819f6df1e2cdef14d2117bf1779a
|
data/README.md
CHANGED
@@ -1,8 +1,34 @@
|
|
1
1
|
# Myhtml2haml
|
2
2
|
|
3
|
-
|
3
|
+
A [html2haml](https://github.com/haml/html2haml) wrapper for converting html templates to haml templates.
|
4
4
|
|
5
|
-
|
5
|
+
## Disclaimer
|
6
|
+
|
7
|
+
`use at your own risk!` I am not responsible if anything goes wrong while using this gem. If you are not sure it will work for you, install it on a vagrant vm and give it a try there. The Vagrantfile that is in this repo will take care of configuring a useable vm.
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
`myhtml2haml` - displays the help menu
|
12
|
+
|
13
|
+
`myhtml2haml convert` - safe file conversion (does not delete original files
|
14
|
+
|
15
|
+
`myhtml2haml covert --pattern=[.erb|.html]` - Converts files with `.html.erb` extension to `.html.haml`
|
16
|
+
|
17
|
+
> Will match .erb, .html.erb, .html, and .rhtml
|
18
|
+
|
19
|
+
> Alias `-p` for `--pattern`
|
20
|
+
|
21
|
+
`myhtml2haml covert --dir_prefix` - Converts files appending parent directory name to the converted files
|
22
|
+
|
23
|
+
> Given the file app/index.html.erb the output would be app/app_index.html.haml
|
24
|
+
|
25
|
+
> Alias `-d` for `--dir_prefix`
|
26
|
+
|
27
|
+
`myhtml2haml convert --obliviate=true` - Dangerous conversion (deletes original files)
|
28
|
+
|
29
|
+
> Alias `-o` for `--obliviate`
|
30
|
+
|
31
|
+
`myhtml2haml reset` - Remove ALL haml files BE CAREFULL!!!!
|
6
32
|
|
7
33
|
## Installation
|
8
34
|
|
@@ -20,16 +46,27 @@ Or install it yourself as:
|
|
20
46
|
|
21
47
|
$ gem install myhtml2haml
|
22
48
|
|
23
|
-
##
|
49
|
+
## Development
|
24
50
|
|
25
|
-
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
52
|
|
27
|
-
|
53
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
28
54
|
|
29
|
-
|
55
|
+
## Releasing
|
56
|
+
To release a new version,
|
57
|
+
* update the version number in `version.rb`
|
58
|
+
* tag the the code `git tag v1.0.0`
|
59
|
+
* push the tag `git push --tags`
|
60
|
+
* then run `bundle exec rake build`
|
61
|
+
* `gem push pkg/myhtml2haml-version`
|
30
62
|
|
31
|
-
|
63
|
+
Which will push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
64
|
|
33
65
|
## Contributing
|
34
66
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
67
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/vmcilwain/myhtml2haml. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
68
|
+
|
69
|
+
|
70
|
+
## License
|
71
|
+
|
72
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/bin/myhtml2haml
ADDED
data/lib/myhtml2haml.rb
CHANGED
@@ -1,5 +1,96 @@
|
|
1
|
-
|
1
|
+
require_relative "myhtml2haml/version"
|
2
|
+
require 'thor'
|
3
|
+
require 'html2haml'
|
4
|
+
require 'html2haml/exec'
|
2
5
|
|
3
6
|
module Myhtml2haml
|
4
|
-
|
7
|
+
class Myhtml2haml < Thor
|
8
|
+
include Thor::Actions
|
9
|
+
|
10
|
+
no_commands do
|
11
|
+
def delete_file(file)
|
12
|
+
File.delete file
|
13
|
+
end
|
14
|
+
|
15
|
+
def file_status(file)
|
16
|
+
say "Converting: #{file}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def warning
|
20
|
+
exit_app unless allowed?
|
21
|
+
end
|
22
|
+
|
23
|
+
def exit_app
|
24
|
+
abort('Aborting...')
|
25
|
+
end
|
26
|
+
|
27
|
+
def allowed?
|
28
|
+
say "Location: #{Dir.pwd}"
|
29
|
+
yes?("Are you sure? This action can't be undone")
|
30
|
+
end
|
31
|
+
|
32
|
+
def formatted_output(file)
|
33
|
+
name = ""
|
34
|
+
name << "#{directory_name(file)}/"
|
35
|
+
name << "#{directory_name(file)}_" if options[:dir_prefix]
|
36
|
+
name << "#{file_name(file)}.html.haml"
|
37
|
+
name+=".dup" if File.exist?(name)
|
38
|
+
name
|
39
|
+
end
|
40
|
+
|
41
|
+
def directory_name(file)
|
42
|
+
File.basename(File.dirname(file))
|
43
|
+
end
|
44
|
+
|
45
|
+
def file_name(file)
|
46
|
+
File.basename(file.split(/\./).first)
|
47
|
+
end
|
48
|
+
|
49
|
+
def convert_file(file)
|
50
|
+
file_status(file)
|
51
|
+
unless File.directory?(file)
|
52
|
+
Html2haml::Exec::HTML2Haml.new([file, formatted_output(file)]).parse
|
53
|
+
@file_counts[:converted] += 1
|
54
|
+
delete_file(file) if options[:obliviate]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def closing_status
|
59
|
+
say 'Files Converted:'
|
60
|
+
@file_counts.each {|key, value| say "#{key}: #{value}"}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
method_option :dir_prefix, type: :boolean, default: false, aliases: :d
|
65
|
+
method_option :obliviate, type: :boolean, default: false, aliases: :o
|
66
|
+
method_option :pattern, type: :string, aliases: :p
|
67
|
+
desc 'convert', 'Changes html templates to haml templates'
|
68
|
+
long_desc <<-LONGDESC
|
69
|
+
-d --dir_prefix
|
70
|
+
Append parent directory name to file on conversion.
|
71
|
+
-o --obliviate
|
72
|
+
Destroy original file after conversion.
|
73
|
+
-p --pattern
|
74
|
+
The matching regexp of the file(s) to be converted.
|
75
|
+
example: -p [.erb|.rhtml] to convert files with .erb or .rhtml extension.
|
76
|
+
LONGDESC
|
77
|
+
def convert
|
78
|
+
warning if options[:obliviate]
|
79
|
+
|
80
|
+
files = Dir["**/*#{options[:pattern]}"]
|
81
|
+
@file_counts = {total: files.size, converted: 0}
|
82
|
+
files.each {|file| convert_file(file)}
|
83
|
+
closing_status
|
84
|
+
end
|
85
|
+
|
86
|
+
desc 'reset', 'Remove all haml templates'
|
87
|
+
def reset
|
88
|
+
warning
|
89
|
+
files = Dir['**/*.haml']
|
90
|
+
files.each {|file| File.delete file}
|
91
|
+
say "Files deleted: #{files.size}"
|
92
|
+
end
|
93
|
+
end
|
5
94
|
end
|
95
|
+
|
96
|
+
Myhtml2haml::Myhtml2haml.start(ARGV)
|
data/lib/myhtml2haml/version.rb
CHANGED
data/myhtml2haml.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.summary = %q{Convert html templates to haml templates}
|
13
13
|
spec.description = %q{An html2haml wrapper for converting html templates to haml templates}
|
14
14
|
spec.homepage = "https://github.com/vmcilwain/myhtml2haml"
|
15
|
-
|
15
|
+
spec.license = "MIT"
|
16
16
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
17
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
18
|
if spec.respond_to?(:metadata)
|
@@ -22,13 +22,14 @@ Gem::Specification.new do |spec|
|
|
22
22
|
"public gem pushes."
|
23
23
|
end
|
24
24
|
|
25
|
-
spec.files =
|
26
|
-
|
27
|
-
|
28
|
-
spec.
|
29
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.files = Dir["{bin,lib}/**/*", "LICENSE.txt", "README.md", 'Rakefile', 'Gemfile', 'myhtml2haml.gemspec']
|
26
|
+
spec.test_files = Dir["spec/**/*"]
|
27
|
+
spec.bindir = "bin"
|
28
|
+
spec.executables = ['myhtml2haml']
|
30
29
|
spec.require_paths = ["lib"]
|
31
30
|
|
32
31
|
spec.add_development_dependency "bundler", "~> 1.15"
|
33
32
|
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_dependency 'html2haml', '~> 2.2'
|
34
|
+
spec.add_dependency 'thor', '~> 0.20'
|
34
35
|
end
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: myhtml2haml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vell
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2017-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
@@ -38,24 +38,54 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: html2haml
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.2'
|
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.20'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.20'
|
41
69
|
description: An html2haml wrapper for converting html templates to haml templates
|
42
70
|
email:
|
43
71
|
- lovell.mcilwain@gmail.com
|
44
|
-
executables:
|
72
|
+
executables:
|
73
|
+
- myhtml2haml
|
45
74
|
extensions: []
|
46
75
|
extra_rdoc_files: []
|
47
76
|
files:
|
48
|
-
- ".gitignore"
|
49
77
|
- Gemfile
|
50
78
|
- README.md
|
51
79
|
- Rakefile
|
52
80
|
- bin/console
|
81
|
+
- bin/myhtml2haml
|
53
82
|
- bin/setup
|
54
83
|
- lib/myhtml2haml.rb
|
55
84
|
- lib/myhtml2haml/version.rb
|
56
85
|
- myhtml2haml.gemspec
|
57
86
|
homepage: https://github.com/vmcilwain/myhtml2haml
|
58
|
-
licenses:
|
87
|
+
licenses:
|
88
|
+
- MIT
|
59
89
|
metadata:
|
60
90
|
allowed_push_host: https://rubygems.org
|
61
91
|
post_install_message:
|