jinda 0.1.0 → 0.1.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -11
  3. data/Rakefile +3 -1
  4. data/bin/console +1 -1
  5. data/lib/generators/jinda/config_generator.rb +23 -9
  6. data/lib/generators/jinda/install_generator.rb +31 -22
  7. data/lib/generators/jinda/minitest_generator.rb +30 -0
  8. data/lib/generators/jinda/rspec_generator.rb +30 -0
  9. data/lib/generators/jinda/templates/.env +2 -0
  10. data/lib/generators/jinda/templates/app/assets/images/facebook-continue-button.png +0 -0
  11. data/lib/generators/jinda/templates/app/assets/images/google-continue-button.png +0 -0
  12. data/lib/generators/jinda/templates/app/assets/javascripts/jqm/jquery.mobile.datebox.js +10 -4
  13. data/lib/generators/jinda/templates/app/assets/stylesheets/application.css.scss +2 -1
  14. data/lib/generators/jinda/templates/app/assets/stylesheets/jqm/app.scss +84 -0
  15. data/lib/generators/jinda/templates/app/assets/stylesheets/jqm/social.scss +133 -0
  16. data/lib/generators/jinda/templates/app/controllers/articles_controller.rb +17 -1
  17. data/lib/generators/jinda/templates/app/controllers/{ctrs_controller.rb → ctrs_controller.rb-gem-test} +0 -0
  18. data/lib/generators/jinda/templates/app/controllers/jinda_controller.rb +11 -3
  19. data/lib/generators/jinda/templates/app/jinda/index.mm +2 -2
  20. data/lib/generators/jinda/templates/app/jinda/template/linkview.haml +21 -0
  21. data/lib/generators/jinda/templates/app/models/jinda/module.rb +1 -1
  22. data/lib/generators/jinda/templates/app/models/user.rb +4 -2
  23. data/lib/generators/jinda/templates/app/views/jinda/_menu.haml +3 -1
  24. data/lib/generators/jinda/templates/app/views/jinda/_menu_mm.haml +17 -2
  25. data/lib/generators/jinda/templates/app/views/jinda/_static.haml +0 -10
  26. data/lib/generators/jinda/templates/app/views/jinda/index.html.haml +4 -3
  27. data/lib/generators/jinda/templates/app/views/jinda/run_form.haml +1 -1
  28. data/lib/generators/jinda/templates/app/views/layouts/jqm/_full.haml +11 -11
  29. data/lib/generators/jinda/templates/spec/controllers/articles_controller_spec.rb +155 -0
  30. data/lib/generators/jinda/templates/spec/helpers/rails_helper.rb +46 -0
  31. data/lib/generators/jinda/templates/spec/helpers/spec_helper.rb +96 -0
  32. data/lib/generators/jinda/templates/spec/models/user_spec.rb +26 -0
  33. data/lib/generators/jinda/templates/spec/requests/jinda_routes_spec.rb +82 -0
  34. data/lib/generators/jinda/templates/spec/requests/password_resets_spec.rb +15 -0
  35. data/lib/generators/jinda/templates/test/application_system_test_case.rb +5 -0
  36. data/lib/generators/jinda/templates/test/integration/jinda_routes_test.rb +42 -0
  37. data/lib/generators/jinda/templates/test/test_helper.rb +6 -0
  38. data/lib/jinda/gemhelpers.rb +50 -0
  39. data/lib/jinda/helpers.rb +335 -30
  40. data/lib/jinda/railtie.rb +2 -2
  41. data/lib/jinda/version.rb +1 -1
  42. data/lib/tasks/jinda.rake +0 -169
  43. metadata +141 -21
  44. data/lib/generators/jinda/templates/app/assets/images/facebook-button.png +0 -0
  45. data/lib/generators/jinda/templates/app/assets/images/facebook-sign-in-button.png +0 -0
  46. data/lib/generators/jinda/templates/app/assets/stylesheets/jqm/rouge.css.erb +0 -11
  47. data/lib/generators/jinda/templates/spec/controllers/admins_controller_spec.rb +0 -5
  48. data/lib/generators/jinda/templates/spec/controllers/devs_controller_spec.rb +0 -5
  49. data/lib/generators/jinda/templates/spec/controllers/users_controller_spec.rb +0 -5
  50. data/lib/generators/jinda/templates/spec/helpers/admins_helper_spec.rb +0 -15
  51. data/lib/generators/jinda/templates/spec/helpers/devs_helper_spec.rb +0 -15
  52. data/lib/generators/jinda/templates/spec/helpers/users_helper_spec.rb +0 -15
  53. data/lib/generators/jinda/templates/spec/spec_helper.rb +0 -38
  54. data/test/jinda_test.rb +0 -7
  55. data/test/test_helper.rb +0 -4
@@ -0,0 +1,46 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV['RAILS_ENV'] ||= 'test'
3
+ require File.expand_path('../../config/environment', __FILE__)
4
+ # Prevent database truncation if the environment is production
5
+ abort("The Rails environment is running in production mode!") if Rails.env.production?
6
+ require 'spec_helper'
7
+ require 'rspec/rails'
8
+ require 'capybara/rspec'
9
+ # Add additional requires below this line. Rails is not loaded until this point!
10
+
11
+ # Requires supporting ruby files with custom matchers and macros, etc, in
12
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
13
+ # run as spec files by default. This means that files in spec/support that end
14
+ # in _spec.rb will both be required and run as specs, causing the specs to be
15
+ # run twice. It is recommended that you do not name files matching this glob to
16
+ # end with _spec.rb. You can configure this pattern with the --pattern
17
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
18
+ #
19
+ # The following line is provided for convenience purposes. It has the downside
20
+ # of increasing the boot-up time by auto-requiring all files in the support
21
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
22
+ # require only the support files necessary.
23
+ #
24
+ # Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
25
+
26
+ RSpec.configure do |config|
27
+ # RSpec Rails can automatically mix in different behaviours to your tests
28
+ # based on their file location, for example enabling you to call `get` and
29
+ # `post` in specs under `spec/controllers`.
30
+ #
31
+ # You can disable this behaviour by removing the line below, and instead
32
+ # explicitly tag your specs with their type, e.g.:
33
+ #
34
+ # RSpec.describe UsersController, :type => :controller do
35
+ # # ...
36
+ # end
37
+ #
38
+ # The different available types are documented in the features, such as in
39
+ # https://relishapp.com/rspec/rspec-rails/docs
40
+ config.infer_spec_type_from_file_location!
41
+
42
+ # Filter lines from Rails gems in backtraces.
43
+ config.filter_rails_from_backtrace!
44
+ # arbitrary gems may also be filtered via:
45
+ # config.filter_gems_from_backtrace("gem name")
46
+ end
@@ -0,0 +1,96 @@
1
+ # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ RSpec.configure do |config|
17
+ # rspec-expectations config goes here. You can use an alternate
18
+ # assertion/expectation library such as wrong or the stdlib/minitest
19
+ # assertions if you prefer.
20
+ config.expect_with :rspec do |expectations|
21
+ # This option will default to `true` in RSpec 4. It makes the `description`
22
+ # and `failure_message` of custom matchers include text for helper methods
23
+ # defined using `chain`, e.g.:
24
+ # be_bigger_than(2).and_smaller_than(4).description
25
+ # # => "be bigger than 2 and smaller than 4"
26
+ # ...rather than:
27
+ # # => "be bigger than 2"
28
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
29
+ end
30
+
31
+ # rspec-mocks config goes here. You can use an alternate test double
32
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
33
+ config.mock_with :rspec do |mocks|
34
+ # Prevents you from mocking or stubbing a method that does not exist on
35
+ # a real object. This is generally recommended, and will default to
36
+ # `true` in RSpec 4.
37
+ mocks.verify_partial_doubles = true
38
+ end
39
+
40
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
41
+ # have no way to turn it off -- the option exists only for backwards
42
+ # compatibility in RSpec 3). It causes shared context metadata to be
43
+ # inherited by the metadata hash of host groups and examples, rather than
44
+ # triggering implicit auto-inclusion in groups with matching metadata.
45
+ config.shared_context_metadata_behavior = :apply_to_host_groups
46
+
47
+ # The settings below are suggested to provide a good initial experience
48
+ # with RSpec, but feel free to customize to your heart's content.
49
+ =begin
50
+ # This allows you to limit a spec run to individual examples or groups
51
+ # you care about by tagging them with `:focus` metadata. When nothing
52
+ # is tagged with `:focus`, all examples get run. RSpec also provides
53
+ # aliases for `it`, `describe`, and `context` that include `:focus`
54
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
55
+ config.filter_run_when_matching :focus
56
+
57
+ # Allows RSpec to persist some state between runs in order to support
58
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
59
+ # you configure your source control system to ignore this file.
60
+ config.example_status_persistence_file_path = "spec/examples.txt"
61
+
62
+ # Limits the available syntax to the non-monkey patched syntax that is
63
+ # recommended. For more details, see:
64
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
65
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
67
+ config.disable_monkey_patching!
68
+
69
+ # Many RSpec users commonly either run the entire suite or an individual
70
+ # file, and it's useful to allow more verbose output when running an
71
+ # individual spec file.
72
+ if config.files_to_run.one?
73
+ # Use the documentation formatter for detailed output,
74
+ # unless a formatter has already been configured
75
+ # (e.g. via a command-line flag).
76
+ config.default_formatter = "doc"
77
+ end
78
+
79
+ # Print the 10 slowest examples and example groups at the
80
+ # end of the spec run, to help surface which specs are running
81
+ # particularly slow.
82
+ config.profile_examples = 10
83
+
84
+ # Run specs in random order to surface order dependencies. If you find an
85
+ # order dependency and want to debug it, you can fix the order by providing
86
+ # the seed, which is printed after each run.
87
+ # --seed 1234
88
+ config.order = :random
89
+
90
+ # Seed global randomization in this process using the `--seed` CLI option.
91
+ # Setting this allows you to use `--seed` to deterministically reproduce
92
+ # test failures related to randomization by passing the same `--seed` value
93
+ # as the one that triggered the failure.
94
+ Kernel.srand config.seed
95
+ =end
96
+ end
@@ -0,0 +1,26 @@
1
+ require 'rails_helper'
2
+ RSpec.describe User Test, type: :model do
3
+ before(:each) do
4
+ @user = User.create!(user: "test name", email: "email@yahoo.com", code: "12345")
5
+ end
6
+
7
+ # describe "creation" do
8
+ # it "should have one item created after being created" do
9
+ # expect(User.all.count).to eq(1)
10
+ # end
11
+ # end
12
+
13
+ describe "email validation" do
14
+ it "should have one email to create user" do
15
+ @user.email = nil
16
+ expect(@user).to_not be_valid
17
+ end
18
+ end
19
+
20
+ # describe " Check User validates_presence_of :code " do
21
+ # it "should not let user be created without a code" do
22
+ # @user.code = nil
23
+ # expect(@user).to_not be_valid
24
+ # end
25
+ # end
26
+ end
@@ -0,0 +1,82 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "route test", :type => :routing do
4
+
5
+ it 'register user form route' do
6
+ expect(:get => "/identities/new").to route_to(
7
+ :controller => "identities",
8
+ :action => "new"
9
+ )
10
+ end
11
+
12
+ it 'Admin Jinda Pending' do
13
+ expect(:get => "/jinda/new").to route_to(
14
+ :controller => "jinda",
15
+ :action => "new"
16
+ )
17
+ end
18
+
19
+ it 'Admin Jinda Pending redirecting to action pending' do
20
+ expect(:get => "/jinda/pending").to route_to(
21
+ :controller => "jinda",
22
+ :action => "pending"
23
+ )
24
+ end
25
+
26
+ it 'jinda action init' do
27
+ expect(:get => "/jinda/init").to route_to(
28
+ :controller => "jinda",
29
+ :action => "init"
30
+ )
31
+ end
32
+
33
+ it 'jinda action run' do
34
+ expect(:get => "/jinda/run").to route_to(
35
+ :controller => "jinda",
36
+ :action => "run"
37
+ )
38
+ end
39
+
40
+ it 'jinda action run_form' do
41
+ expect(:get => "/jinda/run_form").to route_to(
42
+ :controller => "jinda",
43
+ :action => "run_form"
44
+ )
45
+ end
46
+
47
+ it 'jinda action end_form' do
48
+ expect(:get => "/jinda/end_form").to route_to(
49
+ :controller => "jinda",
50
+ :action => "end_form"
51
+ )
52
+ end
53
+
54
+ it 'jinda action end_form method post' do
55
+ expect(:post => "/jinda/end_form").to route_to(
56
+ :controller => "jinda",
57
+ :action => "end_form"
58
+ )
59
+ end
60
+
61
+ it 'jinda action run_do' do
62
+ expect(:get => "/jinda/run_do").to route_to(
63
+ :controller => "jinda",
64
+ :action => "run_do"
65
+ )
66
+ end
67
+
68
+ it 'jinda action logs' do
69
+ expect(:get => "/jinda/logs").to route_to(
70
+ :controller => "jinda",
71
+ :action => "logs"
72
+ )
73
+ end
74
+
75
+ it 'jinda action doc' do
76
+ expect(:get => "/jinda/doc").to route_to(
77
+ :controller => "jinda",
78
+ :action => "doc"
79
+ )
80
+ end
81
+
82
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails_helper'
2
+ RSpec.describe "PasswordResets", type: :request do
3
+ before(:each) do
4
+ @user = User.create!(user: "test name", email: "email@yahoo.com", code: "12345")
5
+ end
6
+ skip describe "GET /password_resets" do
7
+ it "Forgetten password ? Button" do
8
+ visit new_session_path
9
+ click_link "Forgotten password?"
10
+ fill_in "Email", :with => user.email
11
+ click_button "Reset Password"
12
+ expect(response).to redirect_to(root_path)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ require "test_helper"
2
+
3
+ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
4
+ driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
5
+ end
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+ class RegistrationRoutesTest < ActionController::TestCase
3
+
4
+ test 'register user form route' do
5
+ assert_routing '/identities/new', {controller: 'identities', action: 'new'}
6
+ #assert_routing({path: '/identities/new', method: 'post'},{controller: 'identities', action: 'new'})
7
+ end
8
+ test 'Admin Jinda Pending' do
9
+ assert_routing '/jinda/new', {controller: 'jinda', action: 'new'}
10
+ end
11
+ test 'Admin Jinda Pending redirecting to action pending' do
12
+ assert_routing '/jinda/pending', {controller: 'jinda', action: 'pending'}
13
+ #assert_routing {'/jinda/pending', method: 'post'},{controller: 'jinda', action: 'index'})
14
+ end
15
+ test 'jinda action init' do
16
+ assert_routing '/jinda/init', {controller: 'jinda', action:'init'}
17
+ end
18
+ test 'jinda action run' do
19
+ assert_routing '/jinda/run', {controller: 'jinda', action:'run'}
20
+ end
21
+ test 'jinda action run_form' do
22
+ assert_routing '/jinda/run_form', {controller: 'jinda', action:'run_form'}
23
+ end
24
+ test 'jinda action end_form' do
25
+ assert_routing '/jinda/end_form', {controller: 'jinda', action:'end_form'}
26
+ end
27
+ test 'post jinda action end_form' do
28
+ assert_routing({ path:'/jinda/end_form',method: :post},{controller: 'jinda', action:'end_form'})
29
+ end
30
+ test 'jinda action run_do' do
31
+ assert_routing '/jinda/run_do', {controller: 'jinda', action:'run_do'}
32
+ end
33
+ # test "redirect_to(:action=>\'run_#{@runseq.action}\', :id=>@xmain.id)" do
34
+ # assert_select 'title', "Welcome to Rails Testing Guide"
35
+ # end
36
+
37
+
38
+
39
+
40
+
41
+
42
+ end
@@ -0,0 +1,6 @@
1
+ require File.expand_path('../../config/environment', __FILE__)
2
+ require 'rails/test_help'
3
+
4
+ class ActiveSupport::TestCase
5
+ # Add more helper methods to be used by all tests here...
6
+ end
@@ -0,0 +1,50 @@
1
+ # This GemHelpers is to make helper able to be test in gem (not in rails)
2
+ module Jinda
3
+ module GemHelpers
4
+ require 'jinda/helpers'
5
+ include Jinda::Helpers
6
+ require 'pry'
7
+ # Find gem root
8
+ spec = Gem::Specification.find_by_name("jinda")
9
+ $gem_root = spec.gem_dir
10
+
11
+ def controller_exists?(modul)
12
+ File.exists? $gem_root + "/lib/generators/jinda/templates/app/controllers/#{modul}_controller.rb"
13
+ end
14
+
15
+ #
16
+ # Mock generate controller for test
17
+ # Otherwise test will call rails g controller
18
+ #
19
+ def process_controllers
20
+ process_services
21
+ modules= Jinda::Module.all
22
+ modules.each do |m|
23
+ next if controller_exists?(m.code)
24
+ puts " Rails generate controller #{m.code}"
25
+ end
26
+ end
27
+
28
+ def gen_view_file_exist?(dir)
29
+ gdir = $gem_root + "/spec/temp/" + dir
30
+ File.exists?(gdir)
31
+ end
32
+
33
+ def gen_view_mkdir(dir,t)
34
+ gdir = $gem_root + "/spec/temp/" + dir
35
+ Dir.mkdir(gdir)
36
+ t << "create directory #{gdir}"
37
+ end
38
+
39
+ def gen_view_createfile(sv,f,t)
40
+ gsv = $gem_root + "/lib/generators/jinda/templates/" + sv
41
+ gf = $gem_root + "/spec/temp/" + f
42
+ FileUtils.cp gsv,gf
43
+ # FileUtils.cp "app/jinda/template/linkview.haml",f
44
+ t << "create file #{gf}"
45
+ end
46
+
47
+
48
+ end
49
+ end
50
+
data/lib/jinda/helpers.rb CHANGED
@@ -1,4 +1,28 @@
1
1
  # -*- encoding : utf-8 -*-
2
+ # This helper handle
3
+ # 1. Read xml from mm file to run core program:
4
+ # process_services
5
+ # 2. Update Models, Services, Runseqs from index.mm (XML)
6
+ # 3. Rake Task to create app models, views and controller from index.mm(updated)
7
+ #
8
+ # What is xmain, runseq and xvar ?
9
+ #
10
+ # |---- xmain 1 -----|
11
+ # runseq1 runseq2
12
+ #
13
+ # Let make analogy or example compare with Invoicing
14
+ # Each xmain is like each invoice header
15
+ # Each invoice detail is like runseq
16
+ # So, There are only certain number of services limit in freemind index.mm
17
+ # But xmain will increase when entering each menu (services) and will increase along with activities by each user just like log file
18
+ #
19
+ #
20
+ # xvar is (become) global variable of current program including user, runseq, and services
21
+ #
22
+ ################################################################################
23
+
24
+ require 'active_support'
25
+ require 'active_support/core_ext'
2
26
  module Jinda
3
27
  module Helpers
4
28
  require "rexml/document"
@@ -7,35 +31,30 @@ module Jinda
7
31
  def b(s)
8
32
  "<b>#{s}</b>".html_safe
9
33
  end
10
- def date_thai(d= Time.now, options={})
11
- unless d
12
- ""
13
- else
14
- y = d.year+543
15
- if options[:monthfull] || options[:month_full]
16
- mh= ['มกราคม', 'กุมภาพันธ์', 'มีนาคม', 'เมษายน', 'พฤษภาคม', 'มิถุนายน', 'กรกฏาคม', 'สิงหาคม', 'กันยายน', 'ตุลาคม', 'พฤศจิกายน', 'ธันวาคม']
17
- else
18
- mh= ['ม.ค.', 'ก.พ.', 'มี.ค.', 'เม.ย.', 'พ.ค.', 'มิ.ย.', 'ก.ค.', 'ส.ค.', 'ก.ย.', 'ต.ค.', 'พ.ย.', 'ธ.ค.']
19
- end
20
- if options[:dateonly] || options[:date_only]
21
- d.day.to_s+" "+mh[d.month-1]+" "+y.to_s
22
- else
23
- d.day.to_s+" "+mh[d.month-1]+" "+y.to_s+" เวลา "+sprintf("%02d",d.hour.to_s)+":"+sprintf("%02d",d.min.to_s)
24
- end
25
- end
26
- end
27
34
  def link_to_blank(body, url_options = {}, html_options = {})
28
35
  link_to(body, url_options, html_options.merge(target: "_blank"))
29
36
  end
30
37
  def code_text(s) # old def code(s)
31
38
  "<pre style='background-color: #efffef;'><code class='ruby' lang='ruby'>#{s}</code></pre>".html_safe
32
39
  end
40
+
33
41
  def refresh_to(url='/', option={})
34
- if option[:alert]
35
- ma_log option[:alert]
36
- end
42
+ if option[:alert]
43
+ ma_log option[:alert]
44
+ end
45
+ # skip #
46
+ # Rails 5.2 not allow to use js inline call
37
47
  render inline: "<script>window.location.replace('#{url}')</script>"
48
+ #redirect_to url
49
+ #render js: "window.location.replace(\'#{url}\')"
38
50
  end
51
+
52
+ # def refresh_to
53
+ # respond_to do |format|
54
+ # format.js { render :js => "refresh();" }
55
+ # end
56
+ # end
57
+
39
58
  def read_binary(path)
40
59
  File.open path, "rb" do |f| f.read end
41
60
  end
@@ -201,6 +220,12 @@ module Jinda
201
220
  # ""
202
221
  # end
203
222
  # end
223
+
224
+ # ##########################################################################
225
+ #
226
+ # Create / Update Modules, Runseqs, Services from XML
227
+ #
228
+ # ##########################################################################
204
229
  def process_services
205
230
  # todo: persist mm_md5
206
231
  xml= @app||get_app
@@ -217,19 +242,29 @@ module Jinda
217
242
  mseq= 0
218
243
  @services= xml.elements["//node[@TEXT='services']"] || REXML::Document.new
219
244
  @services.each_element('node') do |m|
245
+ # get icon for service menu
220
246
  ss= m.attributes["TEXT"]
221
247
  code, name= ss.split(':', 2)
222
248
  next if code.blank?
223
249
  next if code.comment?
224
250
  module_code= code.to_code
251
+ menu_icon = m_icon(m)
252
+
253
+ # ##########################################################################
254
+ # First Node eg: Module Name
255
+ # ##########################################################################
225
256
  # create or update to GmaModule
226
257
  ma_module= Jinda::Module.find_or_create_by :code=>module_code
227
- ma_module.update_attributes :uid=>ma_module.id.to_s
258
+ ma_module.update_attributes :uid=>ma_module.id.to_s, :icon=>menu_icon
228
259
  protected_modules << ma_module.uid
229
260
  name = module_code if name.blank?
230
261
  ma_module.update_attributes :name=> name.strip, :seq=> mseq
231
262
  mseq += 1
232
263
  seq= 0
264
+
265
+ # ##########################################################################
266
+ # Second Nodes eg: Role, Link otherwise Services
267
+ # ##########################################################################
233
268
  m.each_element('node') do |s|
234
269
  service_name= s.attributes["TEXT"].to_s
235
270
  scode, sname= service_name.split(':', 2)
@@ -251,6 +286,10 @@ module Jinda
251
286
  seq += 1
252
287
  protected_services << ma_service.uid
253
288
  else
289
+
290
+ # ##########################################################################
291
+ # Second and Third Nodes eg: Role, Normal Services
292
+ # ##########################################################################
254
293
  # normal service
255
294
  step1 = s.elements['node']
256
295
  role= get_option_xml("role", step1) || ""
@@ -269,9 +308,14 @@ module Jinda
269
308
  Jinda::Module.not_in(:uid=>protected_modules).delete_all
270
309
  Jinda::Service.not_in(:uid=>protected_services).delete_all
271
310
  end
311
+
312
+ # ##########################################################################
313
+ # Load index.mm from Rails
314
+ # ##########################################################################
272
315
  def get_app
273
- f= MM || "#{Rails.root}/app/jinda/index.mm"
274
- dir= File.dirname(f)
316
+ # MM was defined in Rails: config/initializer/jinda.rb
317
+ f= MM || "#{Rails.root}/app/jinda/index.mm"
318
+ dir= File.dirname(f)
275
319
  t= REXML::Document.new(File.read(MM).gsub("\n","")).root
276
320
  recheck= true ; first_pass= true
277
321
  while recheck
@@ -297,7 +341,244 @@ module Jinda
297
341
  end
298
342
  return t
299
343
  end
300
- def controller_exists?(modul)
344
+
345
+ ########################################################################
346
+ # Jinda Rake Task #
347
+ ########################################################################
348
+
349
+ def gen_views
350
+ t = ["*** generate ui ***"]
351
+
352
+ # create array of files to be tested
353
+ $afile = Array.new
354
+
355
+ Jinda::Module.all.each do |m|
356
+ m.services.each do |s|
357
+ dir ="app/views/#{s.module.code}"
358
+ unless gen_view_file_exist?(dir)
359
+ gen_view_mkdir(dir,t)
360
+ end
361
+
362
+ if s.code=='link'
363
+ f= "app/views/#{s.module.code}/index.haml"
364
+ $afile << f
365
+ unless gen_view_file_exist?(f)
366
+ sv = "app/jinda/template/linkview.haml"
367
+ f= "app/views/#{s.module.code}/index.haml"
368
+ gen_view_createfile(sv,f,t)
369
+ end
370
+ next
371
+ end
372
+
373
+ dir ="app/views/#{s.module.code}/#{s.code}"
374
+ unless gen_view_file_exist?(dir)
375
+ gen_view_mkdir(dir,t)
376
+ end
377
+
378
+ xml= REXML::Document.new(s.xml)
379
+ xml.elements.each('*/node') do |activity|
380
+ icon = activity.elements['icon']
381
+ next unless icon
382
+ action= freemind2action(icon.attributes['BUILTIN'])
383
+ next unless ui_action?(action)
384
+ code_name = activity.attributes["TEXT"].to_s
385
+ next if code_name.comment?
386
+ code= name2code(code_name)
387
+ if action=="pdf"
388
+ f= "app/views/#{s.module.code}/#{s.code}/#{code}.pdf.prawn"
389
+ else
390
+ f= "app/views/#{s.module.code}/#{s.code}/#{code}.html.erb"
391
+ end
392
+ $afile << f
393
+ unless gen_view_file_exist?(f)
394
+ sv = "app/jinda/template/view.html.erb"
395
+ gen_view_createfile(sv,f,t)
396
+ end
397
+ end
398
+ end
399
+ end
400
+ puts $afile.join("\n")
401
+ puts t.join("\n")
402
+ return $afile
403
+ end
404
+
405
+ def process_controllers
406
+ process_services
407
+ modules= Jinda::Module.all
408
+ modules.each do |m|
409
+ next if controller_exists?(m.code)
410
+ system("rails generate controller #{m.code}")
411
+ end
412
+ end
413
+
414
+ def process_models
415
+
416
+ # app= get_app
417
+ # t= ["process models"]
418
+ # xml map sample from index.mm
419
+ # node @CREATED=1273819432637 @ID=ID_1098419600 @MODIFIED=1334737006485 @TEXT=Jinda
420
+ # node @CREATED=1273819462973 @ID=ID_282419531 @MODIFIED=1493705904561 @POSITION=right @TEXT=services
421
+ # node @CREATED=1273819465949 @FOLDED=true @ID=ID_855471610 @MODIFIED=1493768913078 @POSITION=right @TEXT=roles
422
+ # node @CREATED=1273819456867 @ID=ID_1677010054 @MODIFIED=1493418874718 @POSITION=left @TEXT=models
423
+ # node @CREATED=1292122118499 @FOLDED=true @ID=ID_1957754752 @MODIFIED=1493705885123 @TEXT=person
424
+ # node @CREATED=1292122236285 @FOLDED=true @ID=ID_959987887 @MODIFIED=1493768919147 @TEXT=address
425
+ # node @CREATED=1493418879485 @ID=ID_1995497233 @MODIFIED=1493718770637 @TEXT=article
426
+ # node @CREATED=1493418915637 @ID=ID_429078131 @MODIFIED=1493418930081 @TEXT=comment
427
+
428
+ models= @app.elements["//node[@TEXT='models']"] || REXML::Document.new
429
+ models.each_element('node') do |model|
430
+ # t << "= "+model.attributes["TEXT"]
431
+ model_name= model.attributes["TEXT"]
432
+ next if model_name.comment?
433
+ model_code= name2code(model_name)
434
+ model_file= "#{Rails.root}/app/models/#{model_code}.rb"
435
+
436
+ if File.exists?(model_file)
437
+ doc= File.read(model_file)
438
+ else
439
+ system("rails generate model #{model_code}")
440
+ doc= File.read(model_file)
441
+ end
442
+
443
+ doc = add_utf8(doc)
444
+ attr_hash= make_fields(model)
445
+ doc = add_jinda(doc, attr_hash)
446
+ # t << "modified: #{model_file}"
447
+ File.open(model_file, "w") do |f|
448
+ f.puts doc
449
+ end
450
+
451
+ end
452
+
453
+ # puts t.join("\n")
454
+ end
455
+
456
+ def add_jinda(doc, attr_hash)
457
+ if doc =~ /#{@btext}/
458
+ s1,s2,s3= doc.partition(/ #{@btext}.*#{@etext}\n/m)
459
+ s2= ""
460
+ else
461
+ s1,s2,s3= doc.partition("include Mongoid::Document\n")
462
+ end
463
+ doc= s1+s2+ <<-EOT
464
+ #{@btext}
465
+ include Mongoid::Timestamps
466
+ EOT
467
+
468
+ attr_hash.each do |a|
469
+ # doc+= "\n*****"+a.to_s+"\n"
470
+ if a[:edit]
471
+ doc += " #{a[:text]}\n"
472
+ else
473
+ doc += " field :#{a[:code]}, :type => #{a[:type].capitalize}\n"
474
+ end
475
+ end
476
+ doc += " #{@etext}\n"
477
+ doc + s3
478
+ end
479
+
480
+ def add_utf8(doc)
481
+ unless doc =~ /encoding\s*:\s*utf-8/
482
+ doc.insert 0, "# encoding: utf-8\n"
483
+ else
484
+ doc
485
+ end
486
+ end
487
+
488
+ # inspect all nodes that has attached file (2 cases) and replace relative path with absolute path
489
+ def make_folders_absolute(f,tt)
490
+ tt.elements.each("//node") do |nn|
491
+ if nn.attributes['LINK']
492
+ nn.attributes['LINK']= File.expand_path(File.dirname(f))+"/#{nn.attributes['LINK']}"
493
+ end
494
+ end
495
+ end
496
+
497
+ def name2code(s)
498
+ # rather not ignore # symbol cause it could be comment
499
+ code, name = s.split(':')
500
+ code.downcase.strip.gsub(' ','_').gsub(/[^#_\/a-zA-Z0-9]/,'')
501
+ end
502
+
503
+ def model_exists?(model)
504
+ File.exists? "#{Rails.root}/app/models/#{model}.rb"
505
+ end
506
+
507
+ def make_fields(n)
508
+ # s= field string used by generate model cli (old style jinda)
509
+ s= ""
510
+ # h= hash :code, :type, :edit, :text
511
+ h= []
512
+ n.each_element('node') do |nn|
513
+ text = nn.attributes['TEXT']
514
+ icon = nn.elements['icon']
515
+ edit= (icon && icon.attribute('BUILTIN').value=="edit")
516
+ next if text.comment? && !edit
517
+
518
+ # sometimes freemind puts all fields inside a blank node
519
+ unless text.empty?
520
+ k,v= text.split(/:\s*/,2)
521
+ v ||= 'string'
522
+ v= 'float' if v=~/double/i
523
+ s << " #{name2code(k.strip)}:#{v.strip} "
524
+ h << {:code=>name2code(k.strip), :type=>v.strip, :edit=>edit, :text=>text}
525
+ else
526
+ nn.each_element('node') do |nnn|
527
+ icon = nnn.elements['icon']
528
+ edit1= (icon && icon.attribute('BUILTIN').value=="edit")
529
+ text1 = nnn.attributes['TEXT']
530
+ next if text1 =~ /\#.*/
531
+ k,v= text1.split(/:\s*/,2)
532
+ v ||= 'string'
533
+ v= 'float' if v=~/double/i
534
+ s << " #{name2code(k.strip)}:#{v.strip} "
535
+ h << {:code=>name2code(k.strip), :type=>v.strip, :edit=>edit1, :text=>text1}
536
+ end
537
+ end
538
+ end
539
+ # f
540
+ h
541
+ end
542
+
543
+ # Add method to ruby class String
544
+ # ###############################
545
+ class String
546
+ def comment?
547
+ self[0]=='#'
548
+ # self[0]==35 # check if first char is #
549
+ end
550
+ def to_code
551
+ s= self.dup
552
+ s.downcase.strip.gsub(' ','_').gsub(/[^#_\/a-zA-Z0-9]/,'')
553
+ end
554
+ end
555
+
556
+ ########################################################################
557
+ # END code from jinda.rake #
558
+ ########################################################################
559
+
560
+
561
+ ########################################################################
562
+ # Methods to be overrided by gemhelp #
563
+ # for Rspec Test
564
+ ########################################################################
565
+ def gen_view_file_exist?(dir)
566
+ File.exists?(dir)
567
+ end
568
+
569
+ def gen_view_mkdir(dir,t)
570
+ Dir.mkdir(dir)
571
+ t << "create directory #{dir}"
572
+ end
573
+
574
+ def gen_view_createfile(s,f,t)
575
+ FileUtils.cp s,f
576
+ # FileUtils.cp "app/jinda/template/linkview.haml",f
577
+ t << "create file #{f}"
578
+ end
579
+ ########################################################################
580
+
581
+ def controller_exists?(modul)
301
582
  File.exists? "#{Rails.root}/app/controllers/#{modul}_controller.rb"
302
583
  end
303
584
  def dup_hash(a)
@@ -335,12 +616,23 @@ module Jinda
335
616
  return nil
336
617
  end
337
618
  end
619
+ def m_icon(node)
620
+ mcons=[]
621
+ node.each_element("icon") do |mn|
622
+ mcons << mn.attributes["BUILTIN"]
623
+ end
624
+ ticon = mcons[0].to_s
625
+ return ticon
626
+ end
627
+
628
+ # Option to unlisted in the menu_mm if icon 'button_cancel'
338
629
  def listed(node)
339
630
  icons=[]
340
631
  node.each_element("icon") do |nn|
341
632
  icons << nn.attributes["BUILTIN"]
342
633
  end
343
- return !icons.include?("closed")
634
+
635
+ return !icons.include?("button_cancel")
344
636
  end
345
637
  def ma_secured?(node)
346
638
  icons=[]
@@ -349,6 +641,14 @@ module Jinda
349
641
  end
350
642
  return icons.include?("password")
351
643
  end
644
+ def ma_menu?
645
+ icons=[]
646
+ node.each_element("icon") do |mn|
647
+ icons << mn.attributes["BUILTIN"]
648
+ end
649
+ return icons.include?("menu")
650
+ end
651
+
352
652
  def freemind2action(s)
353
653
  case s.downcase
354
654
  #when 'bookmark' # Excellent
@@ -367,8 +667,8 @@ module Jinda
367
667
  'redirect'
368
668
  when 'kaddressbook' #Phone
369
669
  'invoke' # invoke new service along the way
370
- when 'list'
371
- 'list'
670
+ when 'list' # Output
671
+ 'output'
372
672
  when 'mail'
373
673
  'mail'
374
674
  when 'xmag' # Tobe discussed
@@ -393,6 +693,11 @@ module Jinda
393
693
  end
394
694
 
395
695
  class String
696
+ #
697
+ # Put comment in freemind with #
698
+ # Sample Freemind
699
+ # #ctrs:ctrs&Menu
700
+ #
396
701
  def comment?
397
702
  self[0]=='#'
398
703
  end
@@ -416,9 +721,9 @@ module ActionView
416
721
  end
417
722
  end
418
723
  class FormBuilder
419
- # def date_select_thai(method)
420
- # self.date_select method, :use_month_names=>THAI_MONTHS, :order=>[:day, :month, :year]
421
- # end
724
+ def date_select_thai(method)
725
+ self.date_select method, :use_month_names=>THAI_MONTHS, :order=>[:day, :month, :year]
726
+ end
422
727
  def date_field(method, options = {})
423
728
  default= options[:default] || self.object.send(method) || Date.today
424
729
  data_options= ({"mode"=>"calbox"}).merge(options)