codus 0.0.1.2 → 0.0.1.3

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.
@@ -0,0 +1,20 @@
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
18
+ .rspec
19
+ .ruby-gemset
20
+ .ruby-version
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'http://rubygems.org'
2
+
3
+ rails_version = '~> 3.2.0'
4
+
5
+ gem 'rails', rails_version
6
+ gem 'rspec', '~> 2.6.0'
7
+ gem 'debugger'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Vinícius Oyama
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.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'codus/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "codus"
8
+ spec.version = Codus::VERSION.freeze
9
+ spec.authors = ["Vinícius Oyama"]
10
+ spec.email = ["vinicius.oyama@gmail.com"]
11
+ spec.description = %q{Organize your javascript across namespaces matching your controllers and actions. Get automatic executing functions for current controller and action.}
12
+ spec.summary = %q{Organize your javascript across namespaces matching your controllers and actions. Get automatic executing functions for current controller and action.}
13
+ spec.authors = ['Vinícius Oyama']
14
+ spec.email = "vinicius.oyama@codus.com.br"
15
+ spec.homepage = "https://github.com/codus/codus"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files`.split("\n")
19
+ spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "railties", "~> 3.1"
25
+ end
@@ -1,3 +1,3 @@
1
1
  module Codus
2
- VERSION = "0.0.1.2"
2
+ VERSION = "0.0.1.3"
3
3
  end
@@ -0,0 +1,102 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Codus::ViewHelpers::YojsHelper::YojsCallGenerator do
5
+ subject { Codus::ViewHelpers::YojsHelper::YojsCallGenerator.new("ns2", "ns3", {:app_name => "ns1"}) }
6
+ describe "generate_yojs_calls" do
7
+ specify do
8
+ namespaces_array = ["ns1", "ns1.ns2", "ns1.ns2.ns3"]
9
+ namespaces_array_with_method = ["ns1.load", "ns1.ns2.load", "ns1.ns2.ns3.load", "ns1.ns2.ns3.load"]
10
+ conditional_callings = [
11
+ "\n if (yojs.isDefined(\"ns2\")) {\n yojs.call(\"ns2\");\n }\n ",
12
+ "\n if (yojs.isDefined(\"ns4.ng5\")) {\n yojs.call(\"ns4.ng5\");\n }\n "]
13
+ subject.should_receive(:get_all_namespaces_from_full_namespace).and_return(namespaces_array)
14
+ subject.should_receive(:append_onload_method_to_namespaces).with(namespaces_array).and_return(namespaces_array_with_method)
15
+ subject.should_receive(:generate_conditional_function_calling_for_namespaces).with(namespaces_array_with_method).and_return(conditional_callings)
16
+ subject.generate_yojs_calls.should be == "\n if (yojs.isDefined(\"ns2\")) {\n yojs.call(\"ns2\");\n }\n \n\n if (yojs.isDefined(\"ns4.ng5\")) {\n yojs.call(\"ns4.ng5\");\n }\n "
17
+ end
18
+ end
19
+
20
+ describe "get_all_namespaces_from_full_namespace" do
21
+ specify { subject.get_all_namespaces_from_full_namespace.should be == %w(ns1 ns1.ns2 ns1.ns2.ns3)}
22
+
23
+ it "should return mapped ns names" do
24
+ generator = Codus::ViewHelpers::YojsHelper::YojsCallGenerator.new("ns2", "create", {:app_name => "ns1", :method_names_mapper => {:create => "novo"}})
25
+ generator.get_all_namespaces_from_full_namespace().should be == %w(ns1 ns1.ns2 ns1.ns2.create ns1.ns2.novo)
26
+ generator = Codus::ViewHelpers::YojsHelper::YojsCallGenerator.new("ns2", "edit", {:app_name => "ns1", :method_names_mapper => {:create => "novo"}})
27
+ generator.get_all_namespaces_from_full_namespace().should be == %w(ns1 ns1.ns2 ns1.ns2.edit)
28
+
29
+ end
30
+ end
31
+
32
+ describe "append_onload_method_to_namespaces" do
33
+ context "empty method name" do
34
+ specify { subject.append_onload_method_to_namespaces(["ns2", "ns4.ng5"]).should be == ["ns2", "ns4.ng5"] }
35
+ end
36
+
37
+ context "method name not empty" do
38
+ specify do
39
+ subject.instance_eval { @options[:onload_method_name] = "onload_method"}
40
+ subject.append_onload_method_to_namespaces(["ns2", "ns4.ng5"]).should be == ["ns2.onload_method", "ns4.ng5.onload_method"]
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "generate_conditional_function_calling_for_namespaces" do
46
+ specify do
47
+ subject.generate_conditional_function_calling_for_namespaces(["ns2", "ns4.ng5"]).should be == [
48
+ "\n if (yojs.isDefined(\"ns2\")) {\n yojs.call(\"ns2\");\n }\n ",
49
+ "\n if (yojs.isDefined(\"ns4.ng5\")) {\n yojs.call(\"ns4.ng5\");\n }\n "
50
+ ]
51
+ end
52
+ end
53
+
54
+ describe "merge_options_with_defaults" do
55
+ describe "default_values" do
56
+ specify { subject.merge_options_with_defaults({})[:app_name].should be == ""}
57
+ specify { subject.merge_options_with_defaults({})[:onload_method_name].should be == ""}
58
+ specify { subject.merge_options_with_defaults({})[:method_names_mapper].should include({
59
+ :create => :new,
60
+ :update => :edit
61
+ })
62
+ }
63
+ end
64
+
65
+ context "merging parameters" do
66
+ specify do
67
+ subject.merge_options_with_defaults({:app_name => "NOMETESTE"})[:app_name].should be == "NOMETESTE"
68
+ end
69
+
70
+ specify do
71
+ subject.merge_options_with_defaults({:onload_method_name => "NOMETESTE"})[:onload_method_name].should be == "NOMETESTE"
72
+ end
73
+
74
+ specify do
75
+ subject.merge_options_with_defaults({:method_names_mapper => {:rota => :novo_nome}})[:method_names_mapper].should include({
76
+ :create => :new,
77
+ :update => :edit,
78
+ :rota => :novo_nome
79
+ })
80
+ end
81
+
82
+ specify do
83
+ customized_options = subject.merge_options_with_defaults({
84
+ :app_name => "NOMEAPPTESTE",
85
+ :onload_method_name => "NOMELOADTESTE",
86
+ :method_names_mapper => {
87
+ :rota => :novo_nome,
88
+ :create => :createpersonalizado
89
+ }
90
+ })
91
+
92
+ customized_options[:app_name].should be == "NOMEAPPTESTE"
93
+ customized_options[:onload_method_name].should be == "NOMELOADTESTE"
94
+ customized_options[:method_names_mapper].should include({
95
+ :update => :edit,
96
+ :rota => :novo_nome,
97
+ :create => :createpersonalizado
98
+ })
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Codus::ViewHelpers::YojsHelper do
5
+ let(:helper) { Class.new(ActionView::Base) do
6
+ include Codus::ViewHelpers #need javascript_ready
7
+ end.new
8
+ }
9
+
10
+ describe "load_yojs" do
11
+ before(:each) { helper.stub!(:params).and_return({ :action => "nomeaction", :controller => "nomecontroller" }.with_indifferent_access) }
12
+
13
+ specify do
14
+ generator_mock = mock()
15
+ generator_mock.should_receive(:generate_yojs_calls).and_return("<script>JAVASCRIPTDERETORNO</script>")
16
+ Codus::ViewHelpers::YojsHelper::YojsCallGenerator.should_receive(:new).with("nomecontroller", "nomeaction", {:app_name => 'app_teste'}).and_return(generator_mock)
17
+ helper.load_yojs(:app_name => 'app_teste').should be == "<script type=\"text/javascript\">\n//<![CDATA[\n$(function(){\n&lt;script&gt;JAVASCRIPTDERETORNO&lt;/script&gt;});\n//]]>\n</script>"
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Codus::ViewHelpers do
5
+ let(:helper) { Class.new(ActionView::Base) do
6
+ include Codus::ViewHelpers
7
+ end.new
8
+ }
9
+
10
+ describe "javascript_ready" do
11
+ specify do
12
+ helper.javascript_ready do
13
+ "CONTEUDO JAVASCRIPT"
14
+ end.should be == "<script type=\"text/javascript\">\n//<![CDATA[\n$(function(){\nCONTEUDO JAVASCRIPT});\n//]]>\n</script>"
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,10 @@
1
+ ENV["RAILS_ENV"] ||= 'test'
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ require 'codus'
5
+ require 'action_view'
6
+ require 'active_support/all'
7
+
8
+ include ActionView::Helpers
9
+
10
+ Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.2
4
+ version: 0.0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -50,14 +50,23 @@ executables: []
50
50
  extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - app/assets/javascript/yojs.js
59
+ - codus.gemspec
60
+ - lib/README.md
61
+ - lib/codus.rb
53
62
  - lib/codus/version.rb
54
- - lib/codus/view_helpers/yojs_helper/yojs_call_generator.rb
55
- - lib/codus/view_helpers/yojs_helper.rb
56
63
  - lib/codus/view_helpers.rb
57
- - lib/codus.rb
58
- - lib/README.md
59
- - app/assets/javascript/yojs.js
60
- - README.md
64
+ - lib/codus/view_helpers/yojs_helper.rb
65
+ - lib/codus/view_helpers/yojs_helper/yojs_call_generator.rb
66
+ - spec/codus/view_helpers/yojs_helper/yojs_call_generator_spec.rb
67
+ - spec/codus/view_helpers/yojs_helper_spec.rb
68
+ - spec/codus/view_helpers_spec.rb
69
+ - spec/spec_helper.rb
61
70
  homepage: https://github.com/codus/codus
62
71
  licenses:
63
72
  - MIT
@@ -84,4 +93,8 @@ signing_key:
84
93
  specification_version: 3
85
94
  summary: Organize your javascript across namespaces matching your controllers and
86
95
  actions. Get automatic executing functions for current controller and action.
87
- test_files: []
96
+ test_files:
97
+ - spec/codus/view_helpers/yojs_helper/yojs_call_generator_spec.rb
98
+ - spec/codus/view_helpers/yojs_helper_spec.rb
99
+ - spec/codus/view_helpers_spec.rb
100
+ - spec/spec_helper.rb