togglate 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c7a17708de8171ece04a35fe3cb48503252f276d
4
+ data.tar.gz: 041375d65bd90df01849fdc07724880e125f0583
5
+ SHA512:
6
+ metadata.gz: 426662553eede9a73a7b0e1cd895db309eb7a5c7f8cbc7e59d39922df5efde19ba4de05009cc01e476b7a5d27815631a7a679d9c05d3050d6a0cde0f73da3cd1
7
+ data.tar.gz: 3c47ff9fdaef373c6988a4abe30803b1d872dfd18bd9710e074e91ce1888643ffce7f64c0a002f02c2da5c119e7dfb3e324c8b7fd561c2bfa9b0583d0c361295
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in togglate.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 kyoendo
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,29 @@
1
+ # Togglate
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'togglate'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install togglate
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/togglate/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/togglate ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'togglate'
4
+
5
+ Togglate::CLI.start(ARGV)
@@ -0,0 +1,36 @@
1
+ class Togglate::BlockWrapper
2
+ def initialize(text,
3
+ space_re:/^\s*$/,
4
+ chunk_exceptions:[/^```/],
5
+ wrapper:%W([translation\ here]\n```original ```),
6
+ wrap_exceptions:[/^```/, /^\s{4}/], **opts)
7
+ @text = text
8
+ @space_re = space_re
9
+ @chunk_exceptions = chunk_exceptions
10
+ @wrapper = wrapper
11
+ @wrap_exceptions = wrap_exceptions
12
+ end
13
+
14
+ def run
15
+ wrap_with chunk_by_space
16
+ end
17
+
18
+ private
19
+ def chunk_by_space
20
+ in_block = false
21
+ @text.each_line.chunk do |line|
22
+ in_block = !in_block if @chunk_exceptions.any? { |ex| line.match ex }
23
+ !line.match(@space_re).nil? && !in_block
24
+ end
25
+ end
26
+
27
+ def wrap_with(chunks)
28
+ chunks.inject([]) do |m, (is_space, lines)|
29
+ if is_space || @wrap_exceptions.any? { |ex| lines[0].match ex }
30
+ m.push *lines
31
+ else
32
+ m.push @wrapper[0], "\n", *lines, @wrapper[1], "\n"
33
+ end
34
+ end.join
35
+ end
36
+ end
@@ -0,0 +1,20 @@
1
+ require "thor"
2
+
3
+ module Togglate
4
+ class CLI < Thor
5
+ desc "create FILE", "Create a base file for translation from a original file"
6
+ option :toggle_code, aliases:'-t', default:true
7
+ option :target, type: :string
8
+ option :show_text, aliases:'-s', type: :string
9
+ option :hide_text, aliases:'-h', type: :string
10
+ option :wrapper, type: :array
11
+ def create(file)
12
+ opts = options.inject({}) { |h, (k,v)| h[k.intern] = v; h } # symbolize keys
13
+ if wrapper = options[:wrapper]
14
+ wrapper.map! { |wr| wr.gsub(/\\n/, "\n") }
15
+ opts.update(wrapper:wrapper)
16
+ end
17
+ puts Togglate.create(file, opts)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Togglate
2
+ VERSION = "0.0.1"
3
+ end
data/lib/togglate.rb ADDED
@@ -0,0 +1,43 @@
1
+ require "togglate/version"
2
+ require "togglate/block_wrapper"
3
+ require "togglate/cli"
4
+
5
+ module Togglate
6
+ def self.create(file, opts={})
7
+ text = File.read(file)
8
+ wrapped = BlockWrapper.new(text, opts).run
9
+ if opts[:toggle_code]
10
+ code = toggle_code(opts)
11
+ [wrapped, code].join("\n")
12
+ else
13
+ wrapped
14
+ end
15
+ rescue => e
16
+ STDERR.puts "something go wrong. #{e}"
17
+ exit
18
+ end
19
+
20
+ def self.toggle_code(target:%($("pre[lang='original']")), show_text:"*", hide_text:"hide", **opts)
21
+ <<-"CODE"
22
+ <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
23
+ <script>
24
+ function createToggleLinks(target, showText, hideText) {
25
+ var link = "<span><a href='#' onclick='javascript:return false;' class='toggleLink'>" + showText + "</a></span>";
26
+ target.hide().prev().append(link);
27
+ $('.toggleLink').click(
28
+ function() {
29
+ if ($(this).text()==showText) {
30
+ $(this).parent().parent().next(target).slideDown(200);
31
+ $(this).text(hideText);
32
+ } else {
33
+ $(this).parent().parent().next(target).slideUp(200);
34
+ $(this).text(showText);
35
+ };
36
+ });
37
+ }
38
+ var element = #{target};
39
+ createToggleLinks(element, "#{show_text}", "#{hide_text}");
40
+ </script>
41
+ CODE
42
+ end
43
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'togglate'
3
+
4
+ class String
5
+ def ~
6
+ margin = scan(/^ +/).map(&:size).min
7
+ gsub(/^ {#{margin}}/, '')
8
+ end
9
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Togglate do
4
+ it 'should have a version number' do
5
+ Togglate::VERSION.should_not be_nil
6
+ end
7
+ end
8
+
9
+ describe Togglate::BlockWrapper do
10
+ describe "#chunk_by_space" do
11
+ it "returns chunked array" do
12
+ text = "#title\n\n\ntext\n"
13
+ wrapper = Togglate::BlockWrapper.new(text)
14
+ exp = [[false, ["#title\n"]],
15
+ [true, ["\n", "\n"]],
16
+ [false, ["text\n"]]]
17
+ expect(wrapper.send(:chunk_by_space).to_a).to eq exp
18
+ end
19
+ end
20
+
21
+ describe "#wrap_with" do
22
+ it "returns wrapped text" do
23
+ text = "#title\n\n\ntext\n"
24
+ wrapper = Togglate::BlockWrapper.new(text)
25
+ chunks = wrapper.send(:chunk_by_space)
26
+ exp = "<translation here>\n```original\n#title\n```\n\n\n<translation here>\n```original\ntext\n```\n"
27
+ expect(wrapper.send(:wrap_with, chunks)).to eq exp
28
+ end
29
+ end
30
+ end
data/togglate.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'togglate/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "togglate"
8
+ spec.version = Togglate::VERSION
9
+ spec.authors = ["kyoendo"]
10
+ spec.email = ["postagie@gmail.com"]
11
+ spec.summary = %q{Create base text for translation, in which original is togglable}
12
+ spec.homepage = "https://github.com/melborne/togglate"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "thor"
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: togglate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - kyoendo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - postagie@gmail.com
72
+ executables:
73
+ - togglate
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/togglate
85
+ - lib/togglate.rb
86
+ - lib/togglate/block_wrapper.rb
87
+ - lib/togglate/cli.rb
88
+ - lib/togglate/version.rb
89
+ - spec/spec_helper.rb
90
+ - spec/togglate_spec.rb
91
+ - togglate.gemspec
92
+ homepage: https://github.com/melborne/togglate
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.2.0
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Create base text for translation, in which original is togglable
116
+ test_files:
117
+ - spec/spec_helper.rb
118
+ - spec/togglate_spec.rb
119
+ has_rdoc: