left_side 0.0.2

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.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .tags
4
+ .tags*
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in left_side.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 soffolk
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # LeftSide
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'left_side'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install left_side
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/left_side.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'left_side/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "left_side"
8
+ gem.version = LeftSide::VERSION
9
+ gem.authors = ["soffolk"]
10
+ gem.email = ["zlx.star@gmail.com"]
11
+ gem.description = %q{It provide left_side and highlight function web app, base on cells and for rails app}
12
+ gem.summary = %q{left_side and highlight}
13
+ gem.homepage = "https://github.com/zlx/left_side"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "cells", "~> 3.7.1"
21
+ gem.add_dependency "rails", "~> 3.2.6"
22
+ end
@@ -0,0 +1,8 @@
1
+ .left-side {
2
+ background-color: whiteSmoke;
3
+ width: 11.76462%;
4
+ }
5
+
6
+ .left-side a {
7
+ color: #08C;
8
+ }
@@ -0,0 +1,41 @@
1
+ require 'yaml'
2
+ require 'active_support/core_ext'
3
+
4
+ module LeftSide
5
+ class Base
6
+
7
+ class << self
8
+
9
+ def set_up
10
+ new
11
+ end
12
+
13
+ def init_section_method
14
+ @@sections = YAML.load_file(File.join(File.dirname(__FILE__), 'section.yml'))
15
+ define_section_method
16
+ end
17
+
18
+ def define_section_method
19
+ @@sections.keys.each do |section|
20
+
21
+ send(:define_method, section) do
22
+ @@sections[section]
23
+ end
24
+
25
+ # define method alias
26
+ hash = set_up.send section.to_sym
27
+ # fetch values from hash with sub_hash(2 level at most)
28
+ urls = hash.map{|k, v| v.is_a?(Hash) ? v.map{|kk, vv| vv} : v}.join(',').split(',')
29
+ urls.each do |url|
30
+ # fetch controller_name from url(producted by routes)
31
+ controller_name = ::Rails.application.routes.recognize_path(url)[:controller].scan(/\w+$/).first.singularize
32
+ unless respond_to? controller_name
33
+ send(:alias_method, controller_name, section)
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,20 @@
1
+ <div class='left-side'>
2
+ <ul class="nav-list">
3
+ <% @sections.each do |name, section| %>
4
+ <li class="nav-header">
5
+ <%= name %>
6
+ </li>
7
+ <% section.each do |name, link| %>
8
+ <% if link.is_a? Array%>
9
+ <li class="<%= live_active?(link) %>">
10
+ <%= link_to name, link.first %>
11
+ </li>
12
+ <% else %>
13
+ <li class="<%= live_active?(link) %>">
14
+ <%= link_to name, link %>
15
+ </li>
16
+ <% end -%>
17
+ <% end -%>
18
+ <% end -%>
19
+ <ul>
20
+ </div>
@@ -0,0 +1,15 @@
1
+ require 'cells'
2
+
3
+ class LeftSideCell < Cell::Rails
4
+
5
+ def base(args)
6
+ LeftSide::Base.init_section_method
7
+ if LeftSide::Base.new.respond_to? args[:section]
8
+ @sections = LeftSide::Base.new.send args[:section]
9
+ else
10
+ render :nothing => true and return
11
+ end
12
+ append_view_path(File.dirname(__FILE__))
13
+ render
14
+ end
15
+ end
@@ -0,0 +1,30 @@
1
+ class String
2
+ def get_params
3
+ params_str = self.split("?")[1]
4
+ return {} unless params_str
5
+ params_str.split('&').inject({}) do |hash, str|
6
+ arr = str.split('=')
7
+ if arr[0] =~ /(\w*)\[(\w*)\]/
8
+ hash.merge($1 => {$2 => arr[1]})
9
+ else
10
+ hash.merge(arr[0] => arr[1])
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ class Hash
17
+ def extract(*keys)
18
+ result = {}
19
+ keys.flatten.each {|key| result[key] = self[key] }
20
+ result
21
+ end
22
+
23
+ def fixed_hash
24
+ g = {}
25
+ self.each_pair do |k, v|
26
+ g[k.to_s] = v.is_a?(Hash) ? v.fixed_hash : v.to_s
27
+ end
28
+ g
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ # coding: utf-8
2
+ module LeftSide
3
+ module Rails
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,34 @@
1
+ require 'uri'
2
+ require File.join(File.dirname(__FILE__), 'core_ext')
3
+
4
+ module LeftSide
5
+ module Rails
6
+
7
+ module Helper
8
+ # link can be a string or a set of string
9
+ def live_active?(link, active_class = "active")
10
+ if link.is_a?(Array)
11
+ link.inject(nil){|s, lin| s ||= live_active_helper?(lin, active_class)}
12
+ elsif link.is_a?(String)
13
+ live_active_helper?(link, active_class)
14
+ end || ""
15
+ end
16
+
17
+ # use live_active? instead of
18
+ def live_active_helper?(link, active_class)
19
+ # regexp = link["manage"].present? ? /\/manage\/([\w\/]*)/ : /\/my\/([\w\/]*)/
20
+ # regexp = /\/\w*\/([\w\/]*)/
21
+ expect_uri = URI.unescape(link)
22
+ current_uri = URI.unescape(request.url)
23
+ link_params = link.get_params
24
+ expect_hash = ::Rails.application.routes.recognize_path(expect_uri)
25
+ expect_hash[:controller] == request[:controller] && expect_hash[:action] == request[:action] &&\
26
+ request.params.extract(link_params.keys).fixed_hash == link_params ? active_class : nil
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ ActionView::Base.class_eval do
33
+ include ::LeftSide::Rails::Helper
34
+ end
@@ -0,0 +1,25 @@
1
+ require 'cells'
2
+ require File.join(File.dirname(__FILE__), 'cells', 'left_side_cell')
3
+
4
+ module LeftSide
5
+ module Rails
6
+
7
+ module ActionView
8
+ # render left side
9
+ #
10
+ # Example:
11
+ #
12
+ # <%= render_left_side :order %>
13
+ #
14
+ # It will render left side in this page
15
+ #
16
+ def render_left_side(name)
17
+ render_cell :left_side, :base, {:section => name}
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ ActionView::Base.class_eval do
24
+ include ::LeftSide::Rails::ActionView
25
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ all:
3
+ blogs:
4
+ index: ["/blogs", "/blogs/new"]
5
+ tasks:
6
+ index: "my_tasks"
7
+ new: "my_tasks/new"
@@ -0,0 +1,3 @@
1
+ module LeftSide
2
+ VERSION = "0.0.2"
3
+ end
data/lib/left_side.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'left_side/rails'
2
+ require 'left_side/base'
3
+ require 'left_side/helper'
4
+ require 'left_side/engine'
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: left_side
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.2
6
+ platform: ruby
7
+ authors:
8
+ - soffolk
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ type: :runtime
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.7.1
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: 3.7.1
29
+ name: cells
30
+ - !ruby/object:Gem::Dependency
31
+ type: :runtime
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 3.2.6
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 3.2.6
45
+ name: rails
46
+ description: It provide left_side and highlight function web app, base on cells and
47
+ for rails app
48
+ email:
49
+ - zlx.star@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - left_side.gemspec
60
+ - lib/assets/stylesheets/base.css
61
+ - lib/left_side.rb
62
+ - lib/left_side/base.rb
63
+ - lib/left_side/cells/left_side/base.html.erb
64
+ - lib/left_side/cells/left_side_cell.rb
65
+ - lib/left_side/core_ext.rb
66
+ - lib/left_side/engine.rb
67
+ - lib/left_side/helper.rb
68
+ - lib/left_side/rails.rb
69
+ - lib/left_side/section.yml
70
+ - lib/left_side/version.rb
71
+ homepage: https://github.com/zlx/left_side
72
+ licenses: []
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 1.8.24
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: left_side and highlight
95
+ test_files: []