ahc 0.2.7 → 0.3.0

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: 27ae39deee3de104d4820c1884ff3aaeee43dd6c
4
+ data.tar.gz: f6d5add79d98087e0a5d24c834aa12e7c21c4606
5
+ SHA512:
6
+ metadata.gz: fd7e4844d84793505f44634510cefd104f22cb97de81e1b13c888ffddf479e1b776114232647517dd733eceac6bb0937c4e406ddfae8776c950e993a58717fe9
7
+ data.tar.gz: e4b33add627acfb266d0f9cc80d514de6a1f0dd922e1dd8b08b30bda3c07aaa0febde2d58d88b6e5e73f24addaad3fe77210f4e5fb7674cb0f4237050bf6fe36
data/Gemfile CHANGED
@@ -2,15 +2,12 @@ source "http://rubygems.org"
2
2
  # Add dependencies required to use your gem here.
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
- gem 'erubis'
6
- gem 'nokogiri'
7
- gem 'htmlcompressor'
8
5
 
9
6
  # Add dependencies to develop your gem here.
10
7
  # Include everything needed to run rake, tests, features, etc.
11
8
  group :development do
12
9
  gem "rspec", "~> 2.8.0"
13
10
  gem "rdoc", "~> 3.12"
14
- gem "bundler"
15
- gem "jeweler", "~> 1.8.4"
11
+ gem "bundler", "~> 1.0"
12
+ gem "jeweler", "~> 1.8.7"
16
13
  end
data/Gemfile.lock CHANGED
@@ -1,25 +1,48 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- POpen4 (0.1.4)
5
- Platform (>= 0.4.0)
6
- open4
7
- Platform (0.4.0)
4
+ addressable (2.3.5)
5
+ builder (3.2.2)
8
6
  diff-lcs (1.1.3)
9
- erubis (2.7.0)
10
- git (1.2.5)
11
- htmlcompressor (0.0.5)
12
- yui-compressor (~> 0.9.6)
13
- jeweler (1.8.4)
7
+ faraday (0.8.8)
8
+ multipart-post (~> 1.2.0)
9
+ git (1.2.6)
10
+ github_api (0.10.1)
11
+ addressable
12
+ faraday (~> 0.8.1)
13
+ hashie (>= 1.2)
14
+ multi_json (~> 1.4)
15
+ nokogiri (~> 1.5.2)
16
+ oauth2
17
+ hashie (2.0.5)
18
+ highline (1.6.20)
19
+ httpauth (0.2.0)
20
+ jeweler (1.8.8)
21
+ builder
14
22
  bundler (~> 1.0)
15
23
  git (>= 1.2.5)
24
+ github_api (= 0.10.1)
25
+ highline (>= 1.6.15)
26
+ nokogiri (= 1.5.10)
16
27
  rake
17
28
  rdoc
18
- json (1.7.6)
19
- nokogiri (1.5.6)
20
- open4 (1.3.0)
21
- rake (10.0.3)
22
- rdoc (3.12)
29
+ json (1.8.1)
30
+ jwt (0.1.8)
31
+ multi_json (>= 1.5)
32
+ multi_json (1.8.2)
33
+ multi_xml (0.5.5)
34
+ multipart-post (1.2.0)
35
+ nokogiri (1.5.10)
36
+ oauth2 (0.9.2)
37
+ faraday (~> 0.8)
38
+ httpauth (~> 0.2)
39
+ jwt (~> 0.1.4)
40
+ multi_json (~> 1.0)
41
+ multi_xml (~> 0.5)
42
+ rack (~> 1.2)
43
+ rack (1.5.2)
44
+ rake (10.1.0)
45
+ rdoc (3.12.2)
23
46
  json (~> 1.4)
24
47
  rspec (2.8.0)
25
48
  rspec-core (~> 2.8.0)
@@ -29,17 +52,12 @@ GEM
29
52
  rspec-expectations (2.8.0)
30
53
  diff-lcs (~> 1.1.2)
31
54
  rspec-mocks (2.8.0)
32
- yui-compressor (0.9.6)
33
- POpen4 (>= 0.1.4)
34
55
 
35
56
  PLATFORMS
36
57
  ruby
37
58
 
38
59
  DEPENDENCIES
39
- bundler
40
- erubis
41
- htmlcompressor
42
- jeweler (~> 1.8.4)
43
- nokogiri
60
+ bundler (~> 1.0)
61
+ jeweler (~> 1.8.7)
44
62
  rdoc (~> 3.12)
45
63
  rspec (~> 2.8.0)
data/Rakefile CHANGED
@@ -17,9 +17,9 @@ Jeweler::Tasks.new do |gem|
17
17
  gem.name = "ahc"
18
18
  gem.homepage = "http://github.com/romanoff/ahc"
19
19
  gem.license = "MIT"
20
- gem.summary = %Q{TODO: one-line summary of your gem}
21
- gem.description = %Q{TODO: longer description of your gem}
22
- gem.email = "aromanov@partnerpedia.com"
20
+ gem.summary = %Q{Ahc allows you to move all your client side code to ahc server}
21
+ gem.description = %Q{Ahc allows you to move all your client side code to ahc server}
22
+ gem.email = "judo.ras@gmail.com"
23
23
  gem.authors = ["Andriy Romanov"]
24
24
  # dependencies defined in Gemfile
25
25
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.3.0
data/ahc.gemspec ADDED
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "ahc"
8
+ s.version = "0.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Andriy Romanov"]
12
+ s.date = "2013-12-05"
13
+ s.description = "Ahc allows you to move all your client side code to ahc server"
14
+ s.email = "judo.ras@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "ahc.gemspec",
29
+ "lib/ahc.rb",
30
+ "lib/ahc_helper.rb",
31
+ "spec/ahc_spec.rb",
32
+ "spec/spec_helper.rb",
33
+ "static/error.html"
34
+ ]
35
+ s.homepage = "http://github.com/romanoff/ahc"
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = "2.0.3"
39
+ s.summary = "Ahc allows you to move all your client side code to ahc server"
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 4
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
46
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
47
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
48
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
49
+ else
50
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
51
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
52
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
53
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
57
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
60
+ end
61
+ end
62
+
data/lib/ahc.rb CHANGED
@@ -1,60 +1,45 @@
1
- require 'erubis'
2
- require 'ahcx_template_handler'
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'ahc_helper'
3
4
 
4
5
  class Ahc
5
6
 
6
- def self.render(template_name, params)
7
- if @@templates[template_name]
8
- css = lambda {|css_class|
9
- @@css_map[css_class] || css_class
10
- }
11
- return @@templates[template_name].result({:params => params, :css => css}).strip
12
- end
13
- return ''
14
- end
15
-
16
- def self.read_templates(paths)
17
- @@templates = {}
18
- @@css_map ||= {}
19
- paths.each do |path|
20
- if File.directory?(path)
21
- Dir.glob(path+"/**/*.css") do |item|
22
- next if File.directory?(item)
23
- provides = css_provides(item)
24
- template = get_template(item)
25
- provides.each do |provide|
26
- @@templates[provide] = template if template
27
- end
28
- end
29
- end
30
- end
7
+ class << self
8
+ attr_accessor :host, :port, :fake
31
9
  end
32
10
 
33
- def self.set_css_map(css_map)
34
- @@css_map = css_map
11
+ def self.root
12
+ @root ||= File.expand_path '../..', __FILE__
13
+ @root
35
14
  end
36
15
 
37
- def self.css_provides(stylesheet_path)
38
- provides = []
39
- File.readlines(stylesheet_path).each do |line|
40
- match = /@provide ['|"](.*)['|"]/.match(line)
41
- if match
42
- provides << match[1]
43
- end
16
+ def self.render(template, data)
17
+ return '' if @fake
18
+ begin
19
+ res = Net::HTTP.post_form(URI.parse("http://#{@host || default_host}:#{@port || default_port}/t/" + template), {'params'=> data.to_json})
20
+ return res.body
21
+ rescue
22
+ return File.read(self.root + '/static/error.html')
44
23
  end
45
- provides
46
24
  end
47
25
 
48
- def self.get_template(stylesheet_path)
49
- template_path = stylesheet_path.sub(%r{\.css$}, ".erb")
50
- return nil unless File.exists?(template_path)
51
- return Erubis::Eruby.new(File.read(template_path))
26
+ def self.default_host
27
+ '127.0.0.1'
52
28
  end
53
29
 
30
+ def self.default_port
31
+ '8080'
32
+ end
33
+
54
34
  end
55
35
 
56
- Ahc.read_templates(['components']) if File.directory?('components')
57
-
58
36
  if defined? Rails
59
- ActionView::Template.register_template_handler(:ahcx, AhcxTemplateHandler)
37
+ config_path = "#{Rails.root}/config/ahc.yml"
38
+ config = {}
39
+ if File.exists?(config_path)
40
+ config = YAML.load_file(config_path)[Rails.env] || {}
41
+ end
42
+ Ahc.host = config['host']
43
+ Ahc.port = config['port']
44
+ Ahc.fake = config['fake']
60
45
  end
data/lib/ahc_helper.rb ADDED
@@ -0,0 +1,24 @@
1
+ module AhcHelper
2
+
3
+ def render_ahc(template)
4
+ if params[:format] == 'json'
5
+ render json: @data
6
+ else
7
+ render text: Ahc.render(template, @data)
8
+ end
9
+ end
10
+
11
+ end
12
+
13
+ module AhcInheritedResourcesHelper
14
+ include AhcHelper
15
+
16
+ def respond_with(*resources, &block)
17
+ controller = params[:controller].split('/').last
18
+ action = params[:action]
19
+ @data ||= {}
20
+ @data['resources'] = collection
21
+ render_ahc("#{controller}/#{action}")
22
+ end
23
+
24
+ end
data/spec/ahc_spec.rb CHANGED
@@ -1,25 +1,4 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Ahc" do
4
-
5
- it "should get css provides" do
6
- Ahc.css_provides('test_template/template.css').should == ['test.Template']
7
- end
8
-
9
- it "should return erb template" do
10
- template = Ahc.get_template('test_template/template.css')
11
- template.class.should == Erubis::Eruby
12
- end
13
-
14
- it "should read templates" do
15
- Ahc.read_templates(['test_template'])
16
- Ahc.render('test.Template', {"content" => "<div>Content</div>"}).should == "<div class='test'><div>Content</div></div>"
17
- end
18
-
19
- it "should be able to use css maps" do
20
- Ahc.read_templates(['test_template'])
21
- Ahc.set_css_map({"test" => "a"})
22
- Ahc.render('test.Template', {"content" => "<div>Content</div>"}).should == "<div class='a'><div>Content</div></div>"
23
- end
24
-
25
4
  end
data/static/error.html ADDED
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>Ahc server is not running.</h1>
54
+ </div>
55
+ <p>Please start ahc server to fix this problem.</p>
56
+ </body>
57
+ </html>
metadata CHANGED
@@ -1,36 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ahc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Andriy Romanov
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-16 00:00:00.000000000 Z
11
+ date: 2013-12-05 00:00:00.000000000 Z
13
12
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: erubis
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
13
  - !ruby/object:Gem::Dependency
31
14
  name: rspec
32
15
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
16
  requirements:
35
17
  - - ~>
36
18
  - !ruby/object:Gem::Version
@@ -38,7 +20,6 @@ dependencies:
38
20
  type: :development
39
21
  prerelease: false
40
22
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
23
  requirements:
43
24
  - - ~>
44
25
  - !ruby/object:Gem::Version
@@ -46,7 +27,6 @@ dependencies:
46
27
  - !ruby/object:Gem::Dependency
47
28
  name: rdoc
48
29
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
30
  requirements:
51
31
  - - ~>
52
32
  - !ruby/object:Gem::Version
@@ -54,7 +34,6 @@ dependencies:
54
34
  type: :development
55
35
  prerelease: false
56
36
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
37
  requirements:
59
38
  - - ~>
60
39
  - !ruby/object:Gem::Version
@@ -62,37 +41,33 @@ dependencies:
62
41
  - !ruby/object:Gem::Dependency
63
42
  name: bundler
64
43
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
44
  requirements:
67
- - - ! '>='
45
+ - - ~>
68
46
  - !ruby/object:Gem::Version
69
- version: '0'
47
+ version: '1.0'
70
48
  type: :development
71
49
  prerelease: false
72
50
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
51
  requirements:
75
- - - ! '>='
52
+ - - ~>
76
53
  - !ruby/object:Gem::Version
77
- version: '0'
54
+ version: '1.0'
78
55
  - !ruby/object:Gem::Dependency
79
56
  name: jeweler
80
57
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
58
  requirements:
83
59
  - - ~>
84
60
  - !ruby/object:Gem::Version
85
- version: 1.8.4
61
+ version: 1.8.7
86
62
  type: :development
87
63
  prerelease: false
88
64
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
65
  requirements:
91
66
  - - ~>
92
67
  - !ruby/object:Gem::Version
93
- version: 1.8.4
94
- description: Gem for using ahc components in rails application
95
- email: aromanov@partnerpedia.com
68
+ version: 1.8.7
69
+ description: Ahc allows you to move all your client side code to ahc server
70
+ email: judo.ras@gmail.com
96
71
  executables: []
97
72
  extensions: []
98
73
  extra_rdoc_files:
@@ -107,35 +82,34 @@ files:
107
82
  - README.rdoc
108
83
  - Rakefile
109
84
  - VERSION
85
+ - ahc.gemspec
110
86
  - lib/ahc.rb
111
- - lib/ahcx_template_handler.rb
87
+ - lib/ahc_helper.rb
112
88
  - spec/ahc_spec.rb
113
89
  - spec/spec_helper.rb
114
- - test_template/template.css
115
- - test_template/template.erb
90
+ - static/error.html
116
91
  homepage: http://github.com/romanoff/ahc
117
92
  licenses:
118
93
  - MIT
94
+ metadata: {}
119
95
  post_install_message:
120
96
  rdoc_options: []
121
97
  require_paths:
122
98
  - lib
123
99
  required_ruby_version: !ruby/object:Gem::Requirement
124
- none: false
125
100
  requirements:
126
- - - ! '>='
101
+ - - '>='
127
102
  - !ruby/object:Gem::Version
128
103
  version: '0'
129
104
  required_rubygems_version: !ruby/object:Gem::Requirement
130
- none: false
131
105
  requirements:
132
- - - ! '>='
106
+ - - '>='
133
107
  - !ruby/object:Gem::Version
134
108
  version: '0'
135
109
  requirements: []
136
110
  rubyforge_project:
137
- rubygems_version: 1.8.23
111
+ rubygems_version: 2.0.3
138
112
  signing_key:
139
- specification_version: 3
140
- summary: Gem for using ahc components in rails application
113
+ specification_version: 4
114
+ summary: Ahc allows you to move all your client side code to ahc server
141
115
  test_files: []
@@ -1,45 +0,0 @@
1
- require 'nokogiri'
2
- require 'htmlcompressor'
3
-
4
- class AhcxTemplateHandler
5
-
6
- def self.call(template)
7
- erb = ActionView::Template.registered_template_handler(:erb)
8
- source = erb.call(template)
9
- source + ";AhcxTemplateHandler.render(@output_buffer.to_s)"
10
- end
11
-
12
- def self.node_content(node)
13
- tag = node.name
14
- params = {}
15
- node.attributes.values.each do |node_attribute|
16
- params[node_attribute.name] = node_attribute.value
17
- end
18
- node.children.each do |child_node|
19
- child_node_tag, child_node_attr = child_node.name.split(':')
20
- if child_node.children.length == 1 && child_node.children.first.name == 'text'
21
- params[child_node_attr] = child_node.children.text
22
- else
23
- attr_value = ''
24
- child_node.children.each do |inside_node|
25
- attr_value += node_content(inside_node)
26
- end
27
- params[child_node_attr] = attr_value
28
- end
29
- end
30
- html = Ahc.render(tag, params)
31
- html
32
- end
33
-
34
- def self.render(xml)
35
- ahcx_source = "<document>#{xml}</document>"
36
- ahcx = Nokogiri::XML.parse(ahcx_source)
37
- content = ''
38
- ahcx.children.first.children.each do |node|
39
- content += node_content(node)
40
- end
41
- compressor = HtmlCompressor::Compressor.new(:remove_intertag_spaces => true)
42
- compressor.compress(content)
43
- end
44
-
45
- end
@@ -1,3 +0,0 @@
1
- /**
2
- * @provide 'test.Template'
3
- */
@@ -1 +0,0 @@
1
- <div class='<%= css['test']%>'><%= params['content']%></div>