myhtml2haml 0.0.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ab21101845e3db9574bcebe8ef737368703b761
4
- data.tar.gz: 3d18c2ac870d6e8be13f744eaff578caac277b70
3
+ metadata.gz: 0036c730171557438b7bc290fb56eca72aba8478
4
+ data.tar.gz: 81fea5a341d29ad57ccf51fa9e29a00f737aff92
5
5
  SHA512:
6
- metadata.gz: 8796aa8a3e049e8f05dbbd2caccc3249f26c80425c2fe48f51c50df224f28730d3a60235bb13bc69d5e76cc083738b1f4d3a2e022b2ea724ed50155b20943303
7
- data.tar.gz: 9f5263b83f457c975564545ad7d405a725a7938846e22608ce85a232156ac10ad36bd26979bc4afda6c3da2478569ef19663e457f3930a78af15c91ad502e079
6
+ metadata.gz: '05168d3238b201725603d4b92d18cba906e6042029de3cc1784257448aa0ea24791fc1fa805ed515e284023cc2536013a607de4ce2cf5b122ca890bf1b18c1dc'
7
+ data.tar.gz: 1d1b4bb95bca6667cb37d578ba4d4c32ae794556264027956564266bdbb4c9d95f105e867935fd4e233184c19438048ef12c819f6df1e2cdef14d2117bf1779a
data/README.md CHANGED
@@ -1,8 +1,34 @@
1
1
  # Myhtml2haml
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/myhtml2haml`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ A [html2haml](https://github.com/haml/html2haml) wrapper for converting html templates to haml templates.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
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
- ## Usage
49
+ ## Development
24
50
 
25
- TODO: Write usage instructions here
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
- ## Development
53
+ To install this gem onto your local machine, run `bundle exec rake install`.
28
54
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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/[USERNAME]/myhtml2haml.
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).
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/myhtml2haml'
@@ -1,5 +1,96 @@
1
- require "myhtml2haml/version"
1
+ require_relative "myhtml2haml/version"
2
+ require 'thor'
3
+ require 'html2haml'
4
+ require 'html2haml/exec'
2
5
 
3
6
  module Myhtml2haml
4
- # Your code goes here...
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)
@@ -1,3 +1,3 @@
1
1
  module Myhtml2haml
2
- VERSION = "0.0.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -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 = `git ls-files -z`.split("\x0").reject do |f|
26
- f.match(%r{^(test|spec|features)/})
27
- end
28
- spec.bindir = "exe"
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: 0.0.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vell
8
8
  autorequire:
9
- bindir: exe
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:
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/