ServiceInnovationLab/RapuTure

View on GitHub
app/views/variables/show.html.haml

Summary

Maintainability
Test Coverage
.container
  - content_for(:title) do
    = @variable.name

  - content_for(:breadcrumbs) do
    %ul.list-stripped.list-inline.breadcrumbs
      - if @variable.namespace.present?
        %li.breadcrumb-item
          = t @variable.namespace.to_sym
      %li.breadcrumb-item.active{"aria-current" => "page"}= @variable.name


  %h3
    -if @variable.description
      = @variable.description
    - else
      = @variable.name
  = render 'badges', variable: @variable,
    link_to_count: @variable.reversed_variables.size,
    link_from_count: @variable.variables.size

  %hr/

  %p
    %strong= t :value_type
    = @variable.value_type.name
    \.
    %strong=t :default_value
    = @variable.spec['defaultValue']
    %strong=t :entity
    = @variable.spec['entity']

  - cache @variable do
    - if @variable.variables.size.positive?
      %hr/
      %h3= t :references
      %p= t :references_explanation
      = render 'references', variable: @variable
    - if @variable.reversed_variables.size.positive?
      %hr/
      %h3=t :referenced_by
      %p=t :referenced_explanation
      %ul
        - @variable.reversed_variables.order(:name).each do |v|
          %li= render 'link', variable: v

    - if @variable.has_formula?
      %hr/
      .card
        .card-header
          %h3=t :formulas
          %p= t :formula_explanation, name: @variable.name
        .card-body
          - @variable.spec['formulas'].each do |d, formula|
            %h3= d
            %p
              = t(:formula_for_scenarios_from_date_onwards, formula_date: d)
              = link_to 'More info on formulas', 'https://openfisca.org/doc/coding-the-legislation/10_basic_example.html'
            %pre
              %code= display_formula formula['content']

    - if @variable.output_scenarios.size.positive?
      %hr/
      .card
        .card-header
          %h2 Scenarios calculating this variables
        %ul.list-group.list-group-flush
          - @variable.output_scenarios.each do |scenario|
            %li.list-group-item
              = link_to scenario.name, scenario
    %hr/
    %ul.nav
      - if @variable.references.present?
        - @variable.references.each do |ref|
          - if url?(ref)
            %li= link_to t(:reference), ref, class: 'nav-link'
          - else
            %li.nav-link Source: #{ref}
      - if @variable.spec.present?
        %li= link_to 'Source Code', @variable.github_url, class: 'nav-link'
      %li= link_to t(:view_api), @variable.href, class: 'nav-link'