diff options
author | Azul <azul@riseup.net> | 2012-09-27 22:33:04 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2012-09-27 22:33:04 +0200 |
commit | e17a2a676e0ce585ef9eaa9077887bfe1bc1173f (patch) | |
tree | e9984326f2d205d948d0cd3ab8c39aa72cf8af08 /core | |
parent | 7ea11431db5b2ef93cb3caaa8909b742a1b72f8a (diff) |
added in leap web core - merging repos
Diffstat (limited to 'core')
32 files changed, 528 insertions, 0 deletions
diff --git a/core/Development.md b/core/Development.md new file mode 100644 index 0000000..53942bb --- /dev/null +++ b/core/Development.md @@ -0,0 +1,90 @@ +Leap Web Core +============ + +This gem provides the generic helpers shared across the different engines that make up leap_web. + + +Creating a new engine +=================== + +Rails plugin new +---------------- + +Create the basic tree structure for an engine using +<code> +rails plugin new ENGINE_NAME -O --full +</code> + +'''-O''' will skip active record and not add a dev dependency on sqlite. +'''-full''' will create a directory structure with config/routes and app and a basic engine file. + +See http://guides.rubyonrails.org/engines.html for more general info about engines. + +Require Leap Web Core +--------------------- + +You need to add leap_web_core to your .gemspec: +<code> + Gem::Specification.new do |s| + ... + s.add_dependency "rails" ... + s.add_dependency "leap_web_core", "~> 0.0.1" + end +</code> + +You also need to require it before you define your engine in lib/my_engine/engine.rb: +<code> +require "leap_web_core" + +module MyEngine + class Engine < ::Rails::Engine + ... + end +end +</code> + +Require UI Gems +--------------- + +Leap Web Core provides a basic set of UI gems that should be used accross the engines. These include haml, sass, coffeescript, uglifier, bootstrap-sass, jquery and simple_form. + +Do you want to add views, javascript and the like to your engine? Then you should use the common gems. In order to do so you need to add them to your gemspec: + +<code> + require "my_engine/version" + require "leap_web_core/dependencies" + + ... + + Gem::Specification.new do |s| + ... + s.add_dependency "rails" ... + s.add_dependency "leap_web_core", "~> 0.0.1" + + LeapWebCore::Dependencies.add_ui_gems_to_spec(s) + end +</code> + +You also need to require them before you define your engine in lib/my_engine/engine.rb: +<code> +require "leap_web_core" +LeapWebCore::Dependencies.require_ui_gems + +module MyEngine + class Engine < ::Rails::Engine + ... + end +end +</code> + + +Creating Models +=============== + +You can use the normal rails generators to create models. Since you required the leap_web_core gem you will be using CouchRest::Model. So your models inherit from CouchRest::Model::Base. +http://www.couchrest.info/model/definition.html has some good first steps for setting up the model. +CouchRest Model behaved strangely when using a model without a design block. So make sure to define an initial view: http://www.couchrest.info/model/view_objects.html . + +From that point on you should be able to use the standart persistance and querying methods such as create, find, destroy and so on. + + diff --git a/core/Gemfile b/core/Gemfile new file mode 100644 index 0000000..52ed377 --- /dev/null +++ b/core/Gemfile @@ -0,0 +1,17 @@ +source "http://rubygems.org" + +# Declare your gem's dependencies in leap_web_core.gemspec. +# Bundler will treat runtime dependencies like base dependencies, and +# development dependencies will be added by default to the :development group. +gemspec + +# jquery-rails is used by the dummy application +gem "jquery-rails" + +# Declare any dependencies that are still in development here instead of in +# your gemspec. These might include edge Rails or gems from your path or +# Git. Remember to move these dependencies to your gemspec before releasing +# your gem to rubygems.org. + +# To use debugger +# gem 'ruby-debug' diff --git a/core/Rakefile b/core/Rakefile new file mode 100644 index 0000000..477e34d --- /dev/null +++ b/core/Rakefile @@ -0,0 +1,38 @@ +#!/usr/bin/env rake +begin + require 'bundler/setup' +rescue LoadError + puts 'You must `gem install bundler` and `bundle install` to run rake tasks' +end +begin + require 'rdoc/task' +rescue LoadError + require 'rdoc/rdoc' + require 'rake/rdoctask' + RDoc::Task = Rake::RDocTask +end + +RDoc::Task.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'LeapWebCore' + rdoc.options << '--line-numbers' + rdoc.rdoc_files.include('README.rdoc') + rdoc.rdoc_files.include('lib/**/*.rb') +end + + + + +Bundler::GemHelper.install_tasks + +require 'rake/testtask' + +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.libs << 'test' + t.pattern = 'test/**/*_test.rb' + t.verbose = false +end + + +task :default => :test diff --git a/core/Readme.md b/core/Readme.md new file mode 100644 index 0000000..f76999e --- /dev/null +++ b/core/Readme.md @@ -0,0 +1,4 @@ +Leap Web Core +=== + +[Leap](http://www.leap.se) is the Leap Encryption Access Project and this is the rails app for its web interface. diff --git a/core/app/assets/images/leap_web_core/.gitkeep b/core/app/assets/images/leap_web_core/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/core/app/assets/images/leap_web_core/.gitkeep diff --git a/core/app/assets/javascripts/leap_web_core/.gitkeep b/core/app/assets/javascripts/leap_web_core/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/core/app/assets/javascripts/leap_web_core/.gitkeep diff --git a/core/app/assets/stylesheets/leap_web_core/.gitkeep b/core/app/assets/stylesheets/leap_web_core/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/core/app/assets/stylesheets/leap_web_core/.gitkeep diff --git a/core/app/controllers/.gitkeep b/core/app/controllers/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/core/app/controllers/.gitkeep diff --git a/core/app/controllers/home_controller.rb b/core/app/controllers/home_controller.rb new file mode 100644 index 0000000..7db5397 --- /dev/null +++ b/core/app/controllers/home_controller.rb @@ -0,0 +1,5 @@ + +class HomeController < ApplicationController + def index + end +end diff --git a/core/app/helpers/.gitkeep b/core/app/helpers/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/core/app/helpers/.gitkeep diff --git a/core/app/mailers/.gitkeep b/core/app/mailers/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/core/app/mailers/.gitkeep diff --git a/core/app/models/.gitkeep b/core/app/models/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/core/app/models/.gitkeep diff --git a/core/app/views/.gitkeep b/core/app/views/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/core/app/views/.gitkeep diff --git a/core/app/views/home/index.html.haml b/core/app/views/home/index.html.haml new file mode 100644 index 0000000..82f5152 --- /dev/null +++ b/core/app/views/home/index.html.haml @@ -0,0 +1 @@ +%h3 Home diff --git a/core/config/initializers/backtrace_silencers.rb b/core/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..59385cd --- /dev/null +++ b/core/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/core/config/initializers/inflections.rb b/core/config/initializers/inflections.rb new file mode 100644 index 0000000..5d8d9be --- /dev/null +++ b/core/config/initializers/inflections.rb @@ -0,0 +1,15 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format +# (all these examples are active by default): +# ActiveSupport::Inflector.inflections do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end +# +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/core/config/initializers/mime_types.rb b/core/config/initializers/mime_types.rb new file mode 100644 index 0000000..72aca7e --- /dev/null +++ b/core/config/initializers/mime_types.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf +# Mime::Type.register_alias "text/html", :iphone diff --git a/core/config/initializers/simple_form.rb b/core/config/initializers/simple_form.rb new file mode 100644 index 0000000..b346dfa --- /dev/null +++ b/core/config/initializers/simple_form.rb @@ -0,0 +1,181 @@ +# Use this setup block to configure all options available in SimpleForm. + +if defined? SimpleForm + SimpleForm.setup do |config| + # Wrappers are used by the form builder to generate a + # complete input. You can remove any component from the + # wrapper, change the order or even add your own to the + # stack. The options given below are used to wrap the + # whole input. + config.wrappers :default, :class => :input, + :hint_class => :field_with_hint, :error_class => :field_with_errors do |b| + ## Extensions enabled by default + # Any of these extensions can be disabled for a + # given input by passing: `f.input EXTENSION_NAME => false`. + # You can make any of these extensions optional by + # renaming `b.use` to `b.optional`. + + # Determines whether to use HTML5 (:email, :url, ...) + # and required attributes + b.use :html5 + + # Calculates placeholders automatically from I18n + # You can also pass a string as f.input :placeholder => "Placeholder" + b.use :placeholder + + ## Optional extensions + # They are disabled unless you pass `f.input EXTENSION_NAME => :lookup` + # to the input. If so, they will retrieve the values from the model + # if any exists. If you want to enable the lookup for any of those + # extensions by default, you can change `b.optional` to `b.use`. + + # Calculates maxlength from length validations for string inputs + b.optional :maxlength + + # Calculates pattern from format validations for string inputs + b.optional :pattern + + # Calculates min and max from length validations for numeric inputs + b.optional :min_max + + # Calculates readonly automatically from readonly attributes + b.optional :readonly + + ## Inputs + b.use :label_input + b.use :hint, :wrap_with => { :tag => :span, :class => :hint } + b.use :error, :wrap_with => { :tag => :span, :class => :error } + end + + config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b| + b.use :html5 + b.use :placeholder + b.use :label + b.wrapper :tag => 'div', :class => 'controls' do |ba| + ba.use :input + ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' } + ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' } + end + end + + config.wrappers :prepend, :tag => 'div', :class => "control-group", :error_class => 'error' do |b| + b.use :html5 + b.use :placeholder + b.use :label + b.wrapper :tag => 'div', :class => 'controls' do |input| + input.wrapper :tag => 'div', :class => 'input-prepend' do |prepend| + prepend.use :input + end + input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' } + input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' } + end + end + + config.wrappers :append, :tag => 'div', :class => "control-group", :error_class => 'error' do |b| + b.use :html5 + b.use :placeholder + b.use :label + b.wrapper :tag => 'div', :class => 'controls' do |input| + input.wrapper :tag => 'div', :class => 'input-append' do |append| + append.use :input + end + input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' } + input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' } + end + end + + # Wrappers for forms and inputs using the Twitter Bootstrap toolkit. + # Check the Bootstrap docs (http://twitter.github.com/bootstrap) + # to learn about the different styles for forms and inputs, + # buttons and other elements. + config.default_wrapper = :bootstrap + + # Define the way to render check boxes / radio buttons with labels. + # Defaults to :nested for bootstrap config. + # :inline => input + label + # :nested => label > input + config.boolean_style = :nested + + # Default class for buttons + config.button_class = 'btn' + + # Method used to tidy up errors. Specify any Rails Array method. + # :first lists the first message for each field. + # Use :to_sentence to list all errors for each field. + # config.error_method = :first + + # Default tag used for error notification helper. + config.error_notification_tag = :div + + # CSS class to add for error notification helper. + config.error_notification_class = 'alert alert-error' + + # ID to add for error notification helper. + # config.error_notification_id = nil + + # Series of attempts to detect a default label method for collection. + # config.collection_label_methods = [ :to_label, :name, :title, :to_s ] + + # Series of attempts to detect a default value method for collection. + # config.collection_value_methods = [ :id, :to_s ] + + # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none. + # config.collection_wrapper_tag = nil + + # You can define the class to use on all collection wrappers. Defaulting to none. + # config.collection_wrapper_class = nil + + # You can wrap each item in a collection of radio/check boxes with a tag, + # defaulting to :span. Please note that when using :boolean_style = :nested, + # SimpleForm will force this option to be a label. + # config.item_wrapper_tag = :span + + # You can define a class to use in all item wrappers. Defaulting to none. + # config.item_wrapper_class = nil + + # How the label text should be generated altogether with the required text. + # config.label_text = lambda { |label, required| "#{required} #{label}" } + + # You can define the class to use on all labels. Default is nil. + config.label_class = 'control-label' + + # You can define the class to use on all forms. Default is simple_form. + config.form_class = 'form-horizontal' + + # You can define which elements should obtain additional classes + # config.generate_additional_classes_for = [:wrapper, :label, :input] + + # Whether attributes are required by default (or not). Default is true. + # config.required_by_default = true + + # Tell browsers whether to use default HTML5 validations (novalidate option). + # Default is enabled. + config.browser_validations = true + + # Collection of methods to detect if a file type was given. + # config.file_methods = [ :mounted_as, :file?, :public_filename ] + + # Custom mappings for input types. This should be a hash containing a regexp + # to match as key, and the input type that will be used when the field name + # matches the regexp as value. + # config.input_mappings = { /count/ => :integer } + + # Default priority for time_zone inputs. + # config.time_zone_priority = nil + + # Default priority for country inputs. + # config.country_priority = nil + + # Default size for text inputs. + # config.default_input_size = 50 + + # When false, do not use translations for labels. + # config.translate_labels = true + + # Automatically discover new inputs in Rails' autoload path. + # config.inputs_discovery = true + + # Cache SimpleForm inputs discovery + # config.cache_discovery = !Rails.env.development? + end +end diff --git a/core/config/initializers/validations.rb b/core/config/initializers/validations.rb new file mode 100644 index 0000000..e8acfbe --- /dev/null +++ b/core/config/initializers/validations.rb @@ -0,0 +1,4 @@ +# In case we use a different ORM at some point +VALIDATION_FAILED = CouchRest::Model::Errors::Validations +RECORD_NOT_FOUND = CouchRest::Model::DocumentNotFound +RESOURCE_NOT_FOUND = RestClient::ResourceNotFound diff --git a/core/config/initializers/wrap_parameters.rb b/core/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000..5fe232e --- /dev/null +++ b/core/config/initializers/wrap_parameters.rb @@ -0,0 +1,10 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters :format => [:json] +end + diff --git a/core/config/routes.rb b/core/config/routes.rb new file mode 100644 index 0000000..63f644c --- /dev/null +++ b/core/config/routes.rb @@ -0,0 +1,3 @@ +Rails.application.routes.draw do + root :to => "home#index" +end diff --git a/core/leap_web_core.gemspec b/core/leap_web_core.gemspec new file mode 100644 index 0000000..709b451 --- /dev/null +++ b/core/leap_web_core.gemspec @@ -0,0 +1,23 @@ +$:.push File.expand_path("../lib", __FILE__) + +# Maintain your gem's version: +require "leap_web_core/version" + +# Describe your gem and declare its dependencies: +Gem::Specification.new do |s| + s.name = "leap_web_core" + s.version = LeapWebCore::VERSION + s.authors = ["Azul"] + s.email = ["azul@leap.se"] + s.homepage = "http://www.leap.se" + s.summary = "Web interface to the leap platform" + s.description = "This web interface provides various administrative tools for the leap platform through plugins. Currently it manages user accounts and certificates." + + s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "Readme.md"] + s.test_files = Dir["test/**/*"] + + s.add_dependency "rails", "~> 3.2.8" + s.add_dependency "couchrest", "~> 1.1.3" + s.add_dependency "couchrest_model", "~> 2.0.0.beta2" + +end diff --git a/core/lib/extensions/testing.rb b/core/lib/extensions/testing.rb new file mode 100644 index 0000000..14a5698 --- /dev/null +++ b/core/lib/extensions/testing.rb @@ -0,0 +1,24 @@ +module LeapWebCore + module AssertResponses + + def assert_attachement_filename(name) + assert_equal %Q(attachment; filename="#{name}"), + @response.headers["Content-Disposition"] + end + + + def assert_json_response(object) + object.stringify_keys! if object.respond_to? :stringify_keys! + assert_equal object, JSON.parse(@response.body) + end + + end +end + +class ::ActionController::TestCase + include LeapWebCore::AssertResponses +end + +class ::ActionDispatch::IntegrationTest + include LeapWebCore::AssertResponses +end diff --git a/core/lib/leap_web_core.rb b/core/lib/leap_web_core.rb new file mode 100644 index 0000000..16004f8 --- /dev/null +++ b/core/lib/leap_web_core.rb @@ -0,0 +1,6 @@ +require "extensions/testing" +require "leap_web_core/dependencies" +require "leap_web_core/engine" + +module LeapWebCore +end diff --git a/core/lib/leap_web_core/dependencies.rb b/core/lib/leap_web_core/dependencies.rb new file mode 100644 index 0000000..7f6ca87 --- /dev/null +++ b/core/lib/leap_web_core/dependencies.rb @@ -0,0 +1,40 @@ +module LeapWebCore + class Dependencies + UI_DEV = { + "haml-rails" => "~> 0.3.4", + "sass-rails" => "~> 3.2.5", + "coffee-rails" => "~> 3.2.2", + "uglifier" => "~> 1.2.7" + } + + UI = { + "haml" => "~> 3.1.7", + "bootstrap-sass" => "~> 2.0.4", + "jquery-rails" => nil, + "simple_form" => nil + } + + def self.require_ui_gems + UI.keys.each {|dep| require dep} + if Rails.env == "development" + # This will be run in the app including plugins that run it. + # However not all development_dependencies might be present. + # So we better only require those that are. + available = Bundler.definition.specs.map(&:name) + gems_to_require = available & UI_DEV.keys + gems_to_require.each {|dep| require dep} + end + end + + def self.add_ui_gems_to_spec(spec) + UI.each do |dep, version| + spec.add_dependency dep, version + end + + UI_DEV.each do |dep, version| + spec.add_development_dependency dep, version + end + end + + end +end diff --git a/core/lib/leap_web_core/engine.rb b/core/lib/leap_web_core/engine.rb new file mode 100644 index 0000000..940b5e2 --- /dev/null +++ b/core/lib/leap_web_core/engine.rb @@ -0,0 +1,9 @@ +# thou shall require all your dependencies in an engine. +require "couchrest" +require "couchrest_model" + +module LeapWebCore + class Engine < ::Rails::Engine + + end +end diff --git a/core/lib/leap_web_core/version.rb b/core/lib/leap_web_core/version.rb new file mode 100644 index 0000000..6a34982 --- /dev/null +++ b/core/lib/leap_web_core/version.rb @@ -0,0 +1,3 @@ +module LeapWebCore + VERSION = "0.0.1" +end diff --git a/core/lib/tasks/leap_web_core_tasks.rake b/core/lib/tasks/leap_web_core_tasks.rake new file mode 100644 index 0000000..ae5b79b --- /dev/null +++ b/core/lib/tasks/leap_web_core_tasks.rake @@ -0,0 +1,4 @@ +# desc "Explaining what the task does" +# task :leap_web_core do +# # Task goes here +# end diff --git a/core/script/rails b/core/script/rails new file mode 100755 index 0000000..c2ad538 --- /dev/null +++ b/core/script/rails @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby1.8 +# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. + +ENGINE_ROOT = File.expand_path('../..', __FILE__) +ENGINE_PATH = File.expand_path('../../lib/leap_web_core/engine', __FILE__) + +require 'rails/all' +require 'rails/engine/commands' diff --git a/core/test/integration/navigation_test.rb b/core/test/integration/navigation_test.rb new file mode 100644 index 0000000..eec8c0e --- /dev/null +++ b/core/test/integration/navigation_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class NavigationTest < ActionDispatch::IntegrationTest + + # test "the truth" do + # assert true + # end +end + diff --git a/core/test/leap_web_core_test.rb b/core/test/leap_web_core_test.rb new file mode 100644 index 0000000..0dd71ff --- /dev/null +++ b/core/test/leap_web_core_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class LeapWebCoreTest < ActiveSupport::TestCase + test "truth" do + assert_kind_of Module, LeapWebCore + end +end diff --git a/core/test/test_helper.rb b/core/test/test_helper.rb new file mode 100644 index 0000000..1e26a31 --- /dev/null +++ b/core/test/test_helper.rb @@ -0,0 +1,15 @@ +# Configure Rails Environment +ENV["RAILS_ENV"] = "test" + +require File.expand_path("../dummy/config/environment.rb", __FILE__) +require "rails/test_help" + +Rails.backtrace_cleaner.remove_silencers! + +# Load support files +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } + +# Load fixtures from the engine +if ActiveSupport::TestCase.method_defined?(:fixture_path=) + ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__) +end |