rack-app-front_end 0.17.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a47c0c56a11e21c50839d76403af76d3b819efe
4
- data.tar.gz: 542aed97a167984d7eabc987b3ea7ab94de7805d
3
+ metadata.gz: 35dd901d76e7f1ef0ae63b36e5d94e5e4abe1cb4
4
+ data.tar.gz: ec0e189613fda7c97d12466e232250e24d3e3d15
5
5
  SHA512:
6
- metadata.gz: 32947ac03a1c15d57f7d914936fcc49c7de6df026f37cbdbcd3b206a7ed60ed8235f2128138226a01f44f69d90d2a2aab4c2a222b3e9fe2c620c59ae05debf51
7
- data.tar.gz: afd1d57447cb24bea1b9a44a130cfe0a12ebdcad6e4a4e9935a5aa20f1f4a2006ef071e7c9d939be4ced0e89833422b80c217a660e060a214552d9217bd7ce29
6
+ metadata.gz: a1781b849760ac47a34528e94eefef325332863d30faa4531f13d8782ce87c0f135f66d09bf9ead0de06f14d8ba68696dd67c152baa3f6bfafe5cc05e15390b9
7
+ data.tar.gz: 5d369c0b0d462ed7c915540a338ddcea577e652026d54cc5d3b6add0400edc25172243b3137b16fa1c798762b8742ce387d0fd9a0d7722664e8ff79cd0ec774e
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.17.0
1
+ 0.18.0
@@ -0,0 +1,18 @@
1
+ class Rack::App::FrontEnd::Helpers::HtmlDsl::Block
2
+
3
+ def initialize(&block)
4
+ @html = ''
5
+ instance_exec(&block)
6
+ end
7
+
8
+ def to_s
9
+ @html
10
+ end
11
+
12
+ def method_missing(method_name, *args, &block)
13
+ @html << ::Rack::App::FrontEnd::Helpers::HtmlDsl.build(method_name, *args, &block)
14
+ rescue ::Rack::App::FrontEnd::Helpers::HtmlDsl::UnImplementedError
15
+ super
16
+ end
17
+
18
+ end
@@ -0,0 +1,34 @@
1
+ module Rack::App::FrontEnd::Helpers::HtmlDsl::TagBuilder
2
+
3
+ extend self
4
+
5
+ def build(tag_name, *args, &block)
6
+
7
+ content = args.select { |a| a.is_a?(String) }.join
8
+ html_properties = args.select { |a| a.is_a?(Hash) }.reduce({}) do |properties, hash|
9
+ hash.each { |k, v| properties.merge!(k.to_s => v) }
10
+ properties
11
+ end
12
+
13
+ html = ''
14
+ html << "<#{tag_name}"
15
+
16
+ unless html_properties.empty?
17
+ html << ' '
18
+ html << html_properties.reduce([]) { |m, (k, v)| m << "#{k}=#{v.to_s.inspect}" }.join(' ')
19
+ end
20
+
21
+ if not content.empty? or not block.nil?
22
+ html << ">"
23
+ html << content
24
+ html << Rack::App::FrontEnd::Helpers::HtmlDsl::Block.new(&block).to_s unless block.nil?
25
+ html << "</#{tag_name}>"
26
+ else
27
+ html << "/>"
28
+ end
29
+
30
+ return html
31
+ end
32
+
33
+
34
+ end
@@ -0,0 +1,31 @@
1
+ module Rack::App::FrontEnd::Helpers::HtmlDsl
2
+ UnImplementedError = Class.new(StandardError)
3
+
4
+ require 'rack/app/front_end/helpers/html_dsl/block'
5
+ require 'rack/app/front_end/helpers/html_dsl/tag_builder'
6
+
7
+ def self.build(method_name, *args, &block)
8
+ case method_name.to_s
9
+
10
+ when /_tag$/
11
+ tag_name = method_name.to_s.sub(/_tag$/, '')
12
+ TagBuilder.build(tag_name,*args,&block)
13
+
14
+ else
15
+ raise(UnImplementedError)
16
+
17
+ end
18
+ end
19
+
20
+ def method_missing(method_name,*args,&block)
21
+ Rack::App::FrontEnd::Helpers::HtmlDsl.build(method_name,*args,&block)
22
+ rescue UnImplementedError
23
+ super
24
+ end
25
+
26
+ def form_tag(*args, &block)
27
+ args.unshift({'method' => "get", 'accept-charset' => "UTF-8"})
28
+ super
29
+ end
30
+
31
+ end
@@ -0,0 +1,9 @@
1
+ module Rack::App::FrontEnd::Helpers::Rendering
2
+
3
+ def render(template_path, variables={}, options={}, &block)
4
+ full_path = Rack::App::Utils.expand_path(template_path)
5
+ template = Rack::App::FrontEnd::Template.new(full_path,options)
6
+ return template.render(self, variables, &block)
7
+ end
8
+
9
+ end
@@ -0,0 +1,35 @@
1
+ module Rack::App::FrontEnd::Helpers::Table
2
+
3
+ def table_by(array_of_hash)
4
+
5
+ headers = array_of_hash.reduce([]) do |trs, hash|
6
+ trs.push(*hash.keys)
7
+ trs.uniq!
8
+ trs
9
+ end
10
+
11
+ o = Object.new
12
+ o.extend(Rack::App::FrontEnd::Helpers::HtmlDsl)
13
+
14
+ table_html = o.__send__ :table_tag do
15
+
16
+ tr_tag do
17
+ headers.each do |header|
18
+ td_tag String(header)
19
+ end
20
+ end
21
+
22
+ array_of_hash.each do |hash|
23
+ tr_tag do
24
+ headers.each do |header|
25
+ td_tag String(hash[header])
26
+ end
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ table_html
33
+ end
34
+
35
+ end
@@ -1,9 +1,9 @@
1
1
  module Rack::App::FrontEnd::Helpers
2
2
 
3
- def render(template_path, variables={}, options={}, &block)
4
- full_path = Rack::App::Utils.expand_path(template_path)
5
- template = Rack::App::FrontEnd::Template.new(full_path,options)
6
- return template.render(self, variables, &block)
7
- end
3
+ require 'rack/app/front_end/helpers/html_dsl'
4
+ require 'rack/app/front_end/helpers/table'
5
+ require 'rack/app/front_end/helpers/rendering'
6
+
7
+ include Rack::App::FrontEnd::Helpers::Rendering
8
8
 
9
9
  end
@@ -16,6 +16,7 @@ module Rack::App::FrontEnd::SingletonMethods
16
16
  @helpers ||= lambda {
17
17
  helpers_module = Module.new
18
18
  helpers_module.__send__(:include, Rack::App::FrontEnd::Helpers)
19
+ helpers_module.__send__(:extend, Rack::App::FrontEnd::SyntaxSugar::DSL)
19
20
  }.call
20
21
 
21
22
  @helpers.class_eval(&block) unless block.nil?
@@ -0,0 +1,8 @@
1
+ module Rack::App::FrontEnd::SyntaxSugar::DSL
2
+
3
+ def helper(symbolic_name)
4
+ module_name = "Rack::App::FrontEnd::Helpers::#{symbolic_name.to_s.split('_').collect(&:capitalize).join}"
5
+ ObjectSpace.each_object(Module).select{|m| not m.is_a?(Class) }.find {|m| m.to_s == module_name }
6
+ end
7
+
8
+ end
@@ -0,0 +1,3 @@
1
+ module Rack::App::FrontEnd::SyntaxSugar
2
+ require 'rack/app/front_end/syntax_sugar/dsl'
3
+ end
@@ -8,6 +8,7 @@ module Rack::App::FrontEnd
8
8
  require 'rack/app/front_end/version'
9
9
  require 'rack/app/front_end/helpers'
10
10
  require 'rack/app/front_end/template'
11
+ require 'rack/app/front_end/syntax_sugar'
11
12
  require 'rack/app/front_end/folder_mounter'
12
13
  require 'rack/app/front_end/endpoint_methods'
13
14
  require 'rack/app/front_end/singleton_methods'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-app-front_end
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-04 00:00:00.000000000 Z
11
+ date: 2016-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -102,7 +102,14 @@ files:
102
102
  - lib/rack/app/front_end/endpoint_methods.rb
103
103
  - lib/rack/app/front_end/folder_mounter.rb
104
104
  - lib/rack/app/front_end/helpers.rb
105
+ - lib/rack/app/front_end/helpers/html_dsl.rb
106
+ - lib/rack/app/front_end/helpers/html_dsl/block.rb
107
+ - lib/rack/app/front_end/helpers/html_dsl/tag_builder.rb
108
+ - lib/rack/app/front_end/helpers/rendering.rb
109
+ - lib/rack/app/front_end/helpers/table.rb
105
110
  - lib/rack/app/front_end/singleton_methods.rb
111
+ - lib/rack/app/front_end/syntax_sugar.rb
112
+ - lib/rack/app/front_end/syntax_sugar/dsl.rb
106
113
  - lib/rack/app/front_end/template.rb
107
114
  - lib/rack/app/front_end/template/default_layout.rb
108
115
  - lib/rack/app/front_end/template/default_template.rb