pig_latin 0.0.1 → 0.0.2

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.
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ gem "rails", "~> 3.0"
@@ -0,0 +1,85 @@
1
+ GEM
2
+ specs:
3
+ actionmailer (3.2.13)
4
+ actionpack (= 3.2.13)
5
+ mail (~> 2.5.3)
6
+ actionpack (3.2.13)
7
+ activemodel (= 3.2.13)
8
+ activesupport (= 3.2.13)
9
+ builder (~> 3.0.0)
10
+ erubis (~> 2.7.0)
11
+ journey (~> 1.0.4)
12
+ rack (~> 1.4.5)
13
+ rack-cache (~> 1.2)
14
+ rack-test (~> 0.6.1)
15
+ sprockets (~> 2.2.1)
16
+ activemodel (3.2.13)
17
+ activesupport (= 3.2.13)
18
+ builder (~> 3.0.0)
19
+ activerecord (3.2.13)
20
+ activemodel (= 3.2.13)
21
+ activesupport (= 3.2.13)
22
+ arel (~> 3.0.2)
23
+ tzinfo (~> 0.3.29)
24
+ activeresource (3.2.13)
25
+ activemodel (= 3.2.13)
26
+ activesupport (= 3.2.13)
27
+ activesupport (3.2.13)
28
+ i18n (= 0.6.1)
29
+ multi_json (~> 1.0)
30
+ arel (3.0.2)
31
+ builder (3.0.4)
32
+ erubis (2.7.0)
33
+ hike (1.2.2)
34
+ i18n (0.6.1)
35
+ journey (1.0.4)
36
+ json (1.7.7)
37
+ mail (2.5.3)
38
+ i18n (>= 0.4.0)
39
+ mime-types (~> 1.16)
40
+ treetop (~> 1.4.8)
41
+ mime-types (1.22)
42
+ multi_json (1.7.2)
43
+ polyglot (0.3.3)
44
+ rack (1.4.5)
45
+ rack-cache (1.2)
46
+ rack (>= 0.4)
47
+ rack-ssl (1.3.3)
48
+ rack
49
+ rack-test (0.6.2)
50
+ rack (>= 1.0)
51
+ rails (3.2.13)
52
+ actionmailer (= 3.2.13)
53
+ actionpack (= 3.2.13)
54
+ activerecord (= 3.2.13)
55
+ activeresource (= 3.2.13)
56
+ activesupport (= 3.2.13)
57
+ bundler (~> 1.0)
58
+ railties (= 3.2.13)
59
+ railties (3.2.13)
60
+ actionpack (= 3.2.13)
61
+ activesupport (= 3.2.13)
62
+ rack-ssl (~> 1.3.2)
63
+ rake (>= 0.8.7)
64
+ rdoc (~> 3.4)
65
+ thor (>= 0.14.6, < 2.0)
66
+ rake (10.0.4)
67
+ rdoc (3.12.2)
68
+ json (~> 1.4)
69
+ sprockets (2.2.2)
70
+ hike (~> 1.2)
71
+ multi_json (~> 1.0)
72
+ rack (~> 1.0)
73
+ tilt (~> 1.1, != 1.3.0)
74
+ thor (0.18.1)
75
+ tilt (1.3.7)
76
+ treetop (1.4.12)
77
+ polyglot
78
+ polyglot (>= 0.3.1)
79
+ tzinfo (0.3.37)
80
+
81
+ PLATFORMS
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ rails (~> 3.0)
@@ -0,0 +1,28 @@
1
+ Anslatetray ouryay Ailsray appway intoway igpay atinlay! (Translate your Rails app into pig latin!)
2
+ =====
3
+
4
+ Add a pig latin translation layer to your Rails app!) Includes a rake task to translate all of your i18n locale configurations to pig latin!
5
+
6
+ Translate English to Pig Latin on the fly!
7
+ ----
8
+
9
+ PigLatin.translate("Always look on the bright side of life!")
10
+ => "Alwaysway ooklay onway ethay ightbray idesay ofway ifelay!"
11
+
12
+ You could use it in your before save callbacks to shove pig latin in your database!
13
+
14
+ Build a Pig Latin locale layer for i18n
15
+ ----
16
+ Use i18n? The pig_latin rake task can generate a pig latin locale (pgl) based on your English locale files.
17
+
18
+ rake pig_latin:translate["config/locales"]
19
+
20
+ It'll iterate through all of your en.yml files in that location and build a pig latin version. You can also specify a specific en.yml file to translate just that file!
21
+
22
+ Contributions
23
+ =====
24
+ Feel free to write specs. Submit a pull request and we'll see what happens!
25
+
26
+ Credits
27
+ =====
28
+ Copyright (c) 2013, developed and maintained by Steve Hodges, and is released under the open MIT Licence
@@ -0,0 +1,51 @@
1
+ class PigLatin
2
+
3
+ def self.translate(my_string)
4
+ my_string.is_a?(String) ? translate_string(my_string) : my_string
5
+ end
6
+
7
+ private #####################################################################
8
+
9
+ def self.translate_string(my_string)
10
+ my_string.split(/ /).map do |word|
11
+
12
+ capitalized = (word[0] == word[0].upcase)
13
+ punctuation = word[/\W+\z/]
14
+
15
+ punctuation_start = punctuation ? word.length - punctuation.length - 1 : -1
16
+ word = word[0..punctuation_start]
17
+
18
+ word = pig_latinitize(word).downcase
19
+ word = capitalize_first(word) if capitalized
20
+ "#{word}#{punctuation}"
21
+ end.join(" ")
22
+ end
23
+
24
+ def self.pig_latinitize(words)
25
+ words.split(/-/).map do |word|
26
+ if word[0].match(/[^aeiou]/i)
27
+ leading_consonants = word[/\A([^aeiou]+)/i]
28
+ word[leading_consonants.length..-1] + leading_consonants + "ay"
29
+ else
30
+ word + "way"
31
+ end
32
+ end.join("-")
33
+ end
34
+
35
+ def self.capitalize_first(string)
36
+ return string unless string.is_a? String
37
+ return string.upcase if string.length < 2
38
+ string.slice(0,1).capitalize + string.slice(1..-1)
39
+ end
40
+
41
+ def self.rails_present?
42
+ Object.const_defined? :Rails
43
+ end
44
+
45
+ end
46
+
47
+ if Object.const_defined? :Rails
48
+ require "pig_latin/railties"
49
+ else
50
+ require "yaml"
51
+ end
@@ -0,0 +1,5 @@
1
+ class LoadTasks < Rails::Railtie
2
+ rake_tasks do
3
+ Dir[File.join(File.dirname(__FILE__),'tasks/*.rake')].each { |f| load f }
4
+ end
5
+ end
@@ -0,0 +1,56 @@
1
+ namespace "pig_latin" do
2
+ desc "Use this task to translate config/locales dictionary into pig latin"
3
+ task :translate, :dir_or_file_to_translate do |t, args|
4
+ require 'cgi'
5
+ args.with_defaults(:dir_or_file_to_translate => "config/locales")
6
+ translate_locale(args[:dir_or_file_to_translate])
7
+ end
8
+ end
9
+
10
+ def translate(filename)
11
+ en_yml = YAML::load_file(filename)
12
+ target_filename = "pgl" + filename.match(/\/en([a-zA-Z-]*).yml/)[1]
13
+ dirname = filename.split("/")[0..-2].join("/")
14
+ translation = {target_filename => parse_element(en_yml).values.first}
15
+ File.open(dirname + "/#{target_filename}.yml", 'w:utf-8') do |f|
16
+ YAML::dump translation, f
17
+ end
18
+ end
19
+
20
+ def translate_locale(path)
21
+ path = "#{Rails.root}/#{path}" unless path.include? Rails.root.to_s
22
+ return translate(path) if File.exists?(path) && path.match("/\/en([a-zA-Z-]*).yml")
23
+
24
+ relevent_file_paths(path).each do |file_path|
25
+ if File.directory? file_path
26
+ translate(file_path + "/en.yml") if File.exists?(file_path + "/en.yml")
27
+ translate_locale file_path
28
+ elsif file_path.match("\/en([a-zA-Z-]*).yml")
29
+ puts file_path
30
+ translate file_path
31
+ end
32
+ end
33
+ end
34
+
35
+ def parse_element(element)
36
+ case element
37
+ when Hash
38
+ new_hash = {}
39
+ element.each {|k,v| new_hash[k] = parse_element(v)}
40
+ new_hash
41
+ when Array
42
+ element.map {|el| parse_element(element)}
43
+ when String
44
+ PigLatin.translate element
45
+ else
46
+ element
47
+ end
48
+ end
49
+
50
+ def relevent_file_paths(path)
51
+ Dir.new(path).entries.reject do |filename|
52
+ [".", ".."].include? filename
53
+ end.map do |filename|
54
+ "#{path}/#{filename}"
55
+ end
56
+ end
@@ -0,0 +1,13 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |s|
3
+ s.name = 'pig_latin'
4
+ s.version = '0.0.2'
5
+ s.authors = ['Steve Hodges']
6
+ s.email = ['sjhodges@gmail.com']
7
+ s.homepage = 'https://github.com/stevehodges/pig_latin'
8
+ s.summary = 'Pig Latin'
9
+ s.description = 'Anslatetray ouryay Ailsray appway otay Igpay Atinlay!! (Translate your Rails app to Pig Latin!) Includes a rake task to translate all of your i18n locale configurations to pig latin. Or, generate pig latin on the fly!'
10
+
11
+ s.files = `git ls-files`.split("\n")
12
+ s.require_paths = ['lib']
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pig_latin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -19,7 +19,14 @@ email:
19
19
  executables: []
20
20
  extensions: []
21
21
  extra_rdoc_files: []
22
- files: []
22
+ files:
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - README.md
26
+ - lib/pig_latin.rb
27
+ - lib/pig_latin/railties.rb
28
+ - lib/pig_latin/tasks/pig_latin.rake
29
+ - pig_latin.gemspec
23
30
  homepage: https://github.com/stevehodges/pig_latin
24
31
  licenses: []
25
32
  post_install_message: