rack-app-front_end 0.3.0 → 0.5.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: 51ef4d45f171e6d23cac5c08eab2f9d269099766
4
- data.tar.gz: 572457c778986b295db92390cf679b7118872abd
3
+ metadata.gz: 2d6dbf80557515cdc26e9a3d860655fcc405e6b5
4
+ data.tar.gz: 94b8f3f6d3432c16563123064b9013ba6089223d
5
5
  SHA512:
6
- metadata.gz: a2a5a6ea812512d89edf8fbe192b600b52aacf9aae51368e215a88eaf9271aae61b7f713fd99adb13fb26c5274f9bd4ed4f951bee0c1692dfa51f01b44a718b8
7
- data.tar.gz: 32e23043f82402a7e133cf471544001f22030b3f72c9e823fbb933b728d3438372fd61a450aa47b32c9f0f81168a2ecd99dcd5e41ed4e450507a43ecd01aa7d1
6
+ metadata.gz: 53408b6280b21513df6da1af7f364bd9f60a8f76f66b838783a95d0dc4164c37b0c15228762a4518b524114e51d6dea5beb585e67a6ef665d6b60bc23314830c
7
+ data.tar.gz: 795681e871974c662a086285ec078f46c7bceb7ca2830e7c0b8a58b3fc888e721291dd518c8e673d155e1f70f8b1f229bc37d1f38c38051b14598889b55c1a4a
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
- --format documentation
1
+ #--format documentation
2
2
  --color
@@ -1,4 +1,19 @@
1
1
  language: ruby
2
+ script: rspec spec
3
+
2
4
  rvm:
3
- - 2.1.2
4
- before_install: gem install bundler -v 1.10.6
5
+
6
+ - 1.9
7
+ - 2.0
8
+ - 2.1
9
+
10
+ - ruby-head
11
+ - jruby-head
12
+
13
+ branches:
14
+ only:
15
+ - master
16
+
17
+ notifications:
18
+ email:
19
+ - adamluzsi@gmail.com
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Rack::App::FrontEnd
1
+ # Rack::App::FrontEnd [![Build Status](https://travis-ci.org/adamluzsi/rack-app-front_end.rb.svg?branch=master)](https://travis-ci.org/adamluzsi/rack-app-front_end.rb)
2
2
 
3
3
  This is an extend module for Rack::App to have FrontEnd framework extensions for the core app class
4
4
 
@@ -29,6 +29,12 @@ class App < Rack::App
29
29
  mount_folder '/from/project/root/path'
30
30
  mount_folder 'relative/folder/from/this/file/to/folder'
31
31
 
32
+
33
+ get '/some_url' do
34
+ @items = []
35
+ render 'some.html.erb'
36
+ end
37
+
32
38
  end
33
39
 
34
40
  ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.5.0
@@ -1,12 +1,19 @@
1
1
  require 'rack/app'
2
2
  module Rack::App::FrontEnd
3
3
 
4
+ require 'tilt'
5
+ require 'tilt/plain'
6
+
4
7
  require 'rack/app/front_end/version'
5
8
  require 'rack/app/front_end/utils'
6
9
  require 'rack/app/front_end/template'
7
- require 'rack/app/front_end/layout'
8
10
  require 'rack/app/front_end/view'
9
11
  require 'rack/app/front_end/folder_mounter'
12
+ require 'rack/app/front_end/endpoint_methods'
13
+
14
+ def self.extended(klass)
15
+ klass.__send__(:include, ::Rack::App::FrontEnd::EndpointMethods)
16
+ end
10
17
 
11
18
  def mount_folder(folder_path)
12
19
  Rack::App::FrontEnd::FolderMounter.new(self).mount(Rack::App::FrontEnd::Utils.get_full_path(folder_path))
@@ -15,12 +22,8 @@ module Rack::App::FrontEnd
15
22
  alias mount_templates_from mount_folder
16
23
 
17
24
  def layout(layout_path=nil)
18
- @layout = Rack::App::FrontEnd::Layout.new(Rack::App::FrontEnd::Utils.get_full_path(layout_path)) unless layout_path.nil?
19
- @layout || Rack::App::FrontEnd::Layout.new(nil)
20
- end
21
-
22
- def default_layout
23
- # code here
25
+ @layout = Rack::App::FrontEnd::Utils.get_full_path(layout_path) unless layout_path.nil?
26
+ @layout
24
27
  end
25
28
 
26
- end
29
+ end
@@ -0,0 +1,28 @@
1
+ module Rack::App::FrontEnd::EndpointMethods
2
+
3
+ def render(template_path)
4
+
5
+ template_full_path = if template_path.to_s[0] == '/'
6
+ project_file_path = Rack::App::Utils.pwd(template_path)
7
+ File.exist?(project_file_path) ? project_file_path : template_path
8
+
9
+ else
10
+
11
+ app_dirname = File.join(
12
+ File.dirname([caller[0]].flatten.first.split(/\.(?:rb|ru):\d/)[0]),
13
+ Rack::App::FrontEnd::Utils.underscore(self.class)
14
+ )
15
+
16
+ File.join(app_dirname, template_path)
17
+
18
+ end
19
+
20
+ options = {}
21
+ options[:layout]= self.class.layout if self.class.respond_to?(:layout)
22
+ template = Rack::App::FrontEnd::Template.new(template_full_path, options)
23
+
24
+ return template.render(self)
25
+
26
+ end
27
+
28
+ end
@@ -1,5 +1,7 @@
1
1
  class Rack::App::FrontEnd::FolderMounter
2
2
 
3
+ LAST_MODIFIED_HEADER = "Last-Modified"
4
+
3
5
  def initialize(app_class)
4
6
  @app_class = app_class
5
7
  end
@@ -8,8 +10,7 @@ class Rack::App::FrontEnd::FolderMounter
8
10
  template_paths_for(absolute_folder_path).each do |template_path|
9
11
 
10
12
  request_path = request_path_by(absolute_folder_path, template_path)
11
- template = Rack::App::FrontEnd::Template.new(template_path, fallback_handler: Rack::App::File::Streamer)
12
- create_endpoint_for(request_path, template)
13
+ create_endpoint_for(request_path, template_path)
13
14
 
14
15
  end
15
16
  end
@@ -17,31 +18,21 @@ class Rack::App::FrontEnd::FolderMounter
17
18
  protected
18
19
 
19
20
  def template_paths_for(source_folder_path)
20
- Dir.glob(File.join(source_folder_path, '**', '*'))
21
- .select { |p| not File.directory?(p) }
21
+ Dir.glob(File.join(source_folder_path, '**', '*')).select { |p| not File.directory?(p) }
22
22
  end
23
23
 
24
- def create_endpoint_for(request_path, template)
24
+ def create_endpoint_for(request_path, template_path)
25
25
  @app_class.class_eval do
26
26
 
27
27
  get(request_path) do
28
- result = template.render(self)
29
- if result.respond_to?(:each)
30
- response.body = result
31
- else
32
- response.write(self.class.layout.render(result))
33
- end
34
- response.finish
28
+ render(template_path)
35
29
  end
36
30
 
37
31
  end
38
32
  end
39
33
 
40
34
  def request_path_by(source_folder_path, template_path)
41
- Rack::Utils.clean_path_info template_path
42
- .sub(source_folder_path, '')
43
- .split(File::Separator).join('/')
44
-
35
+ Rack::Utils.clean_path_info(template_path.sub(source_folder_path, '').split(File::Separator).join('/'))
45
36
  end
46
37
 
47
38
  end
@@ -1,7 +1,7 @@
1
1
  require 'tilt'
2
2
  class Rack::App::FrontEnd::Template
3
3
 
4
- require 'rack/app/front_end/template/plain_text'
4
+ require 'rack/app/front_end/template/default_layout'
5
5
 
6
6
  def render(*args, &block)
7
7
  return render_result(*args, &block)
@@ -9,29 +9,23 @@ class Rack::App::FrontEnd::Template
9
9
 
10
10
  protected
11
11
 
12
- def initialize(file_path,fallback_handler: Rack::App::FrontEnd::Template::PlainText)
13
- @fallback_handler = fallback_handler
12
+ def initialize(file_path, options={})
14
13
  @file_path = file_path
14
+ @options = options
15
15
  end
16
16
 
17
17
  def render_result(*args, &block)
18
- if it_is_a_template?
19
- render_with_tilt_templates(args, block)
20
- else
21
- @fallback_handler.new(@file_path).render(*args, &block)
22
- end
18
+ return Rack::App::File::Streamer.new(@file_path) unless it_is_a_template?
19
+
20
+ layout.render{ Tilt.new(@file_path).render(*args,&block) }
23
21
  end
24
22
 
25
23
  def it_is_a_template?
26
24
  not Tilt.templates_for(@file_path).empty?
27
25
  end
28
26
 
29
- def render_with_tilt_templates(args, block)
30
- file_content = File.read(@file_path)
31
- Tilt.templates_for(@file_path).each do |template_engine|
32
- file_content = template_engine.new { file_content }.render(*args, &block)
33
- end
34
- return file_content
27
+ def layout
28
+ @options[:layout] ? Tilt.new(@options[:layout]) : DefaultLayout
35
29
  end
36
30
 
37
- end
31
+ end
@@ -0,0 +1,8 @@
1
+ module Rack::App::FrontEnd::Template::DefaultLayout
2
+ extend self
3
+
4
+ def render(&block)
5
+ block.call
6
+ end
7
+
8
+ end
@@ -4,11 +4,22 @@ module Rack::App::FrontEnd::Utils
4
4
 
5
5
  def get_full_path(file_path,caller_index=1)
6
6
  return nil if file_path.nil?
7
- if file_path.to_s[0] == File::Separator
7
+ if file_path.to_s[0] == '/'
8
8
  Rack::App::Utils.pwd(file_path)
9
9
  else
10
- File.join(File.dirname(caller[caller_index].split(':')[0]),file_path)
10
+ File.expand_path(File.join(File.dirname(caller[caller_index].split(':')[0]),file_path))
11
11
  end
12
12
  end
13
13
 
14
+ # Based on ActiveSupport, removed inflections.
15
+ # https://github.com/rails/rails/blob/v4.1.0.rc1/activesupport/lib/active_support/inflector/methods.rb
16
+ def underscore(camel_cased_word)
17
+ word = camel_cased_word.to_s.gsub('::', '/')
18
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
19
+ word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
20
+ word.tr!("-", "_")
21
+ word.downcase!
22
+ word
23
+ end
24
+
14
25
  end
@@ -1,4 +1,2 @@
1
- Rack ||= Module.new
2
- Rack::App ||= Class.new
3
- Rack::App::FrontEnd ||= Module.new
1
+ require 'rack/app/front_end'
4
2
  Rack::App::FrontEnd::VERSION = File.read(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'VERSION')).strip
@@ -1,12 +1,9 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'rack/app/front_end/version'
5
2
 
6
3
  Gem::Specification.new do |spec|
7
4
 
8
5
  spec.name = "rack-app-front_end"
9
- spec.version = Rack::App::FrontEnd::VERSION
6
+ spec.version = File.read(File.join(File.dirname(__FILE__), 'VERSION')).strip
10
7
  spec.authors = ["Adam Luzsi"]
11
8
  spec.email = ["adamluzsi@gmail.com"]
12
9
 
@@ -19,13 +16,13 @@ Gem::Specification.new do |spec|
19
16
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
17
  spec.require_paths = ["lib"]
21
18
 
22
- spec.add_development_dependency "bundler", "~> 1.10"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "rspec"
19
+ spec.required_ruby_version = '>= 1.9.3'
25
20
 
26
- spec.add_development_dependency "maruku"
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
27
24
 
28
- spec.add_dependency 'rack-app'
25
+ spec.add_dependency 'rack-app','>= 0.10.0'
29
26
  spec.add_dependency 'kramdown'
30
27
  spec.add_dependency 'tilt'
31
28
 
metadata CHANGED
@@ -1,45 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-app-front_end
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.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: 2015-12-11 00:00:00.000000000 Z
11
+ date: 2016-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.10'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.10'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '10.0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - ">="
@@ -53,7 +39,7 @@ dependencies:
53
39
  - !ruby/object:Gem::Version
54
40
  version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
- name: maruku
42
+ name: rspec
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - ">="
@@ -72,14 +58,14 @@ dependencies:
72
58
  requirements:
73
59
  - - ">="
74
60
  - !ruby/object:Gem::Version
75
- version: '0'
61
+ version: 0.10.0
76
62
  type: :runtime
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - ">="
81
67
  - !ruby/object:Gem::Version
82
- version: '0'
68
+ version: 0.10.0
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: kramdown
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -126,10 +112,10 @@ files:
126
112
  - bin/console
127
113
  - bin/setup
128
114
  - lib/rack/app/front_end.rb
115
+ - lib/rack/app/front_end/endpoint_methods.rb
129
116
  - lib/rack/app/front_end/folder_mounter.rb
130
- - lib/rack/app/front_end/layout.rb
131
117
  - lib/rack/app/front_end/template.rb
132
- - lib/rack/app/front_end/template/plain_text.rb
118
+ - lib/rack/app/front_end/template/default_layout.rb
133
119
  - lib/rack/app/front_end/utils.rb
134
120
  - lib/rack/app/front_end/version.rb
135
121
  - lib/rack/app/front_end/view.rb
@@ -145,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
131
  requirements:
146
132
  - - ">="
147
133
  - !ruby/object:Gem::Version
148
- version: '0'
134
+ version: 1.9.3
149
135
  required_rubygems_version: !ruby/object:Gem::Requirement
150
136
  requirements:
151
137
  - - ">="
@@ -1,21 +0,0 @@
1
- class Rack::App::FrontEnd::Layout < Rack::App::FrontEnd::Template
2
-
3
- def render(content)
4
- return render_result(content)
5
- end
6
-
7
- protected
8
-
9
- def render_result(content)
10
- if it_is_a_template? and layout_file_is_exists?
11
- render_with_tilt_templates([], -> { content })
12
- else
13
- return content
14
- end
15
- end
16
-
17
- def layout_file_is_exists?
18
- File.exists?(@file_path)
19
- end
20
-
21
- end
@@ -1,27 +0,0 @@
1
- class Rack::App::FrontEnd::Template::PlainText
2
-
3
- include Enumerable
4
-
5
- def each(&block)
6
- file { |f| f.each(&block) }
7
- end
8
-
9
- def render(object=nil)
10
- file { |f| f.read }
11
- end
12
-
13
- protected
14
-
15
- def initialize(file_path)
16
- @file_path = file_path
17
- @file = File.open(file_path)
18
- end
19
-
20
- def file(&block)
21
- @file.reopen(@file_path) if @file.closed?
22
- return block.call(@file)
23
- ensure
24
- @file.close
25
- end
26
-
27
- end