mjollnir 0.1.0 → 0.1.1

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.
Files changed (4) hide show
  1. data/README.md +22 -20
  2. data/lib/mjollnir/version.rb +1 -1
  3. data/lib/mjollnir.rb +22 -24
  4. metadata +2 -2
data/README.md CHANGED
@@ -4,32 +4,33 @@ A gem for prepending and appending text to rails generated files.
4
4
 
5
5
  ## Usage
6
6
 
7
- add "gem 'mjollnir'" to your Gemfile
7
+ add `gem 'mjollnir'` to your Gemfile
8
8
 
9
- Create a directory in your lib directory called "mjollnir".
9
+ Create a directory in your lib directory called `mjollnir`.
10
10
  Add four files to this directory:
11
- 1. append.rb - this file contains instructions for insertions at the end of generated files.
12
- 2. prepend.rb - this file contains instructions for insertions at the beinning of generated files.
13
- 3. comment_starts.csv - put lines in this file when you need to create block comments in different file types. For example, use a line, "rb,=start" for the start of a ruby block. When generating text in the append.rb or prepend.rb files, use <%= universal_comment_start %> to declare the start of any comment block, so long as that file type has been included in comment_starts.csv.
14
- 4. comment_ends.csv - much like comment_starts.csv, but this file is for comment block ends in generated text. For example, use "erb,-->" to end a comment block in an erb file. When generating text in the append.rb or prepend.rb files, use <%= universal_comment_end %> to declare the end of any comment block, so long as that file type has been included in comment.ends.csv.
11
+ 1. `append.rb` - this file contains instructions for insertions at the end of generated files.
12
+ 2. `prepend.rb` - this file contains instructions for insertions at the beinning of generated files.
13
+ 3. `comment_starts.csv` - put lines in this file when you need to create block comments in different file types. For example, use a line, `rb,=start` for the start of a ruby block. When generating text in the `append.rb` or `prepend.rb` files, use `<%= universal_comment_start %>` to declare the start of any comment block, so long as that file type has been included in `comment_starts.csv`.
14
+ 4. `comment_ends.csv` - much like `comment_starts.csv`, but this file is for comment block ends in generated text. For example, use `erb,-->` to end a comment block. in an erb file. When generating text in the `append.rb` or `prepend.rb` files, use `<%= universal_comment_end %>` to declare the end of any comment block, so long as that file type has been included in `comment.ends.csv`.
15
15
 
16
16
  ## Variables
17
17
 
18
- The following usable variables for append.rb and prepend.rb:
18
+ The following usable variables for `append.rb` and `prepend.rb`:
19
19
 
20
- target_file_type - the target file's type (rb, erb, coffee, etc.)
21
- target_file - the target file directory, name and extention
22
- universal_comment_start - the target file's file type comment block start, so long as it is declared in the comment_starts.csv file in the lib/mjollnir directory
23
- universal_comment_end - the taret file's file type comment block end, so long as it is declared in the comment_ends.csv file in the lib/mjollnir directory
20
+ * `target_file_type` - the target file's type (`rb`, `erb`, `coffee`, etc.)
21
+ * `target_file` - the target file directory, name and extention
22
+ * `universal_comment_start` - the target file's file type comment block start, so long as it is declared in the `comment_starts.csv` file in the `lib/mjollnir` directory.
23
+ * `universal_comment_end` - the taret file's file type comment block end, so long as it is declared in the `comment_ends.csv` file in the `lib/mjollnir` directory.
24
24
 
25
25
  ## Example
26
26
 
27
- prepend.rb for adding MIT license:
28
- <%= universal_comment_start %>
27
+ `prepend.rb` for adding MIT license:
28
+ ```Ruby
29
+ <%= universal_comment_start %>
29
30
 
30
- <%= target_file %>
31
+ <%= target_file %>
31
32
 
32
- Copyright (c)<%= Time.now.year %> 123 Fake Co.
33
+ Copyright (c)<%= Time.now.year %> 123 Fake Co.
33
34
 
34
35
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
35
36
 
@@ -38,9 +39,10 @@ prepend.rb for adding MIT license:
38
39
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39
40
 
40
41
  Generated at: <%= Time.now %>
41
- <%= universal_comment_end %>
42
-
43
- comment_ends.csv for common file types:
42
+ <%= universal_comment_end %>
43
+ ```
44
+ `comment_ends.csv` for common file types:
45
+ ```
44
46
  rb,=end
45
47
  scss,*/
46
48
  js,*/
@@ -49,7 +51,7 @@ coffee,###
49
51
  css,*/
50
52
  erb,-->
51
53
  html,-->
52
-
54
+ ```
53
55
 
54
56
 
55
57
  ## Contributing
@@ -63,4 +65,4 @@ html,-->
63
65
  ## Planned changes
64
66
 
65
67
  1. Version 0.2.0 will add a generator for the prepend, and append ruby files, as well as for the two csvs.
66
- 2. The change after that will be to automate some testing.
68
+ 2. The change after that will be to automate some testing.
@@ -1,3 +1,3 @@
1
1
  module Mjollnir
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/mjollnir.rb CHANGED
@@ -1,35 +1,33 @@
1
1
  require "mjollnir/version"
2
2
 
3
3
  module Mjollnir
4
- def self.include(base)
5
- base.extend(ClassMethods)
6
- end
7
-
8
4
  def template(source, *args, &block)
9
5
  inside_template do
10
6
  super
11
- if File.exists?("lib/mjollnir") && File.directory?("lib/mjollnir")
12
- target_file = args.first|| source.sub(/\.tt$/, '')
13
-
14
- prependable = ERB.new(::File.binread("lib/mjollnir/prepend.rb"), nil, '-', '@output_buffer')
15
- appendable = ERB.new(::File.binread("lib/mjollnir/append.rb"), nil, '-', '@output_buffer')
16
7
 
17
- target_file_type = target_file.split('.').pop
8
+ mjollnir_root = "lib/mjollnir"
18
9
 
19
- commentstarts = Hash[*File.read('lib/mjollnir/comment_starts.csv').split(/[, \n]+/)]
20
- commentends = Hash[*File.read('lib/mjollnir/comment_ends.csv').split(/[, \n]+/)]
21
- universal_comment_start = commentstarts[target_file_type]
22
- universal_comment_end = commentends[target_file_type]
23
-
24
- # Bind the variables to the ERB results
25
- preargs = [
26
- prependable.result(binding)
27
- ]
28
- postargs = [
29
- appendable.result(binding)
30
- ]
31
- prepend_to_file(target_file, *preargs, &block)
32
- append_to_file(target_file, *postargs, &block)
10
+ if File.exists?(mjollnir_root) && File.directory?(mjollnir_root)
11
+ target_file = args.first|| source.sub(/\.tt$/, '')
12
+ target_file_type = target_file.split('.').pop
13
+
14
+ if File.exists?(mjollnir_root + "/comment_starts.csv")
15
+ commentstarts = Hash[*File.read(mjollnir_root + '/comment_starts.csv').split(/[, \n]+/)]
16
+ universal_comment_start = commentstarts[target_file_type]
17
+ end
18
+ if File.exists?(mjollnir_root + "/comment_ends.csv")
19
+ commentends = Hash[*File.read(mjollnir_root + '/comment_ends.csv').split(/[, \n]+/)]
20
+ universal_comment_end = commentends[target_file_type]
21
+ end
22
+
23
+ if File.exists?(mjollnir_root + "/prepend.rb")
24
+ preargs = [ ERB.new(::File.binread(mjollnir_root + "/prepend.rb"), nil, '-', '@output_buffer').result(binding) ]
25
+ prepend_to_file(target_file, *preargs, &block)
26
+ end
27
+ if File.exists?(mjollnir_root + "/append.rb")
28
+ postargs = [ ERB.new(::File.binread(mjollnir_root + "/append.rb"), nil, '-', '@output_buffer').result(binding) ]
29
+ append_to_file(target_file, *postargs, &block)
30
+ end
33
31
  end
34
32
  end
35
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mjollnir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-09 00:00:00.000000000 Z
12
+ date: 2012-10-10 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A gem for prepending and appending generated files from any rails generator,
15
15
  though the power of Thor.