lotus-helpers 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,69 @@
1
+ require 'lotus/helpers/html_helper/empty_html_node'
2
+
3
+ module Lotus
4
+ module Helpers
5
+ module HtmlHelper
6
+ # HTML node
7
+ #
8
+ # @since 0.1.0
9
+ # @api private
10
+ #
11
+ # @see Lotus::Helpers::HtmlHelper::EmptyHtmlNode
12
+ class HtmlNode < EmptyHtmlNode
13
+ # Initialize a new HTML node
14
+ #
15
+ # @param name [Symbol,String] the name of the tag
16
+ # @param content [String,Proc,Lotus::Helpers::HtmlHelper::HtmlBuilder,NilClass] the optional content
17
+ # @param attributes [Hash,NilClass] the optional tag attributes
18
+ #
19
+ # @return [Lotus::Helpers::HtmlHelper::HtmlNode]
20
+ def initialize(name, content, attributes)
21
+ @builder = HtmlBuilder.new
22
+ @name = name
23
+ @content = case content
24
+ when Hash
25
+ @attributes = content
26
+ nil
27
+ else
28
+ @attributes = attributes.to_h if attributes.respond_to?(:to_h)
29
+ content
30
+ end
31
+ end
32
+
33
+ # Resolve and return the output
34
+ #
35
+ # @return [String] the output
36
+ #
37
+ # @since 0.1.0
38
+ # @api private
39
+ #
40
+ # @see Lotus::Helpers::HtmlHelper::EmptyHtmlNode#to_s
41
+ def to_s
42
+ %(#{ super }#{ content }</#{ @name }>)
43
+ end
44
+
45
+ private
46
+ # Resolve the (nested) content
47
+ #
48
+ # @return [String] the content
49
+ #
50
+ # @since 0.1.0
51
+ # @api private
52
+ def content
53
+ case @content
54
+ when Proc
55
+ result = @builder.resolve(&@content)
56
+
57
+ if @builder.nested?
58
+ "\n#{ @builder }\n"
59
+ else
60
+ "\n#{ Utils::Escape.html(result) }\n"
61
+ end
62
+ else
63
+ Utils::Escape.html(@content)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,52 @@
1
+ module Lotus
2
+ module Helpers
3
+ # Routing helper for full stack Lotus web applications.
4
+ #
5
+ # For a given application called <tt>Web::Application</tt>, at runtime
6
+ # Lotus creates a routes factory called <tt>Web::Routes</tt>.
7
+ #
8
+ # By including this module in a view, it makes that factory avaliable as
9
+ # <tt>routes</tt>.
10
+ #
11
+ # @since 0.1.0
12
+ #
13
+ # @example Basic usage in template
14
+ # require 'lotus'
15
+ #
16
+ # module Web::Views::Home
17
+ # class Index
18
+ # include Web::View
19
+ # end
20
+ # end
21
+ #
22
+ # # ERB template
23
+ # # <%= routes.home_path %>
24
+ #
25
+ # @example Basic usage in view
26
+ # require 'lotus'
27
+ #
28
+ # module Web::Views::Home
29
+ # class Index
30
+ # include Web::View
31
+ # end
32
+ #
33
+ # def link_to_home
34
+ # %(<a href="#{ routes.home_path }">Home</a>)
35
+ # end
36
+ # end
37
+ #
38
+ # # ERB template
39
+ # # <%= link_to_home %>
40
+ module RoutingHelper
41
+ def self.included(base)
42
+ factory = "#{ Utils::String.new(base).namespace }::Routes"
43
+
44
+ base.class_eval <<-END_EVAL, __FILE__, __LINE__
45
+ def routes
46
+ #{ factory }
47
+ end
48
+ END_EVAL
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,5 +1,8 @@
1
1
  module Lotus
2
2
  module Helpers
3
- VERSION = "0.0.0"
3
+ # Define version
4
+ #
5
+ # @since 0.1.0
6
+ VERSION = '0.1.0'.freeze
4
7
  end
5
8
  end
@@ -4,20 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'lotus/helpers/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "lotus-helpers"
7
+ spec.name = 'lotus-helpers'
8
8
  spec.version = Lotus::Helpers::VERSION
9
- spec.authors = ["Luca Guidi"]
10
- spec.email = ["me@lucaguidi.com"]
9
+ spec.authors = ['Luca Guidi', 'Trung Lê']
10
+ spec.email = ['me@lucaguidi.com', 'trung.le@ruby-journal.com']
11
11
  spec.summary = %q{Lotus helpers}
12
- spec.description = %q{View helpers for Lotus}
13
- spec.homepage = "http://lotusrb.org"
14
- spec.license = "MIT"
12
+ spec.description = %q{View helpers for Ruby applications}
13
+ spec.homepage = 'http://lotusrb.org'
14
+ spec.license = 'MIT'
15
15
 
16
- spec.files = `git ls-files -z`.split("\x0")
16
+ spec.files = `git ls-files -- lib/* LICENSE.md README.md lotus-helpers.gemspec`.split($/)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
+ spec.required_ruby_version = '>= 2.0.0'
20
21
 
21
- spec.add_development_dependency "bundler", "~> 1.6"
22
- spec.add_development_dependency "rake"
22
+ spec.add_dependency 'lotus-utils', '~> 0.4'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.6'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'minitest', '~> 5.5'
23
27
  end
metadata CHANGED
@@ -1,15 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lotus-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
+ - Trung Lê
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-05-13 00:00:00.000000000 Z
12
+ date: 2015-03-23 00:00:00.000000000 Z
12
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: lotus-utils
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.4'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0.4'
13
28
  - !ruby/object:Gem::Dependency
14
29
  name: bundler
15
30
  requirement: !ruby/object:Gem::Requirement
@@ -28,29 +43,47 @@ dependencies:
28
43
  name: rake
29
44
  requirement: !ruby/object:Gem::Requirement
30
45
  requirements:
31
- - - ">="
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '10.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: minitest
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
32
61
  - !ruby/object:Gem::Version
33
- version: '0'
62
+ version: '5.5'
34
63
  type: :development
35
64
  prerelease: false
36
65
  version_requirements: !ruby/object:Gem::Requirement
37
66
  requirements:
38
- - - ">="
67
+ - - "~>"
39
68
  - !ruby/object:Gem::Version
40
- version: '0'
41
- description: View helpers for Lotus
69
+ version: '5.5'
70
+ description: View helpers for Ruby applications
42
71
  email:
43
72
  - me@lucaguidi.com
73
+ - trung.le@ruby-journal.com
44
74
  executables: []
45
75
  extensions: []
46
76
  extra_rdoc_files: []
47
77
  files:
48
- - ".gitignore"
49
- - Gemfile
50
- - LICENSE.txt
78
+ - LICENSE.md
51
79
  - README.md
52
- - Rakefile
53
80
  - lib/lotus/helpers.rb
81
+ - lib/lotus/helpers/escape_helper.rb
82
+ - lib/lotus/helpers/html_helper.rb
83
+ - lib/lotus/helpers/html_helper/empty_html_node.rb
84
+ - lib/lotus/helpers/html_helper/html_builder.rb
85
+ - lib/lotus/helpers/html_helper/html_node.rb
86
+ - lib/lotus/helpers/routing_helper.rb
54
87
  - lib/lotus/helpers/version.rb
55
88
  - lotus-helpers.gemspec
56
89
  homepage: http://lotusrb.org
@@ -65,7 +98,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
98
  requirements:
66
99
  - - ">="
67
100
  - !ruby/object:Gem::Version
68
- version: '0'
101
+ version: 2.0.0
69
102
  required_rubygems_version: !ruby/object:Gem::Requirement
70
103
  requirements:
71
104
  - - ">="
@@ -73,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
106
  version: '0'
74
107
  requirements: []
75
108
  rubyforge_project:
76
- rubygems_version: 2.2.2
109
+ rubygems_version: 2.4.5
77
110
  signing_key:
78
111
  specification_version: 4
79
112
  summary: Lotus helpers
data/.gitignore DELETED
@@ -1,22 +0,0 @@
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
- *.bundle
19
- *.so
20
- *.o
21
- *.a
22
- mkmf.log
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in lotus-helpers.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
-