mintaka 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 10a6a8b96df3a2ac999428317e15605663be2677
4
+ data.tar.gz: 0d0af8ead17dfe39b9d839b3d2b82c3ca5e49727
5
+ SHA512:
6
+ metadata.gz: b7dd92b2e47976e6b0d3c896f0bcbd016c81dce28ca2eeb7e1c0699714a6dc3810699466a6bab8f696950d30bdd6a8c19c22a670b60dc0f97edc018cb43a14f3
7
+ data.tar.gz: 5bfd88f49ddb1660e4dab508154d79d5473ad8f1b3d2c5afcbf3041f17daf53440483f06929f48b4956f7856756da59c6b23038cb3ad06dac828b01b0ae5a6d7
@@ -0,0 +1,7 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/db/*.sqlite3-journal
6
+ test/dummy/log/*.log
7
+ test/dummy/tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem "appraisal"
6
+ gem "rspec-rails", "~> 3.5.0"
@@ -0,0 +1,20 @@
1
+ Copyright 2017 jcottobboni
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ # Mintaka
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'mintaka'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install mintaka
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Mintaka'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,39 @@
1
+ module Mintaka::StaticPage
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ layout ->(_) { Mintaka.layout }
6
+
7
+ rescue_from ActionView::MissingTemplate do |exception|
8
+ if exception.message =~ %r{Missing template #{page_finder.content_path}}
9
+ invalid_page
10
+ else
11
+ raise exception
12
+ end
13
+ end
14
+
15
+ rescue_from Mintaka::InvalidPageIdError, with: :invalid_page
16
+ end
17
+
18
+ def show
19
+ render template: current_page
20
+ end
21
+
22
+ def invalid_page
23
+ raise ActionController::RoutingError, "No such page: #{params[:id]}"
24
+ end
25
+
26
+ private
27
+
28
+ def current_page
29
+ page_finder.find
30
+ end
31
+
32
+ def page_finder
33
+ page_finder_factory.new(params[:id])
34
+ end
35
+
36
+ def page_finder_factory
37
+ Mintaka::PageFinder
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ class Mintaka::PagesController < ApplicationController
2
+ include Mintaka::StaticPage
3
+ end
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
6
+ ENGINE_PATH = File.expand_path('../../lib/mintaka/engine', __FILE__)
7
+
8
+ # Set up gems listed in the Gemfile.
9
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
10
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
11
+
12
+ require 'rails/all'
13
+ require 'rails/engine/commands'
@@ -0,0 +1,10 @@
1
+ Mintaka.parent_engine.routes.draw do
2
+ if Mintaka.home_page
3
+ get "/#{Mintaka.home_page}", to: redirect('/')
4
+ root to: 'mintaka/pages#show', id: Mintaka.home_page
5
+ end
6
+
7
+ if Mintaka.routes
8
+ get Mintaka.route_drawer.match_attributes
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ require 'active_support/core_ext/string'
2
+ require 'active_support/core_ext/module/attribute_accessors'
3
+
4
+ require 'mintaka/configuration'
5
+ require 'mintaka/constraints/root_route'
6
+ require "mintaka/page"
7
+ require "mintaka/page_collector"
8
+ require 'mintaka/page_finder'
9
+ require 'mintaka/route_drawers/default'
10
+ require 'mintaka/route_drawers/root'
11
+ require 'mintaka/version'
12
+
13
+ module Mintaka
14
+ extend Configuration
15
+ require 'mintaka/engine' if defined?(Rails)
16
+ end
@@ -0,0 +1,36 @@
1
+ module Mintaka
2
+ module Configuration
3
+ attr_accessor(
4
+ :content_path,
5
+ :home_page,
6
+ :layout,
7
+ :parent_engine,
8
+ :route_drawer,
9
+ :routes,
10
+ )
11
+
12
+ def configure
13
+ yield self
14
+ end
15
+
16
+ def self.extended(base)
17
+ base.set_default_configuration
18
+ end
19
+
20
+ def page_ids
21
+ Mintaka::PageCollector.new(Mintaka.full_path).page_ids
22
+ end
23
+
24
+ def full_path
25
+ Rails.root.join("app", "views", Mintaka.content_path)
26
+ end
27
+
28
+ def set_default_configuration
29
+ self.content_path = 'pages/'
30
+ self.home_page = nil
31
+ self.layout = 'application'
32
+ self.route_drawer = Mintaka::RouteDrawers::Default
33
+ self.routes = true
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,29 @@
1
+ module Mintaka
2
+ module Constraints
3
+ # Routing constraint to validate request.path has a corresponding view
4
+ class RootRoute
5
+ class << self
6
+ def matches?(request)
7
+ page_id = clean_page_path(request.path)
8
+ pattern = file_pattern(page_id)
9
+
10
+ Dir.glob(pattern).any?
11
+ end
12
+
13
+ private
14
+
15
+ def clean_page_path(request_path)
16
+ request_path.sub(/\.html$/, "")
17
+ end
18
+
19
+ def file_pattern(page_id)
20
+ "#{content_path}#{page_id}.html*"
21
+ end
22
+
23
+ def content_path
24
+ Rails.root.join("app", "views", Mintaka.content_path).to_s
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ module Mintaka
2
+ class Engine < Rails::Engine
3
+ initializer "Set up default parent engine" do |app|
4
+ Mintaka.parent_engine ||= Rails.application
5
+ end
6
+
7
+ initializer "Require concerns path" do |app|
8
+ concerns_path = "app/controllers/concerns"
9
+
10
+ unless app.paths.keys.include?(concerns_path)
11
+ app.paths.add(concerns_path)
12
+ end
13
+ end
14
+
15
+ initializer "Require for Rails 3" do |app|
16
+ if defined?(Rails) && Rails::VERSION::MAJOR == 3
17
+ require "concerns/mintaka/static_page"
18
+ require "mintaka/pages_controller"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,44 @@
1
+ module Mintaka
2
+ class Page
3
+ attr_reader :content_path, :file_path
4
+
5
+ def initialize(content_path, file_path)
6
+ @content_path = content_path
7
+ @file_path = file_path
8
+ end
9
+
10
+ def id
11
+ file_path.gsub(content_path, "").gsub(html_file_pattern, "")
12
+ end
13
+
14
+ def valid?
15
+ exists? && file_in_content_path? && !directory? && !partial? && html?
16
+ end
17
+
18
+ private
19
+
20
+ def exists?
21
+ File.exists?(file_path)
22
+ end
23
+
24
+ def file_in_content_path?
25
+ file_path.start_with?(content_path)
26
+ end
27
+
28
+ def directory?
29
+ FileTest.directory?(file_path)
30
+ end
31
+
32
+ def partial?
33
+ File.basename(file_path).first == "_"
34
+ end
35
+
36
+ def html?
37
+ !file_path.match(html_file_pattern).nil?
38
+ end
39
+
40
+ def html_file_pattern
41
+ /\.(html)(\.[a-z]+)?$/
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,23 @@
1
+ module Mintaka
2
+ require "find"
3
+
4
+ class PageCollector
5
+ attr_reader :content_path
6
+
7
+ def initialize(content_path)
8
+ @content_path = content_path.to_s
9
+ end
10
+
11
+ def page_ids
12
+ pages.select(&:valid?).map(&:id)
13
+ end
14
+
15
+ private
16
+
17
+ def pages
18
+ Find.find(content_path).map do |file_path|
19
+ Mintaka::Page.new(content_path, file_path)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,51 @@
1
+ module Mintaka
2
+ # A command for finding pages by id. This encapsulates the concepts of
3
+ # mapping page names to file names.
4
+ class PageFinder
5
+ VALID_CHARACTERS = "a-zA-Z0-9~!@$%^&*()#`_+-=<>\"{}|[];',?".freeze
6
+
7
+ def initialize(page_id)
8
+ @page_id = page_id
9
+ end
10
+
11
+ # Produce a template path to the page, in a format understood by
12
+ # `render :template => find`
13
+ def find
14
+ "#{content_path}#{clean_path}"
15
+ end
16
+
17
+ def content_path
18
+ Mintaka.content_path
19
+ end
20
+
21
+ protected
22
+
23
+ # The raw page id passed in by the user
24
+ attr_reader :page_id
25
+
26
+ private
27
+
28
+ def clean_path
29
+ path = Pathname.new("/#{clean_id}")
30
+ path.cleanpath.to_s[1..-1].tap do |p|
31
+ if p.blank?
32
+ raise InvalidPageIdError.new "Invalid page id: #{@page_id}"
33
+ end
34
+ end
35
+ end
36
+
37
+ def clean_id
38
+ @page_id.tr("^#{VALID_CHARACTERS}", "").tap do |id|
39
+ if invalid_page_id?(id)
40
+ raise InvalidPageIdError.new "Invalid page id: #{@page_id}"
41
+ end
42
+ end
43
+ end
44
+
45
+ def invalid_page_id?(id)
46
+ id.blank? || (id.first == ".")
47
+ end
48
+ end
49
+
50
+ class InvalidPageIdError < StandardError; end
51
+ end
@@ -0,0 +1,15 @@
1
+ module Mintaka
2
+ module RouteDrawers
3
+ # Matches routes in the Mintaka.content_path directory. By default this looks
4
+ # for /pages/id. e.g. http://www.example.com/pages/about_us
5
+ class Default
6
+ def self.match_attributes
7
+ {
8
+ "/#{Mintaka.content_path}*id" => 'mintaka/pages#show',
9
+ :as => :page,
10
+ :format => false
11
+ }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ module Mintaka
2
+ module RouteDrawers
3
+ # Matches routes from root of the domain e.g. http://www.example.com/about_us
4
+ # Uses Mintaka::Constraints::RootRoute to validate view exists.
5
+ class Root
6
+ def self.match_attributes
7
+ {
8
+ "/*id" => 'mintaka/pages#show',
9
+ :as => :page,
10
+ :format => false,
11
+ :constraints => Mintaka::Constraints::RootRoute
12
+ }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Mintaka
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :mintaka do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,29 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "mintaka/version"
5
+
6
+ $:.push File.expand_path("../lib", __FILE__)
7
+ require "mintaka/version"
8
+ # Describe your gem and declare its dependencies:
9
+ Gem::Specification.new do |s|
10
+ s.name = "mintaka"
11
+ s.version = Mintaka::VERSION
12
+ s.authors = ["jcottobboni"]
13
+ s.email = ["jcottobboni@gmail.com"]
14
+ s.homepage = "http://www.google.com"
15
+ s.summary = "Engine for statics pages"
16
+ s.description = "provides statics page inserts and control"
17
+ s.license = "MIT"
18
+
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+
25
+ s.add_dependency "rails", "~> 5.0.2"
26
+
27
+ s.add_development_dependency("activesupport", ">= 3.1.0")
28
+ s.add_development_dependency("pry")
29
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class NavigationTest < ActionDispatch::IntegrationTest
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
8
+
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class Mintaka::Test < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, Mintaka
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
5
+ ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
6
+ require "rails/test_help"
7
+
8
+ # Filter out Minitest backtrace while allowing backtrace from other libraries
9
+ # to be shown.
10
+ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
11
+
12
+
13
+ # Load fixtures from the engine
14
+ if ActiveSupport::TestCase.respond_to?(:fixture_path=)
15
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
16
+ ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
17
+ ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files"
18
+ ActiveSupport::TestCase.fixtures :all
19
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mintaka
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - jcottobboni
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 5.0.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.1.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 3.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: provides statics page inserts and control
56
+ email:
57
+ - jcottobboni@gmail.com
58
+ executables:
59
+ - rails
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - MIT-LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - app/assets/config/mintaka_manifest.js
69
+ - app/assets/images/mintaka/.keep
70
+ - app/assets/javascripts/mintaka/.keep
71
+ - app/assets/stylesheets/mintaka/.keep
72
+ - app/controllers/.keep
73
+ - app/controllers/concerns/mintaka/static_page.rb
74
+ - app/controllers/mintaka/pages_controller.rb
75
+ - app/helpers/.keep
76
+ - app/mailers/.keep
77
+ - app/models/.keep
78
+ - app/views/.keep
79
+ - bin/rails
80
+ - config/routes.rb
81
+ - lib/mintaka.rb
82
+ - lib/mintaka/configuration.rb
83
+ - lib/mintaka/constraints/root_route.rb
84
+ - lib/mintaka/engine.rb
85
+ - lib/mintaka/page.rb
86
+ - lib/mintaka/page_collector.rb
87
+ - lib/mintaka/page_finder.rb
88
+ - lib/mintaka/route_drawers/default.rb
89
+ - lib/mintaka/route_drawers/root.rb
90
+ - lib/mintaka/version.rb
91
+ - lib/tasks/mintaka_tasks.rake
92
+ - mintaka.gemspec
93
+ - test/integration/navigation_test.rb
94
+ - test/mintaka_test.rb
95
+ - test/test_helper.rb
96
+ homepage: http://www.google.com
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.0.14.1
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Engine for statics pages
120
+ test_files: []