linguist_ruby 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ require "linguist/client"
2
+ require "linguist/rails3/railtie" if defined?(Rails)
3
+
4
+ module Linguist
5
+ class << self
6
+ attr_accessor :environments, :protocol, :host, :username, :project
7
+
8
+ def configure
9
+ yield self
10
+ end
11
+
12
+ def default_value?(value)
13
+ value.start_with?(":")
14
+ end
15
+ end
16
+ end
@@ -1,7 +1,7 @@
1
1
  require 'rest_client'
2
2
  require 'uri'
3
3
  require 'time'
4
- require 'linguist/version'
4
+ require 'linguist_ruby/version'
5
5
  require 'vendor/okjson'
6
6
  require 'json'
7
7
  require 'linguist/models/projects'
@@ -25,22 +25,27 @@ class Linguist::Client
25
25
  "linguist-gem/#{version}"
26
26
  end
27
27
 
28
- attr_accessor :host, :user, :auth_token
28
+ attr_accessor :host, :user, :password
29
29
 
30
- def self.auth(user, password, host='lingui.st')
31
- client = new(user, password, host)
32
- OkJson.decode client.post('/sessions', { :email => user, :password => password }, :accept => 'json').to_s
30
+ def self.auth(options)
31
+ client = new(options)
32
+ OkJson.decode client.post('/sessions', {}, :accept => 'json').to_s
33
33
  end
34
34
 
35
- def initialize(user, auth_token, host='lingui.st')
36
- @user = user
37
- @auth_token = auth_token
38
- @host = host
35
+ def initialize(options)
36
+ @user = options[:username]
37
+ @password = options[:password]
38
+ @auth_token = options[:auth_token]
39
+ @host = options[:host] || 'lingui.st'
40
+ end
41
+
42
+ def credentials
43
+ @auth_token.nil? ? {:username => @user, :password => @password} : {:username => @auth_token, :password => ""}
39
44
  end
40
45
 
41
46
  def project(title)
42
47
  project = self.projects[title]
43
- raise(CommandFailed, "=== You aren't associated for a project named '#{title}'") if project.nil?
48
+ raise(Linguist::Command::CommandFailed, "=== You aren't associated for a project named '#{title}'") if project.nil?
44
49
  project
45
50
  end
46
51
 
@@ -68,27 +73,25 @@ class Linguist::Client
68
73
  headers = linguist_headers.merge(extra_headers)
69
74
  # payload = auth_params.merge(payload)
70
75
  args = [method, payload, headers].compact
71
- response = resource(uri).send(*args)
72
-
73
- puts "RESPONSE #{response}"
76
+ response = resource(uri, credentials).send(*args)
74
77
 
75
78
  # extract_warning(response)
76
79
  response
77
80
  end
78
81
 
79
- def resource(uri)
82
+ def resource(uri, credentials)
80
83
 
81
84
  RestClient.proxy = ENV['HTTP_PROXY'] || ENV['http_proxy']
82
85
  if uri =~ /^https?/
83
86
  # RestClient::Resource.new(uri, user, auth_token)
84
- RestClient::Resource.new(uri)
87
+ RestClient::Resource.new(uri, :user => credentials[:username], :password => credentials[:password])
85
88
  elsif host =~ /^https?/
86
89
  # RestClient::Resource.new(host, user, auth_token)[uri]
87
- RestClient::Resource.new(host)[uri]
90
+ RestClient::Resource.new(host, :user => credentials[:username], :password => credentials[:password])[uri]
88
91
  else
89
92
  # RestClient::Resource.new("https://api.#{host}", user, password)[uri]
90
93
  # RestClient::Resource.new("http://localhost:3000/api/v1", user, auth_token)[uri]
91
- RestClient::Resource.new("http://localhost:3000/api/v1")[uri]
94
+ RestClient::Resource.new("http://localhost:3000/api/v1", :user => credentials[:username], :password => credentials[:password])[uri]
92
95
  end
93
96
  end
94
97
 
@@ -107,8 +110,6 @@ class Linguist::Client
107
110
  def linguist_headers # :nodoc:
108
111
  {
109
112
  'X-Linguist-API-Version' => '1',
110
- 'X-Linguist-User-Email' => user,
111
- 'X-Linguist-User-Auth-Token' => auth_token,
112
113
  'User-Agent' => self.class.gem_version_string,
113
114
  'X-Ruby-Version' => RUBY_VERSION,
114
115
  'X-Ruby-Platform' => RUBY_PLATFORM,
@@ -1,5 +1,5 @@
1
- require 'linguist/helpers'
2
- require 'linguist/commands/base'
1
+ require 'linguist_ruby/helpers'
2
+ require 'linguist_ruby/commands/base'
3
3
 
4
4
  Dir["#{File.dirname(__FILE__)}/commands/*.rb"].each { |c| require c }
5
5
 
@@ -53,7 +53,7 @@ module Linguist
53
53
  begin
54
54
  return eval("Linguist::Command::#{command.capitalize}"), :index
55
55
  rescue NameError, NoMethodError
56
- return Linguist::Command::App, command.to_sym
56
+ return Linguist::Command::Project, command.to_sym
57
57
  end
58
58
  else
59
59
  begin
@@ -1,4 +1,4 @@
1
- require "linguist/client"
1
+ require "linguist_ruby/client"
2
2
 
3
3
  module Linguist::Command
4
4
  class Auth < Base
@@ -9,7 +9,7 @@ module Linguist::Command
9
9
  end
10
10
 
11
11
  def init_linguist
12
- client = Linguist::Client.new(user, auth_token, host)
12
+ client = Linguist::Client.new(:username => user, :auth_token => auth_token, :host => host)
13
13
  # client.on_warning { |msg| self.display("\n#{msg}\n\n") }
14
14
  client
15
15
  end
@@ -20,7 +20,7 @@ module Linguist::Command
20
20
 
21
21
  # just a stub; will raise if not authenticated
22
22
  def check
23
- client.list
23
+ client.projects.all
24
24
  end
25
25
 
26
26
  def reauthorize
@@ -62,14 +62,14 @@ module Linguist::Command
62
62
  end
63
63
 
64
64
  def ask_for_credentials
65
- # puts "Enter your Linguist credentials."
65
+ puts "Enter your Linguist credentials."
66
66
 
67
67
  print "Email: "
68
- user = "hjuskewycz@hemju.com"#ask
68
+ user = ask
69
69
 
70
70
  print "Password: "
71
- password = "testtest"#running_on_windows? ? ask_for_password_on_windows : ask_for_password
72
- api_key = Linguist::Client.auth(user, password, host)['api_key']
71
+ password = running_on_windows? ? ask_for_password_on_windows : ask_for_password
72
+ api_key = Linguist::Client.auth(:username => user, :password => password, :host => host)['api_key']
73
73
 
74
74
  [user, api_key]
75
75
  end
@@ -10,30 +10,35 @@ module Linguist::Command
10
10
  def initialize(args, linguist=nil)
11
11
  @args = args
12
12
  @linguist = linguist
13
- @autodetected_app = false
13
+ @autodetected_project_name = false
14
14
  end
15
15
 
16
16
  def linguist
17
17
  @linguist ||= Linguist::Command.run_internal('auth:client', args)
18
18
  end
19
19
 
20
- def extract_app(force=true)
21
- app = extract_option('--app', false)
22
- raise(CommandFailed, "You must specify an app name after --app") if app == false
23
- unless app
24
- app = extract_app_from_git || extract_from_dir_name ||
25
- raise(CommandFailed, "No app specified.\nRun this command from app folder or set it adding --app <app name>") if force
26
- @autodetected_app = true
20
+ def project_title(force=true)
21
+ project_title = extract_project_title_from_args
22
+ unless project_title
23
+ project_title = extract_project_title_from_git || extract_project_title_from_dir_name ||
24
+ raise(CommandFailed, "No project specified.\nRun this command from project folder or set it adding --project <title>") if force
25
+ @autodetected_project_name = true
27
26
  end
28
- app
27
+ project_title
29
28
  end
30
29
 
31
- def extract_from_dir_name
30
+ def extract_project_title_from_args
31
+ project_title = extract_option('--project', false)
32
+ raise(CommandFailed, "You must specify a project title after --project") if project_title == false
33
+ project_title
34
+ end
35
+
36
+ def extract_project_title_from_dir_name
32
37
  dir = Dir.pwd
33
38
  File.basename(dir)
34
39
  end
35
40
 
36
- def extract_app_from_git
41
+ def extract_project_title_from_git
37
42
  dir = Dir.pwd
38
43
  return unless remotes = git_remotes(dir)
39
44
 
@@ -101,10 +106,6 @@ module Linguist::Command
101
106
  title ||= project_title
102
107
  @project ||= linguist.project(title)
103
108
  end
104
-
105
- def project_title
106
- (args.first && !args.first =~ /^\-\-/) ? args.first : extract_app
107
- end
108
109
  end
109
110
 
110
111
  class BaseWithApp < Base
@@ -0,0 +1,44 @@
1
+ module Linguist::Command
2
+ class Collaborator < Base
3
+ def list
4
+ list = project.collaborators
5
+ if list.size > 0
6
+ display "Collaborators:\n"
7
+ list.each { |c| display("- #{c.display_name} | #{c.email} | #{c.permissions}") }
8
+ else
9
+ display "No collaborators found"
10
+ end
11
+ end
12
+
13
+ def invite
14
+ email = extract_email_from_args
15
+ project.invite_collaborator(email)
16
+
17
+ display("Invitation sent to #{email}")
18
+ rescue RestClient::BadRequest
19
+ display("Error sending invitation to '#{email}'")
20
+ end
21
+
22
+ def remove
23
+ email = extract_email_from_args
24
+ collaborator = project.collaborators.find { |c| c.email == email }
25
+
26
+ if collaborator.nil?
27
+ display("Collaborator with email '#{email}' not found")
28
+ else
29
+ collaborator.destroy
30
+ display("Collaborator with email #{email} was removed")
31
+ end
32
+ rescue RestClient::BadRequest
33
+ display("Error removing collaborator with email '#{email}'")
34
+ end
35
+
36
+ private
37
+
38
+ def extract_email_from_args
39
+ email = args.shift
40
+ raise(CommandFailed, "You must specify a invitee email after --email") if email == false
41
+ email
42
+ end
43
+ end
44
+ end
@@ -36,23 +36,31 @@ module Linguist::Command
36
36
  group.command 'help', 'show this usage'
37
37
  group.command 'version', 'show the gem version'
38
38
  group.space
39
- # group.command 'login', 'log in with your linguist credentials'
40
- # group.command 'logout', 'clear local authentication credentials'
41
- # group.space
42
- group.command 'list', 'list your projects'
43
- # group.command 'create [<name>]', 'create a new app'
44
- group.command 'info', 'show app info, like web url and number of translations'
45
- group.command 'open', 'open the app in a web browser'
46
- group.command 'rename <newname>', 'rename the app'
47
- group.command 'destroy', 'destroy the app permanently'
39
+ end
40
+
41
+ group 'Project Commands' do |group|
42
+ group.command 'project:list', 'list your projects'
43
+ group.command 'project:create <name>', 'create a new project'
44
+ group.command 'project:info <name>', 'show project info, like web url and number of translations'
45
+ group.command 'project:open <name>', 'open the project in a web browser'
46
+ group.command 'project:rename <oldname> <newname>', 'rename the project'
47
+ group.command 'project:destroy <name', 'destroy the project permanently'
48
48
  group.space
49
49
  end
50
50
 
51
- # group 'Plugins' do |group|
52
- # group.command 'plugins', 'list installed plugins'
53
- # group.command 'plugins:install <url>', 'install the plugin from the specified git url'
54
- # group.command 'plugins:uninstall <url/name>', 'remove the specified plugin'
55
- # end
51
+ group 'Collaborator Commands' do |group|
52
+ group.command 'collaborator:list', 'list project collaborators'
53
+ group.command 'collaborator:invite <email>', 'invite the collaborator'
54
+ group.command 'collaborator:remove <email>', 'remove the collaborator'
55
+ group.space
56
+ end
57
+
58
+ group 'Translation Commands' do |group|
59
+ group.command 'translation:down --all --directory <path>', 'download all resource files'
60
+ group.command 'translation:down <file1> <file2> ... --directory <path>', 'download specific resource files'
61
+ group.command 'translation:up <file1> <file2> ... --locale <iso2_slug>', 'upload specific resource files'
62
+ group.space
63
+ end
56
64
  end
57
65
 
58
66
  def index
@@ -2,7 +2,7 @@ require 'readline'
2
2
  require 'launchy'
3
3
 
4
4
  module Linguist::Command
5
- class App < Base
5
+ class Project < Base
6
6
  def login
7
7
  Linguist::Command.run_internal "auth:reauthorize", args.dup
8
8
  end
@@ -31,10 +31,9 @@ module Linguist::Command
31
31
  end
32
32
 
33
33
  def rename
34
- newtitle = args.shift.downcase.strip rescue ''
35
34
  oldtitle = project.title
36
35
 
37
- raise(CommandFailed, "Invalid name.") if newtitle == ''
36
+ newtitle = args[1].downcase.strip rescue raise(CommandFailed, "Invalid new project name")
38
37
 
39
38
  project.update(:title => newtitle)
40
39
  display("Renaming project from #{oldtitle} to #{newtitle}")
@@ -50,9 +49,7 @@ module Linguist::Command
50
49
  end
51
50
 
52
51
  def open
53
- project = linguist.project
54
- url = project.weburl
55
- Launchy.open url
52
+ Launchy.open project.weburl
56
53
  end
57
54
 
58
55
  def destroy
@@ -0,0 +1,65 @@
1
+ module Linguist::Command
2
+ class Translations < Base
3
+ def down
4
+ project #project validation
5
+
6
+ directory = File.join(Dir.pwd, extract_directory_from_args || "")
7
+ raise(CommandFailed, "Error downloading translations. Path #{directory} does not exist") unless File.directory?(directory)
8
+
9
+ files_source = extract_all_from_args ? project.resources.keys : args
10
+ files_source.each do |file_name|
11
+ begin
12
+ project.pull_resource(directory, file_name)
13
+ display("#{file_name} downloaded")
14
+ rescue
15
+ display "Error downloading #{file_name}. Response: #{$!.message}"
16
+ end
17
+ end
18
+ end
19
+
20
+ def up
21
+ project #project validation
22
+
23
+ args.each do |file_name|
24
+ begin
25
+ path = File.expand_path(file_name, Dir.pwd)
26
+ project.push_resource(path, extract_locale_from_args)
27
+ display("#{file_name} uploaded")
28
+ rescue
29
+ display "Error uploading #{file_name}. Response: #{$!.response || $!.message}"
30
+ end
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def rails_environment?
37
+ true #TODO
38
+ end
39
+
40
+ def rails_locale_dir
41
+ Dir.pwd + "/conf/locales"
42
+ end
43
+
44
+ def extract_directory_from_args
45
+ return @directory if defined? @directory
46
+ @directory = extract_option('--directory', false)
47
+ raise(CommandFailed, "You must specify a directory after --directory") if @directory == false
48
+ @directory
49
+ end
50
+
51
+ def extract_locale_from_args
52
+ return @locale if defined? @locale
53
+ @locale = extract_option('--locale', false)
54
+ raise(CommandFailed, "You must specify a locale after --locale") if @locale == false
55
+ @locale
56
+ end
57
+
58
+ def extract_all_from_args
59
+ return @all if defined? @all
60
+ @all = extract_option('--all', true)
61
+ raise(CommandFailed, "You have not specify anything after --all") unless @all == true or @all.nil?
62
+ @all
63
+ end
64
+ end
65
+ end
File without changes
File without changes
@@ -0,0 +1,25 @@
1
+ module Linguist
2
+ module Models
3
+ class Collaborator
4
+ attr_accessor :email, :display_name, :roles
5
+
6
+ ROLES_NAMES = { "project_admin" => "Project admin", "developer" => "Developer" }
7
+
8
+ def initialize(client, link)
9
+ @client = client
10
+ @link = link
11
+ end
12
+
13
+ def destroy
14
+ @client.delete @link
15
+ end
16
+
17
+ def permissions
18
+ return "None" if self.roles.nil? or self.roles.empty?
19
+
20
+ self.roles.find_all { |role| ROLES_NAMES.has_key?(role) }.join(", ")
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,120 @@
1
+ module Linguist
2
+ module Models
3
+ require 'linguist_ruby/models/resource'
4
+ require 'linguist_ruby/models/collaborator'
5
+
6
+ class Project
7
+ def self.lazy_attr_accessor(*params)
8
+ params.each do |sym|
9
+ define_method(sym) do
10
+ unless defined? @fetched
11
+ fetch
12
+ end
13
+ self.instance_variable_get("@#{sym}")
14
+ end
15
+ define_method("#{sym}=") do |value|
16
+ self.instance_variable_set("@#{sym}", value)
17
+ end
18
+ end
19
+ end
20
+
21
+ lazy_attr_accessor(:title, :link, :weburl, :resources_url, :collaborators_url, :invitations_url, :translations_url, :translations_count, :owner)
22
+
23
+ def initialize(client, link)
24
+ @client = client
25
+ @link = link
26
+ end
27
+
28
+ def create!(attributes={})
29
+ self.title = attribtes[:title]
30
+ end
31
+
32
+ def destroy
33
+ @client.delete self.link
34
+ end
35
+
36
+ def update(attributes={})
37
+ @client.put self.link, {:project => attributes}
38
+ end
39
+
40
+ def invite_collaborator(email)
41
+ @client.post(self.invitations_url, :invitation => {:email => email})
42
+ end
43
+
44
+ def resources
45
+ unless defined? @resources
46
+ @resources = {}
47
+ response = @client.get(self.resources_url)
48
+ resource_hash = JSON.parse(response)
49
+ members = resource_hash["resources"]["members"]
50
+ members.each do |member|
51
+ @resources[member["name"]] = Linguist::Models::Resource.new(@client, member["link"]["href"])
52
+ end
53
+ end
54
+ @resources
55
+ end
56
+
57
+ def collaborators
58
+ unless defined? @collaborators
59
+ @collaborators = []
60
+ response = @client.get(self.collaborators_url)
61
+ resource_hash = JSON.parse(response)
62
+ members = resource_hash["collaborators"]["members"]
63
+ members.each do |member|
64
+ link = member["link"]["href"] rescue ""
65
+ collaborator = Linguist::Models::Collaborator.new(@client, link)
66
+ collaborator.email = member["email"]
67
+ collaborator.display_name = member["display_name"]
68
+ collaborator.roles = member["roles"]
69
+ @collaborators << collaborator
70
+ end
71
+ end
72
+ @collaborators
73
+ end
74
+
75
+ def pull_resource(dir, file_name)
76
+ raise "Project does not contain that file." unless self.resources.has_key?(file_name)
77
+ save_to_file(File.join(dir, file_name), self.resources[file_name].content)
78
+ end
79
+
80
+ def push_resource(path, locale)
81
+ raise "Path #{path} does not exists" unless File.exists?(path)
82
+ request = { :file => File.new(path, "rb") }
83
+ request.merge!({ :iso2_slug => locale }) if locale
84
+ @client.post(self.resources_url, request)
85
+ end
86
+
87
+ private
88
+
89
+ def fetch
90
+ @fetched = true
91
+ response = @client.get @link
92
+ project_hash = JSON.parse(response)
93
+ links = project_hash["link"]
94
+ link = links[0]["href"]
95
+ weburl = links[1]["href"]
96
+ translations_url = links[2]["href"]
97
+ resources_url = links[3]["href"]
98
+ collaborators_url = links[4]["href"]
99
+ invitations_url = links[5]["href"]
100
+ init_attributes :title => project_hash["title"], :link => link, :weburl => weburl,
101
+ :owner => project_hash["owner_email"], :translations_count => project_hash["translations_count"],
102
+ :translations_url => translations_url, :resources_url => resources_url,
103
+ :collaborators_url => collaborators_url, :invitations_url => invitations_url
104
+ end
105
+
106
+ def init_attributes(attributes)
107
+ attributes.each_pair do |key, value|
108
+ unless self.instance_variable_get("@#{key}")
109
+ self.send "#{key}=", value
110
+ end
111
+ end
112
+ end
113
+
114
+ def save_to_file(path, content)
115
+ File.open(path, 'w+') { |f| f.write(content) }
116
+ end
117
+
118
+ end
119
+ end
120
+ end
@@ -1,6 +1,6 @@
1
1
  module Linguist
2
2
  module Models
3
- require 'linguist/models/project'
3
+ require 'linguist_ruby/models/project'
4
4
 
5
5
  class Projects
6
6
 
@@ -0,0 +1,15 @@
1
+ module Linguist
2
+ module Models
3
+ class Resource
4
+ def initialize(client, link)
5
+ @client = client
6
+ @link = link
7
+ end
8
+
9
+ # Downloads the resource content
10
+ def content
11
+ @content ||= @client.get(@link)
12
+ end
13
+ end
14
+ end
15
+ end
File without changes
@@ -0,0 +1,14 @@
1
+ require 'rails'
2
+
3
+ module Linguist
4
+ class Railtie < ::Rails::Railtie
5
+ config.after_initialize do
6
+ Linguist.environments ||= [:development]
7
+ Linguist.protocol ||= "https"
8
+ Linguist.host ||= "app.lingui.st"
9
+ Linguist.username ||= ":username"
10
+ Linguist.project ||= ":project"
11
+ Dir[File.join(File.dirname(__FILE__), "../../patches/**/*.rb")].each { |f| require f }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Linguist
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,48 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require "stringex"
3
+
4
+ module I18n
5
+ class << self
6
+ alias :old_translate :translate
7
+
8
+ def translate(*args)
9
+ result = old_translate(args)
10
+ result = wrap_with_wysiwyt(args.dup.shift, result) if enabled?
11
+ result
12
+ end
13
+
14
+ alias :t :translate
15
+
16
+ private
17
+
18
+ def enabled?
19
+ Linguist.environments.include?(current_env) rescue false
20
+ end
21
+
22
+ def current_env
23
+ defined?(Rails) ? Rails.env.to_sym : nil
24
+ end
25
+
26
+ def wrap_with_wysiwyt(translation_title, translation_phrase)
27
+ "<span data-phrase_url=\"#{link_to_translation(translation_title)}\" data-locale=\"#{locale}\" data-master-phrase=\"#{translation_title}\">#{translation_phrase}</span>"
28
+ end
29
+
30
+ def link_to_translation(translation_title)
31
+ username = option_to_url(Linguist.username)
32
+ project = option_to_url(Linguist.project)
33
+ translation_title = translation_title.to_url
34
+
35
+ "#{Linguist.protocol}://#{Linguist.host}/#{username}/#{project}/#{translation_title}"
36
+ end
37
+
38
+ def option_to_url(option)
39
+ if option.nil?
40
+ ""
41
+ elsif Linguist.default_value?(option)
42
+ option
43
+ else
44
+ option.to_url
45
+ end
46
+ end
47
+ end
48
+ end
metadata CHANGED
@@ -1,121 +1,78 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: linguist_ruby
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
4
5
  prerelease:
5
- version: 0.0.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Linguist
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-04-25 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: fakefs
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ~>
22
- - !ruby/object:Gem::Version
23
- version: 0.3.1
24
- type: :development
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: rake
28
- prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
30
- none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
35
- type: :development
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: rspec
39
- prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: 1.3.0
46
- type: :development
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
49
- name: taps
50
- prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
54
- - - ~>
55
- - !ruby/object:Gem::Version
56
- version: 0.3.20
57
- type: :development
58
- version_requirements: *id004
59
- - !ruby/object:Gem::Dependency
60
- name: webmock
61
- prerelease: false
62
- requirement: &id005 !ruby/object:Gem::Requirement
63
- none: false
64
- requirements:
65
- - - ~>
66
- - !ruby/object:Gem::Version
67
- version: 1.5.0
68
- type: :development
69
- version_requirements: *id005
70
- - !ruby/object:Gem::Dependency
12
+ date: 2011-10-16 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
71
15
  name: rest-client
72
- prerelease: false
73
- requirement: &id006 !ruby/object:Gem::Requirement
16
+ requirement: &2154533780 !ruby/object:Gem::Requirement
74
17
  none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
78
21
  version: 1.4.0
79
22
  - - <
80
- - !ruby/object:Gem::Version
23
+ - !ruby/object:Gem::Version
81
24
  version: 1.7.0
82
25
  type: :runtime
83
- version_requirements: *id006
84
- - !ruby/object:Gem::Dependency
85
- name: launchy
86
26
  prerelease: false
87
- requirement: &id007 !ruby/object:Gem::Requirement
27
+ version_requirements: *2154533780
28
+ - !ruby/object:Gem::Dependency
29
+ name: launchy
30
+ requirement: &2154533060 !ruby/object:Gem::Requirement
88
31
  none: false
89
- requirements:
32
+ requirements:
90
33
  - - ~>
91
- - !ruby/object:Gem::Version
34
+ - !ruby/object:Gem::Version
92
35
  version: 0.3.2
93
36
  type: :runtime
94
- version_requirements: *id007
37
+ prerelease: false
38
+ version_requirements: *2154533060
39
+ - !ruby/object:Gem::Dependency
40
+ name: stringex
41
+ requirement: &2154532600 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 1.2.1
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: *2154532600
95
50
  description: Client library and command-line tool to translate Rails apps with Linguist.
96
51
  email: support@lingui.st
97
- executables:
52
+ executables:
98
53
  - linguist
99
54
  extensions: []
100
-
101
55
  extra_rdoc_files: []
102
-
103
- files:
104
- - lib/linguist/client.rb
105
- - lib/linguist/command.rb
106
- - lib/linguist/commands/app.rb
107
- - lib/linguist/commands/auth.rb
108
- - lib/linguist/commands/base.rb
109
- - lib/linguist/commands/help.rb
110
- - lib/linguist/commands/translations.rb
111
- - lib/linguist/commands/version.rb
112
- - lib/linguist/helpers.rb
113
- - lib/linguist/models/project.rb
114
- - lib/linguist/models/projects.rb
115
- - lib/linguist/models/resource.rb
116
- - lib/linguist/models/user.rb
117
- - lib/linguist/version.rb
118
- - lib/linguist.rb
56
+ files:
57
+ - lib/linguist_ruby/client.rb
58
+ - lib/linguist_ruby/command.rb
59
+ - lib/linguist_ruby/commands/auth.rb
60
+ - lib/linguist_ruby/commands/base.rb
61
+ - lib/linguist_ruby/commands/collaborator.rb
62
+ - lib/linguist_ruby/commands/help.rb
63
+ - lib/linguist_ruby/commands/project.rb
64
+ - lib/linguist_ruby/commands/translations.rb
65
+ - lib/linguist_ruby/commands/version.rb
66
+ - lib/linguist_ruby/helpers.rb
67
+ - lib/linguist_ruby/models/collaborator.rb
68
+ - lib/linguist_ruby/models/project.rb
69
+ - lib/linguist_ruby/models/projects.rb
70
+ - lib/linguist_ruby/models/resource.rb
71
+ - lib/linguist_ruby/models/user.rb
72
+ - lib/linguist_ruby/rails3/railtie.rb
73
+ - lib/linguist_ruby/version.rb
74
+ - lib/linguist_ruby.rb
75
+ - lib/patches/rails3/i18n/i18n.rb
119
76
  - lib/vendor/okjson.rb
120
77
  - bin/linguist
121
78
  - LICENSE
@@ -125,30 +82,27 @@ files:
125
82
  - ROADMAP.md
126
83
  homepage: http://lingui.st/
127
84
  licenses: []
128
-
129
85
  post_install_message:
130
86
  rdoc_options: []
131
-
132
- require_paths:
87
+ require_paths:
133
88
  - lib
134
- required_ruby_version: !ruby/object:Gem::Requirement
89
+ required_ruby_version: !ruby/object:Gem::Requirement
135
90
  none: false
136
- requirements:
137
- - - ">="
138
- - !ruby/object:Gem::Version
139
- version: "0"
140
- required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
96
  none: false
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
145
100
  version: 1.3.6
146
101
  requirements: []
147
-
148
102
  rubyforge_project:
149
- rubygems_version: 1.7.2
103
+ rubygems_version: 1.8.7
150
104
  signing_key:
151
105
  specification_version: 3
152
106
  summary: Client library and CLI to translate Rails apps with Linguist.
153
107
  test_files: []
154
-
108
+ has_rdoc:
data/lib/linguist.rb DELETED
@@ -1,3 +0,0 @@
1
- module Linguist; end
2
-
3
- require 'linguist/client'
@@ -1,30 +0,0 @@
1
- module Linguist::Command
2
- class Translations < Base
3
-
4
- def down
5
- if rails_environment?
6
- project.resources["en.yml"].download rails_locale_dir
7
- else
8
- end
9
- end
10
-
11
- def up
12
- if rails_environment?
13
- else
14
-
15
- end
16
- end
17
-
18
- private
19
-
20
- def rails_environment?
21
- true #TODO
22
- end
23
-
24
- def rails_locale_dir
25
- Dir.pwd + "/conf/locales"
26
- end
27
-
28
- end
29
-
30
- end
@@ -1,81 +0,0 @@
1
- module Linguist
2
- module Models
3
- require 'linguist/models/resource'
4
-
5
- class Project
6
- def self.lazy_attr_accessor(*params)
7
- params.each do |sym|
8
- define_method(sym) do
9
- unless defined? @fetched
10
- fetch
11
- end
12
- self.instance_variable_get("@#{sym}")
13
- end
14
- define_method("#{sym}=") do |value|
15
- self.instance_variable_set("@#{sym}", value)
16
- end
17
- end
18
- end
19
-
20
- lazy_attr_accessor(:title, :link, :weburl, :resources_url, :translations_url, :translations_count, :owner)
21
-
22
- def initialize(client, link)
23
- @client = client
24
- @link = link
25
- end
26
-
27
- def create!(attributes={ })
28
- self.title = attribtes[:title]
29
- end
30
-
31
- def destroy
32
- @client.delete self.link
33
- end
34
-
35
- def update(attributes={ })
36
- @client.put self.link, { :project => attributes }
37
- end
38
-
39
- def resources
40
- unless defined? @resources
41
- @resources = { }
42
- response = @client.get(self.resources_url)
43
- resource_hash = JSON.parse(response)
44
- links = resource_hash["link"]
45
- links.each do |link|
46
- file_name = link["rel"]
47
- locale, extension = File.basename(file_name, '.*') , File.extname(file_name)
48
- @resources[file_name] = Linguist::Models::Resource.new(@client, locale, extension, link["href"])
49
- end
50
- end
51
- puts "RESOURCES #{@resources}"
52
- @resources
53
- end
54
-
55
- private
56
-
57
- def fetch
58
- @fetched = true
59
- response = @client.get @link
60
- project_hash = JSON.parse(response)
61
- links = project_hash["link"]
62
- link = links[0]["href"]
63
- weburl = links[1]["href"]
64
- translations_url = links[2]["href"]
65
- resources_url = links[3]["href"]
66
- init_attributes :title => project_hash["title"], :link => link, :weburl => weburl,
67
- :owner => project_hash["owner_email"], :translations_count => project_hash["translations_count"],
68
- :translations_url => translations_url, :resources_url => resources_url
69
- end
70
-
71
- def init_attributes(attributes)
72
- attributes.each_pair do |key, value|
73
- unless self.instance_variable_get("@#{key}")
74
- self.send "#{key}=", value
75
- end
76
- end
77
- end
78
-
79
- end
80
- end
81
- end
@@ -1,26 +0,0 @@
1
- module Linguist
2
- module Models
3
- class Resource
4
- attr_reader :locale, :format, :link
5
-
6
- # @param client [Linguist::Client] passed through client instance
7
- # @param locale [String] String that represents a locale in ISO 2 format, e.g. 'en', 'de'
8
- # @param format [String] Extension of the file format, e.g. 'en', 'de'
9
- # @param link [String] Link to the resource, e.g. 'http://lvh.me:3000/api/v1/projects/project-1/resources/de.properties'
10
- def initialize(client, locale, format, link)
11
- @client = client
12
- @link = link
13
- @locale = locale
14
- @format = format
15
- end
16
-
17
- # Downloads the resource and creates the new resource file. Overrides existing files.
18
- # @param dir [String] The directory where to store the file, e.g. '/Users/heli' would create a file '/Users/heli/en.yml'
19
- def download(dir)
20
- response = @client.get(link)
21
- File.open(dir + "/#{locale}#{format}", 'w+') { |f| f.write(response) }
22
- end
23
-
24
- end
25
- end
26
- end
@@ -1,3 +0,0 @@
1
- module Linguist
2
- VERSION = "0.0.2"
3
- end