├── autoload
└── .keep
├── rplugin
└── python3
│ └── denite
│ ├── modules
│ ├── inflection
│ │ ├── requirements.txt
│ │ ├── setup.cfg
│ │ ├── .gitignore
│ │ ├── MANIFEST.in
│ │ ├── tox.ini
│ │ ├── .travis.yml
│ │ ├── README.rst
│ │ ├── CHANGES.rst
│ │ ├── LICENSE
│ │ ├── setup.py
│ │ ├── docs
│ │ │ ├── index.rst
│ │ │ ├── Makefile
│ │ │ └── conf.py
│ │ ├── inflection.py
│ │ └── test_inflection.py
│ ├── models
│ │ ├── model_file.py
│ │ ├── helper_file.py
│ │ ├── controller_file.py
│ │ ├── spec_file.py
│ │ ├── test_file.py
│ │ ├── view_file.py
│ │ ├── file_base.py
│ │ └── dwim_file.py
│ └── finders
│ │ ├── finder_utils.py
│ │ ├── spec_finder.py
│ │ ├── test_finder.py
│ │ ├── model_finder.py
│ │ ├── helper_finder.py
│ │ ├── controller_finder.py
│ │ ├── view_finder.py
│ │ └── dwim_finder.py
│ └── source
│ └── rails.py
├── LICENSE
├── README.md
└── .gitignore
/autoload/.keep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/inflection/requirements.txt:
--------------------------------------------------------------------------------
1 | flake8
2 | isort
3 | pytest
4 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/inflection/setup.cfg:
--------------------------------------------------------------------------------
1 | [flake8]
2 | exclude=docs/*
3 |
4 | [isort]
5 | skip=.tox,docs
6 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/inflection/.gitignore:
--------------------------------------------------------------------------------
1 | *.egg-info/
2 | *.pyc
3 | .Python
4 | .tox/
5 | __pycache__/
6 | dist/
7 | docs/_build/
8 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/inflection/MANIFEST.in:
--------------------------------------------------------------------------------
1 | include README.rst LICENSE CHANGES.rst test_inflection.py
2 | graft docs
3 | prune docs/_build
4 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/inflection/tox.ini:
--------------------------------------------------------------------------------
1 | [tox]
2 | envlist = py26,py27,pypy,py33,py34
3 |
4 | [testenv]
5 | deps = -r{toxinidir}/requirements.txt
6 | commands = py.test
7 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/inflection/.travis.yml:
--------------------------------------------------------------------------------
1 | language: python
2 | python:
3 | - 2.6
4 | - 2.7
5 | - pypy
6 | - 3.3
7 | - 3.4
8 | script:
9 | - flake8 .
10 | - isort --recursive --diff . && isort --recursive --check-only .
11 | - py.test
12 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/models/model_file.py:
--------------------------------------------------------------------------------
1 | import re
2 | import os
3 |
4 | from file_base import FileBase
5 |
6 |
7 | class ModelFile(FileBase):
8 | def remove_base_directory(self, filename, root_path):
9 | return re.sub(os.path.join(root_path, 'app/models/'), '', filename)
10 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/models/helper_file.py:
--------------------------------------------------------------------------------
1 | import re
2 | import os
3 |
4 | from file_base import FileBase
5 |
6 |
7 | class HelperFile(FileBase):
8 | def remove_base_directory(self, filename, root_path):
9 | return re.sub(os.path.join(root_path, 'app/helpers/'), '', filename)
10 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/models/controller_file.py:
--------------------------------------------------------------------------------
1 | import re
2 | import os
3 |
4 | from file_base import FileBase
5 |
6 |
7 | class ControllerFile(FileBase):
8 | def remove_base_directory(self, filename, root_path):
9 | return re.sub(os.path.join(root_path, 'app/controllers/'), '', filename)
10 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/finders/finder_utils.py:
--------------------------------------------------------------------------------
1 | import glob
2 | import os
3 | import re
4 |
5 |
6 | def glob_project(root_path, glob_pattern):
7 | return glob.glob(os.path.join(root_path, glob_pattern), recursive=True)
8 |
9 | def remove_base_directory(filename, root_path, storage):
10 | return re.sub(os.path.join(root_path, storage), '', filename)
11 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/models/spec_file.py:
--------------------------------------------------------------------------------
1 | import re
2 | import os
3 |
4 | from file_base import FileBase
5 |
6 |
7 | class SpecFile(FileBase):
8 | def remove_base_directory(self, filename, root_path):
9 | return re.sub(os.path.join(root_path, 'spec/'), '', filename)
10 |
11 | def to_word(self, root_path):
12 | return self.remove_base_directory(self.filepath, root_path)
13 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/models/test_file.py:
--------------------------------------------------------------------------------
1 | import re
2 | import os
3 |
4 | from file_base import FileBase
5 |
6 |
7 | class TestFile(FileBase):
8 | def remove_base_directory(self, filename, root_path):
9 | return re.sub(os.path.join(root_path, 'test/'), '', filename)
10 |
11 | def to_word(self, root_path):
12 | return self.remove_base_directory(self.filepath, root_path)
13 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/models/view_file.py:
--------------------------------------------------------------------------------
1 | import re
2 | import os
3 |
4 | from file_base import FileBase
5 |
6 |
7 | class ViewFile(FileBase):
8 | def remove_base_directory(self, filename, root_path):
9 | return re.sub(os.path.join(root_path, 'app/views/'), '', filename)
10 |
11 | def to_word(self, root_path):
12 | return self.remove_base_directory(self.filepath, root_path)
13 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/finders/spec_finder.py:
--------------------------------------------------------------------------------
1 | import finder_utils
2 |
3 | from spec_file import SpecFile
4 |
5 |
6 | class SpecFinder:
7 |
8 | GLOB_PATTERN = 'spec/**/*.rb'
9 |
10 | def __init__(self, context):
11 | self.context = context
12 | self.root_path = context['__root_path']
13 |
14 | def find_files(self):
15 | files = finder_utils.glob_project(self.root_path, self.GLOB_PATTERN)
16 | return [SpecFile(filename) for filename in files]
17 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/finders/test_finder.py:
--------------------------------------------------------------------------------
1 | import finder_utils
2 |
3 | from test_file import TestFile
4 |
5 |
6 | class TestFinder:
7 |
8 | GLOB_PATTERN = 'test/**/*.rb'
9 |
10 | def __init__(self, context):
11 | self.context = context
12 | self.root_path = context['__root_path']
13 |
14 | def find_files(self):
15 | files = finder_utils.glob_project(self.root_path, self.GLOB_PATTERN)
16 | return [TestFile(filename) for filename in files]
17 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/finders/model_finder.py:
--------------------------------------------------------------------------------
1 | import finder_utils
2 |
3 | from model_file import ModelFile
4 |
5 |
6 | class ModelFinder:
7 |
8 | GLOB_PATTERN = 'app/models/**/*.rb'
9 |
10 | def __init__(self, context):
11 | self.context = context
12 | self.root_path = context['__root_path']
13 |
14 | def find_files(self):
15 | files = finder_utils.glob_project(self.root_path, self.GLOB_PATTERN)
16 | return [ModelFile(filename) for filename in files]
17 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/finders/helper_finder.py:
--------------------------------------------------------------------------------
1 | import finder_utils
2 |
3 | from helper_file import HelperFile
4 |
5 |
6 | class HelperFinder:
7 |
8 | GLOB_PATTERN = 'app/helpers/**/*.rb'
9 |
10 | def __init__(self, context):
11 | self.context = context
12 | self.root_path = context['__root_path']
13 |
14 | def find_files(self):
15 | files = finder_utils.glob_project(self.root_path, self.GLOB_PATTERN)
16 | return [HelperFile(filename) for filename in files]
17 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/finders/controller_finder.py:
--------------------------------------------------------------------------------
1 | import finder_utils
2 |
3 | from controller_file import ControllerFile
4 |
5 |
6 | class ControllerFinder:
7 |
8 | GLOB_PATTERN = 'app/controllers/**/*.rb'
9 |
10 | def __init__(self, context):
11 | self.context = context
12 | self.root_path = context['__root_path']
13 |
14 | def find_files(self):
15 | files = finder_utils.glob_project(self.root_path, self.GLOB_PATTERN)
16 | return [ControllerFile(filename) for filename in files]
17 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/finders/view_finder.py:
--------------------------------------------------------------------------------
1 | import os
2 | import finder_utils
3 | from view_file import ViewFile
4 |
5 |
6 | class ViewFinder:
7 | GLOB_PATTERN = 'app/views/**/*'
8 |
9 | def __init__(self, context):
10 | self.context = context
11 | self.root_path = context['__root_path']
12 |
13 | def find_files(self):
14 | files = finder_utils.glob_project(self.root_path, self.GLOB_PATTERN)
15 | files = [filename for filename in files if os.path.isfile(filename)]
16 | return [ViewFile(filename) for filename in files]
17 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/models/file_base.py:
--------------------------------------------------------------------------------
1 | import os
2 | import inflection
3 |
4 |
5 | class FileBase:
6 | def __init__(self, filepath):
7 | self.filepath = os.path.normpath(filepath)
8 |
9 | def to_word(self, root_path):
10 | return self.to_constant(root_path)
11 |
12 | def to_constant(self, root_path):
13 | filepath = self.remove_base_directory(self.filename_without_extension(), root_path)
14 | path_components = filepath.split(os.sep)
15 | constant = '::'.join(inflection.camelize(path_component) for path_component in path_components)
16 | return '{0} ({1})'.format(constant, self.remove_base_directory(self.filepath, root_path))
17 |
18 | def filename_without_extension(self):
19 | return os.path.splitext(self.filepath)[0]
20 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/inflection/README.rst:
--------------------------------------------------------------------------------
1 | Inflection
2 | ==========
3 |
4 | |build status|_
5 |
6 | .. |build status| image:: https://secure.travis-ci.org/jpvanhal/inflection.png?branch=master
7 | :alt: Build Status
8 | .. _build status: http://travis-ci.org/jpvanhal/inflection
9 |
10 | Inflection is a string transformation library. It singularizes and pluralizes
11 | English words, and transforms strings from CamelCase to underscored string.
12 | Inflection is a port of `Ruby on Rails`_' `inflector`_ to Python.
13 |
14 | .. _Ruby on Rails: http://rubyonrails.org
15 | .. _inflector: http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html
16 |
17 | Resources
18 | ---------
19 |
20 | - `Documentation `_
21 | - `Issue Tracker `_
22 | - `Code `_
23 | - `Development Version
24 | `_
25 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/inflection/CHANGES.rst:
--------------------------------------------------------------------------------
1 | Changelog
2 | ---------
3 |
4 | Here you can see the full list of changes between each Inflection release.
5 |
6 | 0.3.1 (May 3, 2015)
7 | ^^^^^^^^^^^^^^^^^^^
8 |
9 | - Fixed trove classifiers not showing up on PyPI.
10 | - Fixed "human" pluralized as "humen" and not "humans".
11 | - Fixed "potato" pluralized as "potatos" and not "potatoes".
12 |
13 | 0.3.0 (March 1, 2015)
14 | +++++++++++++++++++++
15 |
16 | - Added `tableize()` function.
17 |
18 | 0.2.1 (September 3, 2014)
19 | +++++++++++++++++++++++++
20 |
21 | - Added Python 2, Python 3 and Python 3.4 trove classifiers.
22 |
23 | 0.2.0 (June 15, 2013)
24 | +++++++++++++++++++++
25 |
26 | - Added initial support for Python 3.
27 | - Dropped Python 2.5 support.
28 |
29 | 0.1.2 (March 13, 2012)
30 | ++++++++++++++++++++++
31 |
32 | - Added Python 2.5 support.
33 |
34 | 0.1.1 (February 24, 2012)
35 | +++++++++++++++++++++++++
36 |
37 | - Fixed some files not included in the distribution package.
38 |
39 | 0.1.0 (February 24, 2012)
40 | +++++++++++++++++++++++++
41 |
42 | - Initial public release
43 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Hirofumi Wakasugi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/inflection/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (C) 2012-2015 Janne Vanhala
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 | SOFTWARE.
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # denite-rails
2 |
3 | denite-rails is a Denite.nvim source for Rails.
4 |
5 | ```
6 | Denite rails:dwim
7 | ```
8 |
9 | to list correspoinding files to the current buffer's file in Denite buffer.
10 |
11 | denite-rails also provide the below command to list specific files.
12 |
13 |
14 | ```
15 | Denite rails:model
16 | Denite rails:controller
17 | Denite rails:view
18 | Denite rails:helper
19 | Denite rails:test
20 | Denite rails:spec
21 | ```
22 |
23 | ## Keymap examples
24 |
25 | ```vim
26 | nnoremap [rails]
27 | nmap r [rails]
28 | nnoremap [rails]r :Deniterails:
29 | nnoremap [rails]r :Deniterails:dwim
30 | nnoremap [rails]m :Deniterails:model
31 | nnoremap [rails]c :Deniterails:controller
32 | nnoremap [rails]v :Deniterails:view
33 | nnoremap [rails]h :Deniterails:helper
34 | nnoremap [rails]r :Deniterails:test
35 | nnoremap [rails]s :Deniterails:spec
36 | ```
37 |
38 | ## TODO
39 |
40 | - Support decorators/fixtures/etc.
41 | - Support Cucumber/Turnip etc.
42 | - Smarter namespace handling
43 | - Refactoring
44 | - Write tests
45 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/inflection/setup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # -*- coding: utf-8 -*-
3 |
4 | from setuptools import setup
5 |
6 | import inflection
7 |
8 | setup(
9 | name='inflection',
10 | version=inflection.__version__,
11 | description="A port of Ruby on Rails inflector to Python",
12 | long_description=(
13 | open('README.rst').read() + '\n\n' +
14 | open('CHANGES.rst').read()
15 | ),
16 | author='Janne Vanhala',
17 | author_email='janne.vanhala@gmail.com',
18 | url='http://github.com/jpvanhal/inflection',
19 | license='MIT',
20 | py_modules=['inflection'],
21 | zip_safe=False,
22 | classifiers=[
23 | 'Development Status :: 4 - Beta',
24 | 'Intended Audience :: Developers',
25 | 'Natural Language :: English',
26 | 'License :: OSI Approved :: MIT License',
27 | 'Programming Language :: Python',
28 | 'Programming Language :: Python :: 2',
29 | 'Programming Language :: Python :: 2.6',
30 | 'Programming Language :: Python :: 2.7',
31 | 'Programming Language :: Python :: 3',
32 | 'Programming Language :: Python :: 3.3',
33 | 'Programming Language :: Python :: 3.4',
34 | 'Programming Language :: Python :: Implementation :: PyPy',
35 | ],
36 | )
37 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/inflection/docs/index.rst:
--------------------------------------------------------------------------------
1 | Inflection
2 | ==========
3 |
4 | Inflection is a string transformation library. It singularizes and pluralizes
5 | English words, and transforms strings from CamelCase to underscored_string.
6 | Inflection is a port of `Ruby on Rails`_' `inflector`_ to Python.
7 |
8 | .. _Ruby on Rails: http://rubyonrails.org
9 | .. _inflector: http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html
10 |
11 |
12 | Installation
13 | ------------
14 |
15 | Use pip to install from PyPI::
16 |
17 | pip install inflection
18 |
19 |
20 | Contributing
21 | ------------
22 |
23 | To contribute to Inflector `create a fork`_ on GitHub. Clone your fork, make
24 | some changes, and submit a pull request.
25 |
26 | .. _create a fork: https://github.com/jpvanhal/inflection/fork_select
27 |
28 |
29 | API Documentation
30 | -----------------
31 |
32 | .. module:: inflection
33 |
34 | .. autofunction:: camelize
35 | .. autofunction:: dasherize
36 | .. autofunction:: humanize
37 | .. autofunction:: ordinal
38 | .. autofunction:: ordinalize
39 | .. autofunction:: parameterize
40 | .. autofunction:: pluralize
41 | .. autofunction:: singularize
42 | .. autofunction:: tableize
43 | .. autofunction:: titleize
44 | .. autofunction:: transliterate
45 | .. autofunction:: underscore
46 |
47 |
48 | .. include:: ../CHANGES.rst
49 |
50 |
51 | License
52 | -------
53 |
54 | .. include:: ../LICENSE
55 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by https://www.gitignore.io/api/python
2 |
3 | ### Python ###
4 | # Byte-compiled / optimized / DLL files
5 | __pycache__/
6 | *.py[cod]
7 | *$py.class
8 |
9 | # C extensions
10 | *.so
11 |
12 | # Distribution / packaging
13 | .Python
14 | env/
15 | build/
16 | develop-eggs/
17 | dist/
18 | downloads/
19 | eggs/
20 | .eggs/
21 | lib/
22 | lib64/
23 | parts/
24 | sdist/
25 | var/
26 | wheels/
27 | *.egg-info/
28 | .installed.cfg
29 | *.egg
30 |
31 | # PyInstaller
32 | # Usually these files are written by a python script from a template
33 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
34 | *.manifest
35 | *.spec
36 |
37 | # Installer logs
38 | pip-log.txt
39 | pip-delete-this-directory.txt
40 |
41 | # Unit test / coverage reports
42 | htmlcov/
43 | .tox/
44 | .coverage
45 | .coverage.*
46 | .cache
47 | nosetests.xml
48 | coverage.xml
49 | *,cover
50 | .hypothesis/
51 |
52 | # Translations
53 | *.mo
54 | *.pot
55 |
56 | # Django stuff:
57 | *.log
58 | local_settings.py
59 |
60 | # Flask stuff:
61 | instance/
62 | .webassets-cache
63 |
64 | # Scrapy stuff:
65 | .scrapy
66 |
67 | # Sphinx documentation
68 | docs/_build/
69 |
70 | # PyBuilder
71 | target/
72 |
73 | # Jupyter Notebook
74 | .ipynb_checkpoints
75 |
76 | # pyenv
77 | .python-version
78 |
79 | # celery beat schedule file
80 | celerybeat-schedule
81 |
82 | # dotenv
83 | .env
84 |
85 | # virtualenv
86 | .venv
87 | venv/
88 | ENV/
89 |
90 | # Spyder project settings
91 | .spyderproject
92 |
93 | # Rope project settings
94 | .ropeproject
95 |
96 | # End of https://www.gitignore.io/api/python
97 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/models/dwim_file.py:
--------------------------------------------------------------------------------
1 | import re
2 | import os
3 | import inflection
4 |
5 | from file_base import FileBase
6 |
7 |
8 | class DwimFile(FileBase):
9 | def __init__(self, filepath):
10 | self.filepath_with_type_info = filepath
11 | pattern = re.compile(r'^.+: ?')
12 | self.type_info = re.match(pattern, filepath).group(0)
13 | self.filepath = re.sub(pattern, '', filepath)
14 |
15 | def remove_base_directory(self, filename, root_path):
16 | if self.type_info == 'Model: ':
17 | dirpath = os.path.join(root_path, 'app/models/')
18 | elif self.type_info == 'Controller: ':
19 | dirpath = os.path.join(root_path, 'app/controllers/')
20 | elif self.type_info == 'Helper: ':
21 | dirpath = os.path.join(root_path, 'app/helpers/')
22 | elif self.type_info == 'View: ':
23 | dirpath = os.path.join(root_path, 'app/views/')
24 | elif self.type_info == 'Test: ':
25 | dirpath = os.path.join(root_path, 'test/')
26 | elif self.type_info == 'Spec: ':
27 | dirpath = os.path.join(root_path, 'spec/')
28 | return re.sub(dirpath, '', filename)
29 |
30 | def to_word(self, root_path):
31 | if self.type_info == 'View: ' or self.type_info == 'Test: ' or self.type_info == 'Spec: ':
32 | return self.remove_base_directory(self.filepath_with_type_info, root_path)
33 | else:
34 | return self.to_constant(root_path)
35 |
36 | def to_constant(self, root_path):
37 | filepath = self.remove_base_directory(self.filename_without_extension(), root_path)
38 | path_components = filepath.split(os.sep)
39 | constant = '::'.join(inflection.camelize(path_component) for path_component in path_components)
40 | return '{0}{1} ({2})'.format(re.search(r'^.+: ?', self.filepath_with_type_info).group(), constant, self.remove_base_directory(self.filepath, root_path))
41 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/source/rails.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | from denite import util
4 | from .base import Base
5 |
6 | import os
7 | import site
8 |
9 | # Add external modules
10 | path_to_parent_dir = os.path.abspath(os.path.dirname(__file__) + '/../')
11 | path_to_modules = os.path.join(path_to_parent_dir, 'modules')
12 | site.addsitedir(path_to_modules)
13 | site.addsitedir(os.path.join(path_to_modules, 'inflection'))
14 | site.addsitedir(os.path.join(path_to_modules, 'finders'))
15 | site.addsitedir(os.path.join(path_to_modules, 'models'))
16 |
17 | from dwim_finder import DwimFinder # noqa
18 | from model_finder import ModelFinder # noqa
19 | from controller_finder import ControllerFinder # noqa
20 | from helper_finder import HelperFinder # noqa
21 | from view_finder import ViewFinder # noqa
22 | from test_finder import TestFinder # noqa
23 | from spec_finder import SpecFinder # noqa
24 |
25 |
26 | class Source(Base):
27 |
28 | def __init__(self, vim):
29 | super().__init__(vim)
30 | self.name = 'rails'
31 | self.kind = 'file'
32 |
33 | def on_init(self, context):
34 | try:
35 | context['__target'] = context['args'][0]
36 | except IndexError:
37 | raise NameError('target must be provided')
38 |
39 | cbname = self.vim.current.buffer.name
40 | context['__cbname'] = cbname
41 | context['__root_path'] = util.path2project(self.vim, cbname, context.get('root_markers', ''))
42 |
43 | def highlight(self):
44 | # TODO syntax does not work as expected
45 | self.vim.command('syntax region deniteSource_railsConstant start=+^+ end=+^.\{-}\s+')
46 | self.vim.command('highlight link deniteSource_railsConstant Statement')
47 | self.vim.command('syntax match deniteSource_railsSeparator /::/ containedin=deniteSource_railsConstant')
48 | self.vim.command('highlight link deniteSource_railsSeparator Identifier')
49 | self.vim.command('syntax region deniteSource_railsPath start=+(+ end=+)+')
50 | self.vim.command('highlight link deniteSource_railsPath Statement')
51 | self.vim.command('syntax match deniteSource_railsController /Controller:/')
52 | self.vim.command('highlight link deniteSource_railsController Function')
53 | self.vim.command('syntax match deniteSource_railsModel /Model:/')
54 | self.vim.command('highlight link deniteSource_railsModel String')
55 | self.vim.command('syntax match deniteSource_railsHelper /Helper:/')
56 | self.vim.command('highlight link deniteSource_railsHelper Type')
57 | self.vim.command('syntax match deniteSource_railsView /View:/')
58 | self.vim.command('highlight link deniteSource_railsView Statement')
59 | self.vim.command('syntax match deniteSource_railsTest /Test:/')
60 | self.vim.command('highlight link deniteSource_railsTest Number')
61 | self.vim.command('syntax match deniteSource_railsSpec /Spec:/')
62 | self.vim.command('highlight link deniteSource_railsSpec Number')
63 |
64 | def gather_candidates(self, context):
65 | file_list = self._find_files(context)
66 | if file_list is not None:
67 | return [self._convert(context, x) for x in file_list]
68 | else:
69 | return []
70 |
71 | def _find_files(self, context):
72 | target = context['__target']
73 |
74 | if target == 'dwim':
75 | finder_class = DwimFinder
76 | elif target == 'model':
77 | finder_class = ModelFinder
78 | elif target == 'controller':
79 | finder_class = ControllerFinder
80 | elif target == 'helper':
81 | finder_class = HelperFinder
82 | elif target == 'view':
83 | finder_class = ViewFinder
84 | elif target == 'test':
85 | finder_class = TestFinder
86 | elif target == 'spec':
87 | finder_class = SpecFinder
88 | else:
89 | msg = '{0} is not valid denite-rails target'.format(target)
90 | raise NameError(msg)
91 |
92 | return finder_class(context).find_files()
93 |
94 | def _convert(self, context, file_object):
95 | result_dict = {
96 | 'word': file_object.to_word(context['__root_path']),
97 | 'action__path': file_object.filepath
98 | }
99 |
100 | return result_dict
101 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/inflection/docs/Makefile:
--------------------------------------------------------------------------------
1 | # Makefile for Sphinx documentation
2 | #
3 |
4 | # You can set these variables from the command line.
5 | SPHINXOPTS =
6 | SPHINXBUILD = sphinx-build
7 | PAPER =
8 | BUILDDIR = _build
9 |
10 | # Internal variables.
11 | PAPEROPT_a4 = -D latex_paper_size=a4
12 | PAPEROPT_letter = -D latex_paper_size=letter
13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
14 | # the i18n builder cannot share the environment and doctrees with the others
15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
16 |
17 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
18 |
19 | help:
20 | @echo "Please use \`make ' where is one of"
21 | @echo " html to make standalone HTML files"
22 | @echo " dirhtml to make HTML files named index.html in directories"
23 | @echo " singlehtml to make a single large HTML file"
24 | @echo " pickle to make pickle files"
25 | @echo " json to make JSON files"
26 | @echo " htmlhelp to make HTML files and a HTML help project"
27 | @echo " qthelp to make HTML files and a qthelp project"
28 | @echo " devhelp to make HTML files and a Devhelp project"
29 | @echo " epub to make an epub"
30 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
31 | @echo " latexpdf to make LaTeX files and run them through pdflatex"
32 | @echo " text to make text files"
33 | @echo " man to make manual pages"
34 | @echo " texinfo to make Texinfo files"
35 | @echo " info to make Texinfo files and run them through makeinfo"
36 | @echo " gettext to make PO message catalogs"
37 | @echo " changes to make an overview of all changed/added/deprecated items"
38 | @echo " linkcheck to check all external links for integrity"
39 | @echo " doctest to run all doctests embedded in the documentation (if enabled)"
40 |
41 | clean:
42 | -rm -rf $(BUILDDIR)/*
43 |
44 | html:
45 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
46 | @echo
47 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
48 |
49 | dirhtml:
50 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
51 | @echo
52 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
53 |
54 | singlehtml:
55 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
56 | @echo
57 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
58 |
59 | pickle:
60 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
61 | @echo
62 | @echo "Build finished; now you can process the pickle files."
63 |
64 | json:
65 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
66 | @echo
67 | @echo "Build finished; now you can process the JSON files."
68 |
69 | htmlhelp:
70 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
71 | @echo
72 | @echo "Build finished; now you can run HTML Help Workshop with the" \
73 | ".hhp project file in $(BUILDDIR)/htmlhelp."
74 |
75 | qthelp:
76 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
77 | @echo
78 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \
79 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
80 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/inflection.qhcp"
81 | @echo "To view the help file:"
82 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/inflection.qhc"
83 |
84 | devhelp:
85 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
86 | @echo
87 | @echo "Build finished."
88 | @echo "To view the help file:"
89 | @echo "# mkdir -p $$HOME/.local/share/devhelp/inflection"
90 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/inflection"
91 | @echo "# devhelp"
92 |
93 | epub:
94 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
95 | @echo
96 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
97 |
98 | latex:
99 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
100 | @echo
101 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
102 | @echo "Run \`make' in that directory to run these through (pdf)latex" \
103 | "(use \`make latexpdf' here to do that automatically)."
104 |
105 | latexpdf:
106 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
107 | @echo "Running LaTeX files through pdflatex..."
108 | $(MAKE) -C $(BUILDDIR)/latex all-pdf
109 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
110 |
111 | text:
112 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
113 | @echo
114 | @echo "Build finished. The text files are in $(BUILDDIR)/text."
115 |
116 | man:
117 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
118 | @echo
119 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
120 |
121 | texinfo:
122 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
123 | @echo
124 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
125 | @echo "Run \`make' in that directory to run these through makeinfo" \
126 | "(use \`make info' here to do that automatically)."
127 |
128 | info:
129 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
130 | @echo "Running Texinfo files through makeinfo..."
131 | make -C $(BUILDDIR)/texinfo info
132 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
133 |
134 | gettext:
135 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
136 | @echo
137 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
138 |
139 | changes:
140 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
141 | @echo
142 | @echo "The overview file is in $(BUILDDIR)/changes."
143 |
144 | linkcheck:
145 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
146 | @echo
147 | @echo "Link check complete; look for any errors in the above output " \
148 | "or in $(BUILDDIR)/linkcheck/output.txt."
149 |
150 | doctest:
151 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
152 | @echo "Testing of doctests in the sources finished, look at the " \
153 | "results in $(BUILDDIR)/doctest/output.txt."
154 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/inflection/docs/conf.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | #
3 | # inflection documentation build configuration file, created by
4 | # sphinx-quickstart on Wed Feb 22 22:51:13 2012.
5 | #
6 | # This file is execfile()d with the current directory set to its containing dir.
7 | #
8 | # Note that not all possible configuration values are present in this
9 | # autogenerated file.
10 | #
11 | # All configuration values have a default; values that are commented out
12 | # serve to show the default.
13 |
14 | import sys, os
15 |
16 | # If extensions (or modules to document with autodoc) are in another directory,
17 | # add these directories to sys.path here. If the directory is relative to the
18 | # documentation root, use os.path.abspath to make it absolute, like shown here.
19 | sys.path.insert(0, os.path.abspath('..'))
20 | from inflection import __version__
21 |
22 | on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
23 |
24 |
25 | # -- General configuration -----------------------------------------------------
26 |
27 | # If your documentation needs a minimal Sphinx version, state it here.
28 | #needs_sphinx = '1.0'
29 |
30 | # Add any Sphinx extension module names here, as strings. They can be extensions
31 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
32 | extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.coverage', 'sphinx.ext.viewcode']
33 |
34 | # Add any paths that contain templates here, relative to this directory.
35 | templates_path = ['_templates']
36 |
37 | # The suffix of source filenames.
38 | source_suffix = '.rst'
39 |
40 | # The encoding of source files.
41 | #source_encoding = 'utf-8-sig'
42 |
43 | # The master toctree document.
44 | master_doc = 'index'
45 |
46 | # General information about the project.
47 | project = u'inflection'
48 | copyright = u'2012-2015, Janne Vanhala'
49 |
50 | # The version info for the project you're documenting, acts as replacement for
51 | # |version| and |release|, also used in various other places throughout the
52 | # built documents.
53 | #
54 | # The short X.Y version.
55 | version = __version__
56 | # The full version, including alpha/beta/rc tags.
57 | release = version
58 |
59 | # The language for content autogenerated by Sphinx. Refer to documentation
60 | # for a list of supported languages.
61 | #language = None
62 |
63 | # There are two options for replacing |today|: either, you set today to some
64 | # non-false value, then it is used:
65 | #today = ''
66 | # Else, today_fmt is used as the format for a strftime call.
67 | #today_fmt = '%B %d, %Y'
68 |
69 | # List of patterns, relative to source directory, that match files and
70 | # directories to ignore when looking for source files.
71 | exclude_patterns = ['_build']
72 |
73 | # The reST default role (used for this markup: `text`) to use for all documents.
74 | #default_role = None
75 |
76 | # If true, '()' will be appended to :func: etc. cross-reference text.
77 | #add_function_parentheses = True
78 |
79 | # If true, the current module name will be prepended to all description
80 | # unit titles (such as .. function::).
81 | #add_module_names = True
82 |
83 | # If true, sectionauthor and moduleauthor directives will be shown in the
84 | # output. They are ignored by default.
85 | #show_authors = False
86 |
87 | # The name of the Pygments (syntax highlighting) style to use.
88 | pygments_style = 'sphinx'
89 |
90 | # A list of ignored prefixes for module index sorting.
91 | #modindex_common_prefix = []
92 |
93 |
94 | # -- Options for HTML output ---------------------------------------------------
95 |
96 | # The theme to use for HTML and HTML Help pages. See the documentation for
97 | # a list of builtin themes.
98 | html_theme = 'default' if on_rtd else 'nature'
99 |
100 | # Theme options are theme-specific and customize the look and feel of a theme
101 | # further. For a list of options available for each theme, see the
102 | # documentation.
103 | #html_theme_options = {}
104 |
105 | # Add any paths that contain custom themes here, relative to this directory.
106 | #html_theme_path = []
107 |
108 | # The name for this set of Sphinx documents. If None, it defaults to
109 | # " v documentation".
110 | #html_title = None
111 |
112 | # A shorter title for the navigation bar. Default is the same as html_title.
113 | #html_short_title = None
114 |
115 | # The name of an image file (relative to this directory) to place at the top
116 | # of the sidebar.
117 | #html_logo = None
118 |
119 | # The name of an image file (within the static path) to use as favicon of the
120 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
121 | # pixels large.
122 | #html_favicon = None
123 |
124 | # Add any paths that contain custom static files (such as style sheets) here,
125 | # relative to this directory. They are copied after the builtin static files,
126 | # so a file named "default.css" will overwrite the builtin "default.css".
127 | html_static_path = ['_static']
128 |
129 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
130 | # using the given strftime format.
131 | #html_last_updated_fmt = '%b %d, %Y'
132 |
133 | # If true, SmartyPants will be used to convert quotes and dashes to
134 | # typographically correct entities.
135 | #html_use_smartypants = True
136 |
137 | # Custom sidebar templates, maps document names to template names.
138 | #html_sidebars = {}
139 |
140 | # Additional templates that should be rendered to pages, maps page names to
141 | # template names.
142 | #html_additional_pages = {}
143 |
144 | # If false, no module index is generated.
145 | #html_domain_indices = True
146 |
147 | # If false, no index is generated.
148 | #html_use_index = True
149 |
150 | # If true, the index is split into individual pages for each letter.
151 | #html_split_index = False
152 |
153 | # If true, links to the reST sources are added to the pages.
154 | #html_show_sourcelink = True
155 |
156 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
157 | #html_show_sphinx = True
158 |
159 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
160 | #html_show_copyright = True
161 |
162 | # If true, an OpenSearch description file will be output, and all pages will
163 | # contain a tag referring to it. The value of this option must be the
164 | # base URL from which the finished HTML is served.
165 | #html_use_opensearch = ''
166 |
167 | # This is the file name suffix for HTML files (e.g. ".xhtml").
168 | #html_file_suffix = None
169 |
170 | # Output file base name for HTML help builder.
171 | htmlhelp_basename = 'inflectiondoc'
172 |
173 |
174 | # -- Options for LaTeX output --------------------------------------------------
175 |
176 | latex_elements = {
177 | # The paper size ('letterpaper' or 'a4paper').
178 | #'papersize': 'letterpaper',
179 |
180 | # The font size ('10pt', '11pt' or '12pt').
181 | #'pointsize': '10pt',
182 |
183 | # Additional stuff for the LaTeX preamble.
184 | #'preamble': '',
185 | }
186 |
187 | # Grouping the document tree into LaTeX files. List of tuples
188 | # (source start file, target name, title, author, documentclass [howto/manual]).
189 | latex_documents = [
190 | ('index', 'inflection.tex', u'inflection Documentation',
191 | u'Janne Vanhala', 'manual'),
192 | ]
193 |
194 | # The name of an image file (relative to this directory) to place at the top of
195 | # the title page.
196 | #latex_logo = None
197 |
198 | # For "manual" documents, if this is true, then toplevel headings are parts,
199 | # not chapters.
200 | #latex_use_parts = False
201 |
202 | # If true, show page references after internal links.
203 | #latex_show_pagerefs = False
204 |
205 | # If true, show URL addresses after external links.
206 | #latex_show_urls = False
207 |
208 | # Documents to append as an appendix to all manuals.
209 | #latex_appendices = []
210 |
211 | # If false, no module index is generated.
212 | #latex_domain_indices = True
213 |
214 |
215 | # -- Options for manual page output --------------------------------------------
216 |
217 | # One entry per manual page. List of tuples
218 | # (source start file, name, description, authors, manual section).
219 | man_pages = [
220 | ('index', 'inflection', u'inflection Documentation',
221 | [u'Janne Vanhala'], 1)
222 | ]
223 |
224 | # If true, show URL addresses after external links.
225 | #man_show_urls = False
226 |
227 |
228 | # -- Options for Texinfo output ------------------------------------------------
229 |
230 | # Grouping the document tree into Texinfo files. List of tuples
231 | # (source start file, target name, title, author,
232 | # dir menu entry, description, category)
233 | texinfo_documents = [
234 | ('index', 'inflection', u'inflection Documentation',
235 | u'Janne Vanhala', 'inflection', 'One line description of project.',
236 | 'Miscellaneous'),
237 | ]
238 |
239 | # Documents to append as an appendix to all manuals.
240 | #texinfo_appendices = []
241 |
242 | # If false, no module index is generated.
243 | #texinfo_domain_indices = True
244 |
245 | # How to display URL addresses: 'footnote', 'no', or 'inline'.
246 | #texinfo_show_urls = 'footnote'
247 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/finders/dwim_finder.py:
--------------------------------------------------------------------------------
1 | import os
2 | import re
3 |
4 | import inflection
5 | import finder_utils
6 |
7 | from dwim_file import DwimFile
8 |
9 |
10 | class DwimFinder:
11 |
12 | MODEL_GLOB_PATTERN = 'app/models/**/*.rb'
13 | CONTROLLER_GLOB_PATTERN = 'app/controllers/**/*.rb'
14 | HELPER_GLOB_PATTERN = 'app/helpers/**/*.rb'
15 | VIEW_GLOB_PATTERN = 'app/views/**/*'
16 | MODEL_TEST_GLOB_PATTERN = 'test/models/**/*.rb'
17 | CONTROLLER_TEST_GLOB_PATTERN = 'test/controllers/**/*.rb'
18 | HELPER_TEST_GLOB_PATTERN = 'test/helpers/**/*.rb'
19 | MODEL_SPEC_GLOB_PATTERN = 'spec/models/**/*.rb'
20 | CONTROLLER_SPEC_GLOB_PATTERN = 'spec/controllers/**/*.rb'
21 | HELPER_SPEC_GLOB_PATTERN = 'spec/helpers/**/*.rb'
22 |
23 | def __init__(self, context):
24 | self.context = context
25 | self.root_path = context['__root_path']
26 | cbname = os.path.normpath(self.context['__cbname'])
27 | self.source_path = re.sub(self.root_path, '', cbname)
28 |
29 | @property
30 | def source_name(self):
31 | basename = os.path.basename(self.source_path)
32 |
33 | if self._is_controller_file():
34 | basename = re.sub(r'_controller', '', basename)
35 | elif self._is_helper_file():
36 | basename = re.sub(r'_helper', '', basename)
37 | elif self._is_view_file():
38 | basename = os.path.dirname(self.source_path).split('/')[-1]
39 | elif self._is_model_test_file():
40 | basename = re.sub(r'_test', '', basename)
41 | elif self._is_controller_test_file():
42 | basename = re.sub(r'_controller_test', '', basename)
43 | elif self._is_model_spec_files():
44 | basename = re.sub(r'_spec', '', basename)
45 | elif self._is_controller_spec_files():
46 | basename = re.sub(r'_controller_spec', '', basename)
47 |
48 | return os.path.splitext(basename)[0]
49 |
50 | @property
51 | def pluralized_name(self):
52 | return inflection.pluralize(self.source_name)
53 |
54 | @property
55 | def singularized_name(self):
56 | return inflection.singularize(self.source_name)
57 |
58 | def find_files(self):
59 | if self._is_model_file():
60 | return self._find_dwim_files_for_model()
61 | elif self._is_controller_file():
62 | return self._find_dwim_files_for_controller()
63 | elif self._is_helper_file():
64 | return self._find_dwim_files_for_helper()
65 | elif self._is_view_file():
66 | return self._find_dwim_files_for_view()
67 | elif self._is_model_test_file():
68 | return self._find_dwim_files_for_model_test()
69 | elif self._is_controller_test_file():
70 | return self._find_dwim_files_for_controller_test()
71 | elif self._is_model_spec_files():
72 | return self._find_dwim_files_for_model_spec()
73 | elif self._is_controller_spec_files():
74 | return self._find_dwim_files_for_controller_spec()
75 |
76 | def _find_dwim_files_for_model(self):
77 | result_list = []
78 | result_list.extend(self._create_controller_list())
79 | result_list.extend(self._create_helper_list())
80 | result_list.extend(self._create_view_list())
81 | result_list.extend(self._create_model_test_list())
82 | result_list.extend(self._create_model_spec_list())
83 | return [DwimFile(x) for x in result_list]
84 |
85 | def _find_dwim_files_for_controller(self):
86 | result_list = []
87 | result_list.extend(self._create_model_list())
88 | result_list.extend(self._create_helper_list())
89 | result_list.extend(self._create_view_list())
90 | result_list.extend(self._create_controller_test_list())
91 | result_list.extend(self._create_controller_spec_list())
92 | return [DwimFile(x) for x in result_list]
93 |
94 | def _find_dwim_files_for_helper(self):
95 | result_list = []
96 | result_list.extend(self._create_controller_list())
97 | result_list.extend(self._create_model_list())
98 | result_list.extend(self._create_view_list())
99 | result_list.extend(self._create_helper_test_list())
100 | result_list.extend(self._create_helper_spec_list())
101 | return [DwimFile(x) for x in result_list]
102 |
103 | def _find_dwim_files_for_view(self):
104 | result_list = []
105 | result_list.extend(self._create_controller_list())
106 | result_list.extend(self._create_model_list())
107 | result_list.extend(self._create_helper_list())
108 | result_list.extend(self._create_helper_spec_list())
109 | return [DwimFile(filename) for filename in result_list]
110 |
111 | def _find_dwim_files_for_model_test(self):
112 | result_list = []
113 | result_list.extend(self._create_model_list())
114 | return [DwimFile(filename) for filename in result_list]
115 |
116 | def _find_dwim_files_for_controller_test(self):
117 | result_list = []
118 | result_list.extend(self._create_controller_list())
119 | return [DwimFile(filename) for filename in result_list]
120 |
121 | def _find_dwim_files_for_model_spec(self):
122 | result_list = []
123 | result_list.extend(self._create_model_list())
124 | return [DwimFile(filename) for filename in result_list]
125 |
126 | def _find_dwim_files_for_controller_spec(self):
127 | result_list = []
128 | result_list.extend(self._create_controller_list())
129 | return [DwimFile(filename) for filename in result_list]
130 |
131 | def _is_model_file(self):
132 | dirpath = os.path.join(self.root_path, '/app/models/')
133 | return True if self.source_path.startswith(dirpath) else False
134 |
135 | def _is_controller_file(self):
136 | dirpath = os.path.join(self.root_path, '/app/controllers/')
137 | return True if self.source_path.startswith(dirpath) else False
138 |
139 | def _is_helper_file(self):
140 | dirpath = os.path.join(self.root_path, '/app/helpers/')
141 | return True if self.source_path.startswith(dirpath) else False
142 |
143 | def _is_view_file(self):
144 | dirpath = os.path.join(self.root_path, '/app/views/')
145 | return True if self.source_path.startswith(dirpath) else False
146 |
147 | def _is_model_test_file(self):
148 | dirpath = os.path.join(self.root_path, '/test/models/')
149 | return True if self.source_path.startswith(dirpath) else False
150 |
151 | def _is_controller_test_file(self):
152 | dirpath = os.path.join(self.root_path, '/test/controllers/')
153 | return True if self.source_path.startswith(dirpath) else False
154 |
155 | def _is_helper_test_file(self):
156 | dirpath = os.path.join(self.root_path, '/test/helpers/')
157 | return True if self.source_path.startswith(dirpath) else False
158 |
159 | def _is_model_spec_files(self):
160 | dirpath = os.path.join(self.root_path, '/spec/models/')
161 | return True if self.source_path.startswith(dirpath) else False
162 |
163 | def _is_controller_spec_files(self):
164 | dirpath = os.path.join(self.root_path, '/spec/controllers/')
165 | return True if self.source_path.startswith(dirpath) else False
166 |
167 | def _is_helper_spec_files(self):
168 | dirpath = os.path.join(self.root_path, '/spec/helpers/')
169 | return True if self.source_path.startswith(dirpath) else False
170 |
171 | def _create_model_list(self):
172 | l = self._find_model_files()
173 | return ['Model: {0}'.format(x) for x in l]
174 |
175 | def _create_controller_list(self):
176 | l = self._find_controller_files()
177 | return ['Controller: {0}'.format(x) for x in l]
178 |
179 | def _create_helper_list(self):
180 | l = self._find_helper_files()
181 | return ['Helper: {0}'.format(x) for x in l]
182 |
183 | def _create_view_list(self):
184 | l = self._find_view_files()
185 | return ['View: {0}'.format(x) for x in l]
186 |
187 | def _create_model_test_list(self):
188 | l = self._find_model_test_files()
189 | return ['Test: {0}'.format(x) for x in l]
190 |
191 | def _create_controller_test_list(self):
192 | l = self._find_controller_test_files()
193 | return ['Test: {0}'.format(x) for x in l]
194 |
195 | def _create_helper_test_list(self):
196 | l = self._find_helper_test_files()
197 | return ['Test: {0}'.format(x) for x in l]
198 |
199 | def _create_model_spec_list(self):
200 | l = self._find_model_spec_files()
201 | return ['Spec: {0}'.format(x) for x in l]
202 |
203 | def _create_controller_spec_list(self):
204 | l = self._find_controller_spec_files()
205 | return ['Spec: {0}'.format(x) for x in l]
206 |
207 | def _create_helper_spec_list(self):
208 | l = self._find_helper_spec_files()
209 | return ['Spec: {0}'.format(x) for x in l]
210 |
211 | def _find_model_files(self):
212 | l = finder_utils.glob_project(self.root_path, self.MODEL_GLOB_PATTERN)
213 | return [x for x in l if self.singularized_name in finder_utils.remove_base_directory(x, self.root_path, 'app/models/')]
214 |
215 | def _find_controller_files(self):
216 | l = finder_utils.glob_project(self.root_path,
217 | self.CONTROLLER_GLOB_PATTERN)
218 | return [x for x in l if self.pluralized_name in finder_utils.remove_base_directory(x, self.root_path, 'app/controllers/')]
219 |
220 | def _find_helper_files(self):
221 | l = finder_utils.glob_project(self.root_path, self.HELPER_GLOB_PATTERN)
222 | return [x for x in l if self.pluralized_name in finder_utils.remove_base_directory(x, self.root_path, 'app/helpers/')]
223 |
224 | def _find_view_files(self):
225 | l = finder_utils.glob_project(self.root_path, self.VIEW_GLOB_PATTERN)
226 | return [x for x in l if os.path.isfile(x) and self.pluralized_name in finder_utils.remove_base_directory(x, self.root_path, 'app/views/')]
227 |
228 | def _find_model_test_files(self):
229 | l = finder_utils.glob_project(self.root_path, self.MODEL_TEST_GLOB_PATTERN)
230 | return [x for x in l if self.pluralized_name in finder_utils.remove_base_directory(x, self.root_path, 'test/models/') or self.singularized_name in finder_utils.remove_base_directory(x, self.root_path, 'test/models/')]
231 |
232 | def _find_controller_test_files(self):
233 | l = finder_utils.glob_project(self.root_path, self.CONTROLLER_TEST_GLOB_PATTERN)
234 | return [x for x in l if self.pluralized_name in finder_utils.remove_base_directory(x, self.root_path, 'test/controllers/') or self.singularized_name in finder_utils.remove_base_directory(x, self.root_path, 'test/controllers/')]
235 |
236 | def _find_helper_test_files(self):
237 | l = finder_utils.glob_project(self.root_path, self.HELPER_TEST_GLOB_PATTERN)
238 | return [x for x in l if self.pluralized_name in finder_utils.remove_base_directory(x, self.root_path, 'test/helpers/') or self.singularized_name in finder_utils.remove_base_directory(x, self.root_path, 'test/helpers/')]
239 |
240 | def _find_model_spec_files(self):
241 | l = finder_utils.glob_project(self.root_path, self.MODEL_SPEC_GLOB_PATTERN)
242 | return [x for x in l if self.pluralized_name in finder_utils.remove_base_directory(x, self.root_path, 'spec/models/') or self.singularized_name in finder_utils.remove_base_directory(x, self.root_path, 'spec/models/')]
243 |
244 | def _find_controller_spec_files(self):
245 | l = finder_utils.glob_project(self.root_path, self.CONTROLLER_SPEC_GLOB_PATTERN)
246 | return [x for x in l if self.pluralized_name in finder_utils.remove_base_directory(x, self.root_path, 'spec/controllers/') or self.singularized_name in finder_utils.remove_base_directory(x, self.root_path, 'spec/controllers/')]
247 |
248 | def _find_helper_spec_files(self):
249 | l = finder_utils.glob_project(self.root_path, self.HELPER_SPEC_GLOB_PATTERN)
250 | return [x for x in l if self.pluralized_name in finder_utils.remove_base_directory(x, self.root_path, 'spec/helpers/') or self.singularized_name in finder_utils.remove_base_directory(x, self.root_path, 'spec/helpers/')]
251 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/inflection/inflection.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | inflection
4 | ~~~~~~~~~~~~
5 |
6 | A port of Ruby on Rails' inflector to Python.
7 |
8 | :copyright: (c) 2012-2015 by Janne Vanhala
9 |
10 | :license: MIT, see LICENSE for more details.
11 | """
12 | import re
13 | import unicodedata
14 |
15 | __version__ = '0.3.1'
16 |
17 | PLURALS = [
18 | (r"(?i)(quiz)$", r'\1zes'),
19 | (r"(?i)^(oxen)$", r'\1'),
20 | (r"(?i)^(ox)$", r'\1en'),
21 | (r"(?i)(m|l)ice$", r'\1ice'),
22 | (r"(?i)(m|l)ouse$", r'\1ice'),
23 | (r"(?i)(matr|vert|ind)(?:ix|ex)$", r'\1ices'),
24 | (r"(?i)(x|ch|ss|sh)$", r'\1es'),
25 | (r"(?i)([^aeiouy]|qu)y$", r'\1ies'),
26 | (r"(?i)(hive)$", r'\1s'),
27 | (r"(?i)([lr])f$", r'\1ves'),
28 | (r"(?i)([^f])fe$", r'\1ves'),
29 | (r"(?i)sis$", 'ses'),
30 | (r"(?i)([ti])a$", r'\1a'),
31 | (r"(?i)([ti])um$", r'\1a'),
32 | (r"(?i)(buffal|potat|tomat)o$", r'\1oes'),
33 | (r"(?i)(bu)s$", r'\1ses'),
34 | (r"(?i)(alias|status)$", r'\1es'),
35 | (r"(?i)(octop|vir)i$", r'\1i'),
36 | (r"(?i)(octop|vir)us$", r'\1i'),
37 | (r"(?i)^(ax|test)is$", r'\1es'),
38 | (r"(?i)s$", 's'),
39 | (r"$", 's'),
40 | ]
41 |
42 | SINGULARS = [
43 | (r"(?i)(database)s$", r'\1'),
44 | (r"(?i)(quiz)zes$", r'\1'),
45 | (r"(?i)(matr)ices$", r'\1ix'),
46 | (r"(?i)(vert|ind)ices$", r'\1ex'),
47 | (r"(?i)^(ox)en", r'\1'),
48 | (r"(?i)(alias|status)(es)?$", r'\1'),
49 | (r"(?i)(octop|vir)(us|i)$", r'\1us'),
50 | (r"(?i)^(a)x[ie]s$", r'\1xis'),
51 | (r"(?i)(cris|test)(is|es)$", r'\1is'),
52 | (r"(?i)(shoe)s$", r'\1'),
53 | (r"(?i)(o)es$", r'\1'),
54 | (r"(?i)(bus)(es)?$", r'\1'),
55 | (r"(?i)(m|l)ice$", r'\1ouse'),
56 | (r"(?i)(x|ch|ss|sh)es$", r'\1'),
57 | (r"(?i)(m)ovies$", r'\1ovie'),
58 | (r"(?i)(s)eries$", r'\1eries'),
59 | (r"(?i)([^aeiouy]|qu)ies$", r'\1y'),
60 | (r"(?i)([lr])ves$", r'\1f'),
61 | (r"(?i)(tive)s$", r'\1'),
62 | (r"(?i)(hive)s$", r'\1'),
63 | (r"(?i)([^f])ves$", r'\1fe'),
64 | (r"(?i)(t)he(sis|ses)$", r"\1hesis"),
65 | (r"(?i)(s)ynop(sis|ses)$", r"\1ynopsis"),
66 | (r"(?i)(p)rogno(sis|ses)$", r"\1rognosis"),
67 | (r"(?i)(p)arenthe(sis|ses)$", r"\1arenthesis"),
68 | (r"(?i)(d)iagno(sis|ses)$", r"\1iagnosis"),
69 | (r"(?i)(b)a(sis|ses)$", r"\1asis"),
70 | (r"(?i)(a)naly(sis|ses)$", r"\1nalysis"),
71 | (r"(?i)([ti])a$", r'\1um'),
72 | (r"(?i)(n)ews$", r'\1ews'),
73 | (r"(?i)(ss)$", r'\1'),
74 | (r"(?i)s$", ''),
75 | ]
76 |
77 | UNCOUNTABLES = set([
78 | 'equipment',
79 | 'fish',
80 | 'information',
81 | 'jeans',
82 | 'money',
83 | 'rice',
84 | 'series',
85 | 'sheep',
86 | 'species',
87 | ])
88 |
89 |
90 | def _irregular(singular, plural):
91 | """
92 | A convenience function to add appropriate rules to plurals and singular
93 | for irregular words.
94 |
95 | :param singular: irregular word in singular form
96 | :param plural: irregular word in plural form
97 | """
98 | def caseinsensitive(string):
99 | return ''.join('[' + char + char.upper() + ']' for char in string)
100 |
101 | if singular[0].upper() == plural[0].upper():
102 | PLURALS.insert(0, (
103 | r"(?i)(%s)%s$" % (singular[0], singular[1:]),
104 | r'\1' + plural[1:]
105 | ))
106 | PLURALS.insert(0, (
107 | r"(?i)(%s)%s$" % (plural[0], plural[1:]),
108 | r'\1' + plural[1:]
109 | ))
110 | SINGULARS.insert(0, (
111 | r"(?i)(%s)%s$" % (plural[0], plural[1:]),
112 | r'\1' + singular[1:]
113 | ))
114 | else:
115 | PLURALS.insert(0, (
116 | r"%s%s$" % (singular[0].upper(), caseinsensitive(singular[1:])),
117 | plural[0].upper() + plural[1:]
118 | ))
119 | PLURALS.insert(0, (
120 | r"%s%s$" % (singular[0].lower(), caseinsensitive(singular[1:])),
121 | plural[0].lower() + plural[1:]
122 | ))
123 | PLURALS.insert(0, (
124 | r"%s%s$" % (plural[0].upper(), caseinsensitive(plural[1:])),
125 | plural[0].upper() + plural[1:]
126 | ))
127 | PLURALS.insert(0, (
128 | r"%s%s$" % (plural[0].lower(), caseinsensitive(plural[1:])),
129 | plural[0].lower() + plural[1:]
130 | ))
131 | SINGULARS.insert(0, (
132 | r"%s%s$" % (plural[0].upper(), caseinsensitive(plural[1:])),
133 | singular[0].upper() + singular[1:]
134 | ))
135 | SINGULARS.insert(0, (
136 | r"%s%s$" % (plural[0].lower(), caseinsensitive(plural[1:])),
137 | singular[0].lower() + singular[1:]
138 | ))
139 |
140 |
141 | def camelize(string, uppercase_first_letter=True):
142 | """
143 | Convert strings to CamelCase.
144 |
145 | Examples::
146 |
147 | >>> camelize("device_type")
148 | "DeviceType"
149 | >>> camelize("device_type", False)
150 | "deviceType"
151 |
152 | :func:`camelize` can be though as a inverse of :func:`underscore`, although
153 | there are some cases where that does not hold::
154 |
155 | >>> camelize(underscore("IOError"))
156 | "IoError"
157 |
158 | :param uppercase_first_letter: if set to `True` :func:`camelize` converts
159 | strings to UpperCamelCase. If set to `False` :func:`camelize` produces
160 | lowerCamelCase. Defaults to `True`.
161 | """
162 | if uppercase_first_letter:
163 | return re.sub(r"(?:^|_)(.)", lambda m: m.group(1).upper(), string)
164 | else:
165 | return string[0].lower() + camelize(string)[1:]
166 |
167 |
168 | def dasherize(word):
169 | """Replace underscores with dashes in the string.
170 |
171 | Example::
172 |
173 | >>> dasherize("puni_puni")
174 | "puni-puni"
175 |
176 | """
177 | return word.replace('_', '-')
178 |
179 |
180 | def humanize(word):
181 | """
182 | Capitalize the first word and turn underscores into spaces and strip a
183 | trailing ``"_id"``, if any. Like :func:`titleize`, this is meant for
184 | creating pretty output.
185 |
186 | Examples::
187 |
188 | >>> humanize("employee_salary")
189 | "Employee salary"
190 | >>> humanize("author_id")
191 | "Author"
192 |
193 | """
194 | word = re.sub(r"_id$", "", word)
195 | word = word.replace('_', ' ')
196 | word = re.sub(r"(?i)([a-z\d]*)", lambda m: m.group(1).lower(), word)
197 | word = re.sub(r"^\w", lambda m: m.group(0).upper(), word)
198 | return word
199 |
200 |
201 | def ordinal(number):
202 | """
203 | Return the suffix that should be added to a number to denote the position
204 | in an ordered sequence such as 1st, 2nd, 3rd, 4th.
205 |
206 | Examples::
207 |
208 | >>> ordinal(1)
209 | "st"
210 | >>> ordinal(2)
211 | "nd"
212 | >>> ordinal(1002)
213 | "nd"
214 | >>> ordinal(1003)
215 | "rd"
216 | >>> ordinal(-11)
217 | "th"
218 | >>> ordinal(-1021)
219 | "st"
220 |
221 | """
222 | number = abs(int(number))
223 | if number % 100 in (11, 12, 13):
224 | return "th"
225 | else:
226 | return {
227 | 1: "st",
228 | 2: "nd",
229 | 3: "rd",
230 | }.get(number % 10, "th")
231 |
232 |
233 | def ordinalize(number):
234 | """
235 | Turn a number into an ordinal string used to denote the position in an
236 | ordered sequence such as 1st, 2nd, 3rd, 4th.
237 |
238 | Examples::
239 |
240 | >>> ordinalize(1)
241 | "1st"
242 | >>> ordinalize(2)
243 | "2nd"
244 | >>> ordinalize(1002)
245 | "1002nd"
246 | >>> ordinalize(1003)
247 | "1003rd"
248 | >>> ordinalize(-11)
249 | "-11th"
250 | >>> ordinalize(-1021)
251 | "-1021st"
252 |
253 | """
254 | return "%s%s" % (number, ordinal(number))
255 |
256 |
257 | def parameterize(string, separator='-'):
258 | """
259 | Replace special characters in a string so that it may be used as part of a
260 | 'pretty' URL.
261 |
262 | Example::
263 |
264 | >>> parameterize(u"Donald E. Knuth")
265 | 'donald-e-knuth'
266 |
267 | """
268 | string = transliterate(string)
269 | # Turn unwanted chars into the separator
270 | string = re.sub(r"(?i)[^a-z0-9\-_]+", separator, string)
271 | if separator:
272 | re_sep = re.escape(separator)
273 | # No more than one of the separator in a row.
274 | string = re.sub(r'%s{2,}' % re_sep, separator, string)
275 | # Remove leading/trailing separator.
276 | string = re.sub(r"(?i)^%(sep)s|%(sep)s$" % {'sep': re_sep}, '', string)
277 |
278 | return string.lower()
279 |
280 |
281 | def pluralize(word):
282 | """
283 | Return the plural form of a word.
284 |
285 | Examples::
286 |
287 | >>> pluralize("post")
288 | "posts"
289 | >>> pluralize("octopus")
290 | "octopi"
291 | >>> pluralize("sheep")
292 | "sheep"
293 | >>> pluralize("CamelOctopus")
294 | "CamelOctopi"
295 |
296 | """
297 | if not word or word.lower() in UNCOUNTABLES:
298 | return word
299 | else:
300 | for rule, replacement in PLURALS:
301 | if re.search(rule, word):
302 | return re.sub(rule, replacement, word)
303 | return word
304 |
305 |
306 | def singularize(word):
307 | """
308 | Return the singular form of a word, the reverse of :func:`pluralize`.
309 |
310 | Examples::
311 |
312 | >>> singularize("posts")
313 | "post"
314 | >>> singularize("octopi")
315 | "octopus"
316 | >>> singularize("sheep")
317 | "sheep"
318 | >>> singularize("word")
319 | "word"
320 | >>> singularize("CamelOctopi")
321 | "CamelOctopus"
322 |
323 | """
324 | for inflection in UNCOUNTABLES:
325 | if re.search(r'(?i)\b(%s)\Z' % inflection, word):
326 | return word
327 |
328 | for rule, replacement in SINGULARS:
329 | if re.search(rule, word):
330 | return re.sub(rule, replacement, word)
331 | return word
332 |
333 |
334 | def tableize(word):
335 | """
336 | Create the name of a table like Rails does for models to table names. This
337 | method uses the :func:`pluralize` method on the last word in the string.
338 |
339 | Examples::
340 |
341 | >>> tableize('RawScaledScorer')
342 | "raw_scaled_scorers"
343 | >>> tableize('egg_and_ham')
344 | "egg_and_hams"
345 | >>> tableize('fancyCategory')
346 | "fancy_categories"
347 | """
348 | return pluralize(underscore(word))
349 |
350 |
351 | def titleize(word):
352 | """
353 | Capitalize all the words and replace some characters in the string to
354 | create a nicer looking title. :func:`titleize` is meant for creating pretty
355 | output.
356 |
357 | Examples::
358 |
359 | >>> titleize("man from the boondocks")
360 | "Man From The Boondocks"
361 | >>> titleize("x-men: the last stand")
362 | "X Men: The Last Stand"
363 | >>> titleize("TheManWithoutAPast")
364 | "The Man Without A Past"
365 | >>> titleize("raiders_of_the_lost_ark")
366 | "Raiders Of The Lost Ark"
367 |
368 | """
369 | return re.sub(
370 | r"\b('?[a-z])",
371 | lambda match: match.group(1).capitalize(),
372 | humanize(underscore(word))
373 | )
374 |
375 |
376 | def transliterate(string):
377 | """
378 | Replace non-ASCII characters with an ASCII approximation. If no
379 | approximation exists, the non-ASCII character is ignored. The string must
380 | be ``unicode``.
381 |
382 | Examples::
383 |
384 | >>> transliterate(u'älämölö')
385 | u'alamolo'
386 | >>> transliterate(u'Ærøskøbing')
387 | u'rskbing'
388 |
389 | """
390 | normalized = unicodedata.normalize('NFKD', string)
391 | return normalized.encode('ascii', 'ignore').decode('ascii')
392 |
393 |
394 | def underscore(word):
395 | """
396 | Make an underscored, lowercase form from the expression in the string.
397 |
398 | Example::
399 |
400 | >>> underscore("DeviceType")
401 | "device_type"
402 |
403 | As a rule of thumb you can think of :func:`underscore` as the inverse of
404 | :func:`camelize`, though there are cases where that does not hold::
405 |
406 | >>> camelize(underscore("IOError"))
407 | "IoError"
408 |
409 | """
410 | word = re.sub(r"([A-Z]+)([A-Z][a-z])", r'\1_\2', word)
411 | word = re.sub(r"([a-z\d])([A-Z])", r'\1_\2', word)
412 | word = word.replace("-", "_")
413 | return word.lower()
414 |
415 |
416 | _irregular('person', 'people')
417 | _irregular('man', 'men')
418 | _irregular('human', 'humans')
419 | _irregular('child', 'children')
420 | _irregular('sex', 'sexes')
421 | _irregular('move', 'moves')
422 | _irregular('cow', 'kine')
423 | _irregular('zombie', 'zombies')
424 |
--------------------------------------------------------------------------------
/rplugin/python3/denite/modules/inflection/test_inflection.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | import pytest
3 |
4 | import inflection
5 |
6 | SINGULAR_TO_PLURAL = (
7 | ("search", "searches"),
8 | ("switch", "switches"),
9 | ("fix", "fixes"),
10 | ("box", "boxes"),
11 | ("process", "processes"),
12 | ("address", "addresses"),
13 | ("case", "cases"),
14 | ("stack", "stacks"),
15 | ("wish", "wishes"),
16 | ("fish", "fish"),
17 | ("jeans", "jeans"),
18 | ("funky jeans", "funky jeans"),
19 |
20 | ("category", "categories"),
21 | ("query", "queries"),
22 | ("ability", "abilities"),
23 | ("agency", "agencies"),
24 | ("movie", "movies"),
25 |
26 | ("archive", "archives"),
27 |
28 | ("index", "indices"),
29 |
30 | ("wife", "wives"),
31 | ("safe", "saves"),
32 | ("half", "halves"),
33 |
34 | ("move", "moves"),
35 |
36 | ("salesperson", "salespeople"),
37 | ("person", "people"),
38 |
39 | ("spokesman", "spokesmen"),
40 | ("man", "men"),
41 | ("woman", "women"),
42 |
43 | ("basis", "bases"),
44 | ("diagnosis", "diagnoses"),
45 | ("diagnosis_a", "diagnosis_as"),
46 |
47 | ("datum", "data"),
48 | ("medium", "media"),
49 | ("stadium", "stadia"),
50 | ("analysis", "analyses"),
51 |
52 | ("node_child", "node_children"),
53 | ("child", "children"),
54 |
55 | ("experience", "experiences"),
56 | ("day", "days"),
57 |
58 | ("comment", "comments"),
59 | ("foobar", "foobars"),
60 | ("newsletter", "newsletters"),
61 |
62 | ("old_news", "old_news"),
63 | ("news", "news"),
64 |
65 | ("series", "series"),
66 | ("species", "species"),
67 |
68 | ("quiz", "quizzes"),
69 |
70 | ("perspective", "perspectives"),
71 |
72 | ("ox", "oxen"),
73 | ("photo", "photos"),
74 | ("buffalo", "buffaloes"),
75 | ("tomato", "tomatoes"),
76 | ("potato", "potatoes"),
77 | ("dwarf", "dwarves"),
78 | ("elf", "elves"),
79 | ("information", "information"),
80 | ("equipment", "equipment"),
81 | ("bus", "buses"),
82 | ("status", "statuses"),
83 | ("status_code", "status_codes"),
84 | ("mouse", "mice"),
85 |
86 | ("louse", "lice"),
87 | ("house", "houses"),
88 | ("octopus", "octopi"),
89 | ("virus", "viri"),
90 | ("alias", "aliases"),
91 | ("portfolio", "portfolios"),
92 |
93 | ("vertex", "vertices"),
94 | ("matrix", "matrices"),
95 | ("matrix_fu", "matrix_fus"),
96 |
97 | ("axis", "axes"),
98 | ("testis", "testes"),
99 | ("crisis", "crises"),
100 |
101 | ("rice", "rice"),
102 | ("shoe", "shoes"),
103 |
104 | ("horse", "horses"),
105 | ("prize", "prizes"),
106 | ("edge", "edges"),
107 |
108 | ("cow", "kine"),
109 | ("database", "databases"),
110 | ("human", "humans")
111 | )
112 |
113 | CAMEL_TO_UNDERSCORE = (
114 | ("Product", "product"),
115 | ("SpecialGuest", "special_guest"),
116 | ("ApplicationController", "application_controller"),
117 | ("Area51Controller", "area51_controller"),
118 | )
119 |
120 | CAMEL_TO_UNDERSCORE_WITHOUT_REVERSE = (
121 | ("HTMLTidy", "html_tidy"),
122 | ("HTMLTidyGenerator", "html_tidy_generator"),
123 | ("FreeBSD", "free_bsd"),
124 | ("HTML", "html"),
125 | )
126 |
127 | STRING_TO_PARAMETERIZED = (
128 | (u"Donald E. Knuth", "donald-e-knuth"),
129 | (
130 | u"Random text with *(bad)* characters",
131 | "random-text-with-bad-characters"
132 | ),
133 | (u"Allow_Under_Scores", "allow_under_scores"),
134 | (u"Trailing bad characters!@#", "trailing-bad-characters"),
135 | (u"!@#Leading bad characters", "leading-bad-characters"),
136 | (u"Squeeze separators", "squeeze-separators"),
137 | (u"Test with + sign", "test-with-sign"),
138 | (u"Test with malformed utf8 \251", "test-with-malformed-utf8"),
139 | )
140 |
141 | STRING_TO_PARAMETERIZE_WITH_NO_SEPARATOR = (
142 | (u"Donald E. Knuth", "donaldeknuth"),
143 | (u"With-some-dashes", "with-some-dashes"),
144 | (u"Random text with *(bad)* characters", "randomtextwithbadcharacters"),
145 | (u"Trailing bad characters!@#", "trailingbadcharacters"),
146 | (u"!@#Leading bad characters", "leadingbadcharacters"),
147 | (u"Squeeze separators", "squeezeseparators"),
148 | (u"Test with + sign", "testwithsign"),
149 | (u"Test with malformed utf8 \251", "testwithmalformedutf8"),
150 | )
151 |
152 | STRING_TO_PARAMETERIZE_WITH_UNDERSCORE = (
153 | (u"Donald E. Knuth", "donald_e_knuth"),
154 | (
155 | u"Random text with *(bad)* characters",
156 | "random_text_with_bad_characters"
157 | ),
158 | (u"With-some-dashes", "with-some-dashes"),
159 | (u"Retain_underscore", "retain_underscore"),
160 | (u"Trailing bad characters!@#", "trailing_bad_characters"),
161 | (u"!@#Leading bad characters", "leading_bad_characters"),
162 | (u"Squeeze separators", "squeeze_separators"),
163 | (u"Test with + sign", "test_with_sign"),
164 | (u"Test with malformed utf8 \251", "test_with_malformed_utf8"),
165 | )
166 |
167 | STRING_TO_PARAMETERIZED_AND_NORMALIZED = (
168 | (u"Malmö", "malmo"),
169 | (u"Garçons", "garcons"),
170 | (u"Ops\331", "opsu"),
171 | (u"Ærøskøbing", "rskbing"),
172 | (u"Aßlar", "alar"),
173 | (u"Japanese: 日本語", "japanese"),
174 | )
175 |
176 | UNDERSCORE_TO_HUMAN = (
177 | ("employee_salary", "Employee salary"),
178 | ("employee_id", "Employee"),
179 | ("underground", "Underground"),
180 | )
181 |
182 | MIXTURE_TO_TITLEIZED = (
183 | ('active_record', 'Active Record'),
184 | ('ActiveRecord', 'Active Record'),
185 | ('action web service', 'Action Web Service'),
186 | ('Action Web Service', 'Action Web Service'),
187 | ('Action web service', 'Action Web Service'),
188 | ('actionwebservice', 'Actionwebservice'),
189 | ('Actionwebservice', 'Actionwebservice'),
190 | ("david's code", "David's Code"),
191 | ("David's code", "David's Code"),
192 | ("david's Code", "David's Code"),
193 | )
194 |
195 |
196 | ORDINAL_NUMBERS = (
197 | ("-1", "-1st"),
198 | ("-2", "-2nd"),
199 | ("-3", "-3rd"),
200 | ("-4", "-4th"),
201 | ("-5", "-5th"),
202 | ("-6", "-6th"),
203 | ("-7", "-7th"),
204 | ("-8", "-8th"),
205 | ("-9", "-9th"),
206 | ("-10", "-10th"),
207 | ("-11", "-11th"),
208 | ("-12", "-12th"),
209 | ("-13", "-13th"),
210 | ("-14", "-14th"),
211 | ("-20", "-20th"),
212 | ("-21", "-21st"),
213 | ("-22", "-22nd"),
214 | ("-23", "-23rd"),
215 | ("-24", "-24th"),
216 | ("-100", "-100th"),
217 | ("-101", "-101st"),
218 | ("-102", "-102nd"),
219 | ("-103", "-103rd"),
220 | ("-104", "-104th"),
221 | ("-110", "-110th"),
222 | ("-111", "-111th"),
223 | ("-112", "-112th"),
224 | ("-113", "-113th"),
225 | ("-1000", "-1000th"),
226 | ("-1001", "-1001st"),
227 | ("0", "0th"),
228 | ("1", "1st"),
229 | ("2", "2nd"),
230 | ("3", "3rd"),
231 | ("4", "4th"),
232 | ("5", "5th"),
233 | ("6", "6th"),
234 | ("7", "7th"),
235 | ("8", "8th"),
236 | ("9", "9th"),
237 | ("10", "10th"),
238 | ("11", "11th"),
239 | ("12", "12th"),
240 | ("13", "13th"),
241 | ("14", "14th"),
242 | ("20", "20th"),
243 | ("21", "21st"),
244 | ("22", "22nd"),
245 | ("23", "23rd"),
246 | ("24", "24th"),
247 | ("100", "100th"),
248 | ("101", "101st"),
249 | ("102", "102nd"),
250 | ("103", "103rd"),
251 | ("104", "104th"),
252 | ("110", "110th"),
253 | ("111", "111th"),
254 | ("112", "112th"),
255 | ("113", "113th"),
256 | ("1000", "1000th"),
257 | ("1001", "1001st"),
258 | )
259 |
260 | UNDERSCORES_TO_DASHES = (
261 | ("street", "street"),
262 | ("street_address", "street-address"),
263 | ("person_street_address", "person-street-address"),
264 | )
265 |
266 | STRING_TO_TABLEIZE = (
267 | ("person", "people"),
268 | ("Country", "countries"),
269 | ("ChildToy", "child_toys"),
270 | ("_RecipeIngredient", "_recipe_ingredients"),
271 | )
272 |
273 |
274 | def test_pluralize_plurals():
275 | assert "plurals" == inflection.pluralize("plurals")
276 | assert "Plurals" == inflection.pluralize("Plurals")
277 |
278 |
279 | def test_pluralize_empty_string():
280 | assert "" == inflection.pluralize("")
281 |
282 |
283 | @pytest.mark.parametrize(
284 | ("word", ),
285 | [(word,) for word in inflection.UNCOUNTABLES]
286 | )
287 | def test_uncountability(word):
288 | assert word == inflection.singularize(word)
289 | assert word == inflection.pluralize(word)
290 | assert inflection.pluralize(word) == inflection.singularize(word)
291 |
292 |
293 | def test_uncountable_word_is_not_greedy():
294 | uncountable_word = "ors"
295 | countable_word = "sponsor"
296 |
297 | inflection.UNCOUNTABLES.add(uncountable_word)
298 | try:
299 | assert uncountable_word == inflection.singularize(uncountable_word)
300 | assert uncountable_word == inflection.pluralize(uncountable_word)
301 | assert(
302 | inflection.pluralize(uncountable_word) ==
303 | inflection.singularize(uncountable_word)
304 | )
305 |
306 | assert "sponsor" == inflection.singularize(countable_word)
307 | assert "sponsors" == inflection.pluralize(countable_word)
308 | assert (
309 | "sponsor" ==
310 | inflection.singularize(inflection.pluralize(countable_word))
311 | )
312 | finally:
313 | inflection.UNCOUNTABLES.remove(uncountable_word)
314 |
315 |
316 | @pytest.mark.parametrize(("singular", "plural"), SINGULAR_TO_PLURAL)
317 | def test_pluralize_singular(singular, plural):
318 | assert plural == inflection.pluralize(singular)
319 | assert plural.capitalize() == inflection.pluralize(singular.capitalize())
320 |
321 |
322 | @pytest.mark.parametrize(("singular", "plural"), SINGULAR_TO_PLURAL)
323 | def test_singularize_plural(singular, plural):
324 | assert singular == inflection.singularize(plural)
325 | assert singular.capitalize() == inflection.singularize(plural.capitalize())
326 |
327 |
328 | @pytest.mark.parametrize(("singular", "plural"), SINGULAR_TO_PLURAL)
329 | def test_pluralize_plural(singular, plural):
330 | assert plural == inflection.pluralize(plural)
331 | assert plural.capitalize() == inflection.pluralize(plural.capitalize())
332 |
333 |
334 | @pytest.mark.parametrize(("before", "titleized"), MIXTURE_TO_TITLEIZED)
335 | def test_titleize(before, titleized):
336 | assert titleized == inflection.titleize(before)
337 |
338 |
339 | @pytest.mark.parametrize(("camel", "underscore"), CAMEL_TO_UNDERSCORE)
340 | def test_camelize(camel, underscore):
341 | assert camel == inflection.camelize(underscore)
342 |
343 |
344 | def test_camelize_with_lower_downcases_the_first_letter():
345 | assert 'capital' == inflection.camelize('Capital', False)
346 |
347 |
348 | def test_camelize_with_underscores():
349 | assert "CamelCase" == inflection.camelize('Camel_Case')
350 |
351 |
352 | @pytest.mark.parametrize(
353 | ("camel", "underscore"),
354 | CAMEL_TO_UNDERSCORE + CAMEL_TO_UNDERSCORE_WITHOUT_REVERSE
355 | )
356 | def test_underscore(camel, underscore):
357 | assert underscore == inflection.underscore(camel)
358 |
359 |
360 | @pytest.mark.parametrize(
361 | ("some_string", "parameterized_string"),
362 | STRING_TO_PARAMETERIZED
363 | )
364 | def test_parameterize(some_string, parameterized_string):
365 | assert parameterized_string == inflection.parameterize(some_string)
366 |
367 |
368 | @pytest.mark.parametrize(
369 | ("some_string", "parameterized_string"),
370 | STRING_TO_PARAMETERIZED_AND_NORMALIZED
371 | )
372 | def test_parameterize_and_normalize(some_string, parameterized_string):
373 | assert parameterized_string == inflection.parameterize(some_string)
374 |
375 |
376 | @pytest.mark.parametrize(
377 | ("some_string", "parameterized_string"),
378 | STRING_TO_PARAMETERIZE_WITH_UNDERSCORE
379 | )
380 | def test_parameterize_with_custom_separator(some_string, parameterized_string):
381 | assert parameterized_string == inflection.parameterize(some_string, '_')
382 |
383 |
384 | @pytest.mark.parametrize(
385 | ("some_string", "parameterized_string"),
386 | STRING_TO_PARAMETERIZED
387 | )
388 | def test_parameterize_with_multi_character_separator(
389 | some_string,
390 | parameterized_string
391 | ):
392 | assert (
393 | parameterized_string.replace('-', '__sep__') ==
394 | inflection.parameterize(some_string, '__sep__')
395 | )
396 |
397 |
398 | @pytest.mark.parametrize(
399 | ("some_string", "parameterized_string"),
400 | STRING_TO_PARAMETERIZE_WITH_NO_SEPARATOR
401 | )
402 | def test_parameterize_with_no_separator(some_string, parameterized_string):
403 | assert parameterized_string == inflection.parameterize(some_string, '')
404 |
405 |
406 | @pytest.mark.parametrize(("underscore", "human"), UNDERSCORE_TO_HUMAN)
407 | def test_humanize(underscore, human):
408 | assert human == inflection.humanize(underscore)
409 |
410 |
411 | @pytest.mark.parametrize(("number", "ordinalized"), ORDINAL_NUMBERS)
412 | def test_ordinal(number, ordinalized):
413 | assert ordinalized == number + inflection.ordinal(number)
414 |
415 |
416 | @pytest.mark.parametrize(("number", "ordinalized"), ORDINAL_NUMBERS)
417 | def test_ordinalize(number, ordinalized):
418 | assert ordinalized == inflection.ordinalize(number)
419 |
420 |
421 | @pytest.mark.parametrize(("input", "expected"), UNDERSCORES_TO_DASHES)
422 | def test_dasherize(input, expected):
423 | assert inflection.dasherize(input) == expected
424 |
425 |
426 | @pytest.mark.parametrize(("string", "tableized"), STRING_TO_TABLEIZE)
427 | def test_tableize(string, tableized):
428 | assert inflection.tableize(string) == tableized
429 |
--------------------------------------------------------------------------------